#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  threadgroup int* a;
  threadgroup int* b;
  threadgroup int* c;
};

struct tint_symbol_6 {
  int tint_symbol_5;
};

struct tint_symbol_4 {
  int tint_symbol_3;
};

struct tint_symbol_2 {
  int tint_symbol;
  int tint_symbol_1;
};

void uses_a(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.a) = ((*tint_module_vars.a) + 1);
}

void uses_b(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.b) = ((*tint_module_vars.b) * 2);
}

void uses_a_and_b(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.b) = (*tint_module_vars.a);
}

void no_uses() {
}

void outer(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.a) = 0;
  uses_a(tint_module_vars);
  uses_a_and_b(tint_module_vars);
  uses_b(tint_module_vars);
  no_uses();
}

void main1_inner(uint tint_local_index, tint_module_vars_struct tint_module_vars) {
  if ((tint_local_index == 0u)) {
    (*tint_module_vars.a) = 0;
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
  (*tint_module_vars.a) = 42;
  uses_a(tint_module_vars);
}

void main2_inner(uint tint_local_index, tint_module_vars_struct tint_module_vars) {
  if ((tint_local_index == 0u)) {
    (*tint_module_vars.b) = 0;
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
  (*tint_module_vars.b) = 7;
  uses_b(tint_module_vars);
}

void main3_inner(uint tint_local_index, tint_module_vars_struct tint_module_vars) {
  if ((tint_local_index == 0u)) {
    (*tint_module_vars.a) = 0;
    (*tint_module_vars.b) = 0;
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
  outer(tint_module_vars);
  no_uses();
}

kernel void main4() {
  no_uses();
}

kernel void main1(uint tint_local_index [[thread_index_in_threadgroup]], threadgroup tint_symbol_6* v [[threadgroup(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.a=(&(*v).tint_symbol_5)};
  main1_inner(tint_local_index, tint_module_vars);
}

kernel void main2(uint tint_local_index [[thread_index_in_threadgroup]], threadgroup tint_symbol_4* v_1 [[threadgroup(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.b=(&(*v_1).tint_symbol_3)};
  main2_inner(tint_local_index, tint_module_vars);
}

kernel void main3(uint tint_local_index [[thread_index_in_threadgroup]], threadgroup tint_symbol_2* v_2 [[threadgroup(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.a=(&(*v_2).tint_symbol), .b=(&(*v_2).tint_symbol_1)};
  main3_inner(tint_local_index, tint_module_vars);
}
