#include <metal_stdlib>

using namespace metal;
int transpose_8c06ce() {
  half4x3 res = half4x3(half3(1.0h), half3(1.0h), half3(1.0h), half3(1.0h));
  return select(0, 1, (res[0][0] == 0.0h));
}

fragment void fragment_main(device int* tint_symbol_1 [[buffer(0)]]) {
  *(tint_symbol_1) = transpose_8c06ce();
  return;
}

kernel void compute_main(device int* tint_symbol_2 [[buffer(0)]]) {
  *(tint_symbol_2) = transpose_8c06ce();
  return;
}

struct VertexOutput {
  float4 pos;
  int prevent_dce;
};

struct tint_symbol {
  int prevent_dce [[user(locn0)]] [[flat]];
  float4 pos [[position]];
};

VertexOutput vertex_main_inner() {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = transpose_8c06ce();
  return out;
}

vertex tint_symbol vertex_main() {
  VertexOutput const inner_result = vertex_main_inner();
  tint_symbol wrapper_result = {};
  wrapper_result.pos = inner_result.pos;
  wrapper_result.prevent_dce = inner_result.prevent_dce;
  return wrapper_result;
}

