#version 310 es


struct S {
  int a;
  int b;
};

layout(binding = 0, std430)
buffer tint_symbol_2_1_ssbo {
  int tint_symbol_1;
} v;
shared int g1;
int accept_value(int val) {
  return val;
}
int accept_ptr_deref_call_func(inout int val) {
  int v_1 = val;
  return (v_1 + accept_value(val));
}
int accept_ptr_deref_pass_through(inout int val) {
  int v_2 = val;
  return (v_2 + accept_ptr_deref_call_func(val));
}
int accept_ptr_to_struct_and_access(inout S val) {
  return (val.a + val.b);
}
int accept_ptr_to_struct_access_pass_ptr(inout S val) {
  val.a = 2;
  return val.a;
}
int tint_f32_to_i32(float value) {
  return mix(2147483647, mix((-2147483647 - 1), int(value), (value >= -2147483648.0f)), (value <= 2147483520.0f));
}
int accept_ptr_vec_access_elements(inout vec3 v1) {
  v1[0u] = cross(v1, v1)[0u];
  return tint_f32_to_i32(v1.x);
}
int call_builtin_with_mod_scope_ptr() {
  return atomicOr(g1, 0);
}
void tint_symbol_inner(uint tint_local_index) {
  if ((tint_local_index == 0u)) {
    atomicExchange(g1, 0);
  }
  barrier();
  int v1 = 0;
  S v2 = S(0, 0);
  vec3 v4 = vec3(0.0f);
  int t1 = atomicOr(g1, 0);
  int v_3 = accept_ptr_deref_pass_through(v1);
  int v_4 = (v_3 + accept_ptr_to_struct_and_access(v2));
  int v_5 = (v_4 + accept_ptr_to_struct_and_access(v2));
  int v_6 = (v_5 + accept_ptr_vec_access_elements(v4));
  int v_7 = (v_6 + accept_ptr_to_struct_access_pass_ptr(v2));
  v.tint_symbol_1 = ((v_7 + call_builtin_with_mod_scope_ptr()) + t1);
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
  tint_symbol_inner(gl_LocalInvocationIndex);
}
