#include <metal_stdlib>

using namespace metal;
int2 tint_extract_bits(int2 v, uint offset, uint count) {
  uint const s = min(offset, 32u);
  uint const e = min(32u, (s + count));
  return extract_bits(v, s, (e - s));
}

int2 extractBits_a99a8d() {
  int2 arg_0 = int2(1);
  uint arg_1 = 1u;
  uint arg_2 = 1u;
  int2 res = tint_extract_bits(arg_0, arg_1, arg_2);
  return res;
}

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

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

struct VertexOutput {
  float4 pos;
  int2 prevent_dce;
};

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

VertexOutput vertex_main_inner() {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = extractBits_a99a8d();
  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;
}

