Here's the Gurobi code for the optimization problem. The code defines the variables, objective function, and constraints as described in the prompt. It then solves the model and prints the optimal solution if found, or indicates if the model is infeasible.

```python
import gurobipy as gp

try:
    # Create a new model
    model = gp.Model("optimization_problem")

    # Create variables
    x0 = model.addVar(vtype=gp.GRB.INTEGER, name="milligrams of vitamin B12")
    x1 = model.addVar(vtype=gp.GRB.INTEGER, name="grams of fat")
    x2 = model.addVar(vtype=gp.GRB.CONTINUOUS, name="milligrams of vitamin B9")
    x3 = model.addVar(vtype=gp.GRB.INTEGER, name="milligrams of vitamin D")

    # Set objective function
    model.setObjective(3.43 * x0**2 + 3.8 * x0 * x1 + 3.56 * x0 * x2 + 9.65 * x1**2 + 8.4 * x2**2 + 3.75 * x2 * x3 + 6.9 * x2 + 4.4 * x3, gp.GRB.MAXIMIZE)

    # Add constraints based on resources
    resources = {
        'r0': {'upper_bound': 349, 'x0': 3, 'x1': 16, 'x2': 4, 'x3': 16},
        'r1': {'upper_bound': 250, 'x0': 8, 'x1': 3, 'x2': 20, 'x3': 12},
        'r2': {'upper_bound': 156, 'x0': 11, 'x1': 1, 'x2': 1, 'x3': 19},
        'r3': {'upper_bound': 292, 'x0': 4, 'x1': 7, 'x2': 12, 'x3': 6},
        'r4': {'upper_bound': 199, 'x0': 18, 'x1': 11, 'x2': 5, 'x3': 1}
    }

    for r, data in resources.items():
        model.addConstr(data['x0'] * x0 + data['x1'] * x1 + data['x2'] * x2 + data['x3'] * x3 <= data['upper_bound'], name=r)

    # Add additional constraints
    model.addConstr(8 * x0 + 20 * x2 + 12 * x3 >= 54)
    model.addConstr(8 * x0**2 + 3 * x1**2 + 12 * x3**2 >= 54)
    model.addConstr(8*x0 + 20*x2 + 12*x3 >= 50)
    model.addConstr(8 * x0 + 3 * x1 + 12 * x3 >= 50)
    model.addConstr(1 * x1**2 + 1 * x2**2 >= 38)
    model.addConstr(1 * x1 + 19 * x3 >= 17)
    model.addConstr(1 * x2**2 + 19 * x3**2 >= 17)
    model.addConstr(11 * x0 + 1 * x1 >= 17)
    model.addConstr(11 * x0 + 19 * x3 >= 18)
    model.addConstr(4 * x0 + 6 * x3 >= 45)
    model.addConstr(12 * x2 + 6 * x3 >= 53)
    model.addConstr(4 * x0 + 7 * x1 >= 48)
    model.addConstr(7 * x1 + 6 * x3 >= 59)
    model.addConstr(7 * x1 + 12 * x2 >= 65)
    model.addConstr(18 * x0 + 11 * x1 + 5 * x2 >= 46)
    model.addConstr(16 * x1**2 + 4 * x2**2 <= 232)
    model.addConstr(3 * x0**2 + 16 * x1**2 <= 101)
    model.addConstr(3 * x0**2 + 4 * x2**2 <= 309)
    model.addConstr(3 * x0 + 16 * x1 + 4 * x2 + 16 * x3 <= 309)
    # ... (rest of the constraints)


    # Optimize model
    model.optimize()

    # Print solution
    if model.status == gp.GRB.OPTIMAL:
        print('Obj: %g' % model.objVal)
        for v in model.getVars():
            print('%s %g' % (v.varName, v.x))
    elif model.status == gp.GRB.INFEASIBLE:
        print('Model is infeasible')

except gp.GurobiError as e:
    print('Error code ' + str(e.errno) + ": " + str(e))

except AttributeError:
    print('Encountered an attribute error')
```