#include <metal_stdlib>
using namespace metal;

struct MyStruct {
  float f1;
};

template<typename T, size_t N>
struct tint_array {
  const constant T& operator[](size_t i) const constant { return elements[i]; }
  device T& operator[](size_t i) device { return elements[i]; }
  const device T& operator[](size_t i) const device { return elements[i]; }
  thread T& operator[](size_t i) thread { return elements[i]; }
  const thread T& operator[](size_t i) const thread { return elements[i]; }
  threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
  const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
  T elements[N];
};

struct tint_symbol_outputs {
  float4 tint_symbol_1 [[color(0)]];
};

int ret_i32() {
  return 1;
}

uint ret_u32() {
  return 1u;
}

float ret_f32() {
  return 1.0f;
}

MyStruct ret_MyStruct() {
  return MyStruct{};
}

tint_array<float, 10> ret_MyArray() {
  return tint_array<float, 10>{};
}

void var_decls() {
  int v1 = 1;
  uint v2 = 1u;
  float v3 = 1.0f;
  int3 v4 = int3(1);
  uint3 v5 = uint3(1u);
  float3 v6 = float3(1.0f);
  float3x3 v7 = float3x3(v6, v6, v6);
  MyStruct v8 = MyStruct{.f1=1.0f};
  tint_array<float, 10> v9 = tint_array<float, 10>{};
  int v10 = ret_i32();
  uint v11 = ret_u32();
  float v12 = ret_f32();
  MyStruct v13 = ret_MyStruct();
  MyStruct v14 = ret_MyStruct();
  tint_array<float, 10> v15 = ret_MyArray();
}

float4 tint_symbol_inner() {
  return float4(0.0f);
}

fragment tint_symbol_outputs tint_symbol() {
  tint_symbol_outputs tint_wrapper_result = {};
  tint_wrapper_result.tint_symbol_1 = tint_symbol_inner();
  return tint_wrapper_result;
}
