#include <metal_stdlib>

using namespace metal;
struct PixelLocal {
  uint a;
};

struct tint_private_vars_struct {
  PixelLocal V;
};

struct f_res {
  uint output_0;
};

struct tint_symbol_1 {
  uint a [[color(1)]];
};

struct tint_symbol_2 {
  uint output_0 [[color(1)]];
};

void f_inner(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).V.a = 42u;
}

f_res f_inner_1(PixelLocal pixel_local_1, thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).V = pixel_local_1;
  f_inner(tint_private_vars);
  f_res const tint_symbol_4 = {.output_0=(*(tint_private_vars)).V.a};
  return tint_symbol_4;
}

fragment tint_symbol_2 f(tint_symbol_1 tint_symbol [[stage_in]]) {
  thread tint_private_vars_struct tint_private_vars = {};
  PixelLocal const tint_symbol_3 = {.a=tint_symbol.a};
  f_res const inner_result = f_inner_1(tint_symbol_3, &(tint_private_vars));
  tint_symbol_2 wrapper_result = {};
  wrapper_result.output_0 = inner_result.output_0;
  return wrapper_result;
}

