#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  depth2d_ms<float, access::read> arg_0;
  thread float4* tint_symbol_1;
};

struct vertex_main_out {
  float4 tint_symbol_1_1;
};

struct vertex_main_outputs {
  float4 vertex_main_out_tint_symbol_1_1 [[position]];
};

void textureNumSamples_a3c8a0(tint_module_vars_struct tint_module_vars) {
  int res = 0;
  res = int(tint_module_vars.arg_0.get_num_samples());
}

void tint_symbol_2(float4 tint_symbol, tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.tint_symbol_1) = tint_symbol;
}

void vertex_main_1(tint_module_vars_struct tint_module_vars) {
  textureNumSamples_a3c8a0(tint_module_vars);
  tint_symbol_2(float4(0.0f), tint_module_vars);
}

vertex_main_out vertex_main_inner(tint_module_vars_struct tint_module_vars) {
  vertex_main_1(tint_module_vars);
  return vertex_main_out{.tint_symbol_1_1=(*tint_module_vars.tint_symbol_1)};
}

void fragment_main_1(tint_module_vars_struct tint_module_vars) {
  textureNumSamples_a3c8a0(tint_module_vars);
}

fragment void fragment_main(depth2d_ms<float, access::read> arg_0 [[texture(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0=arg_0};
  fragment_main_1(tint_module_vars);
}

void compute_main_1(tint_module_vars_struct tint_module_vars) {
  textureNumSamples_a3c8a0(tint_module_vars);
}

kernel void compute_main(depth2d_ms<float, access::read> arg_0 [[texture(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0=arg_0};
  compute_main_1(tint_module_vars);
}

vertex vertex_main_outputs vertex_main(depth2d_ms<float, access::read> arg_0 [[texture(0)]]) {
  thread float4 tint_symbol_1 = float4(0.0f);
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0=arg_0, .tint_symbol_1=(&tint_symbol_1)};
  vertex_main_outputs tint_wrapper_result = {};
  tint_wrapper_result.vertex_main_out_tint_symbol_1_1 = vertex_main_inner(tint_module_vars).tint_symbol_1_1;
  return tint_wrapper_result;
}
