#include <metal_stdlib>
using namespace metal;

// shader 0f2b9ee517917425
// Shader dumped from BotW 208, using Cemu 2193a8c
// Based on 0f2b9ee517917425_00000000000003c9_ps.txt
// Used for: Restoring the native BotW Anti-Aliasing implementation in inventory
// screen

constant float resX = float($width) / float($gameWidth);
constant float resY = float($height) / float($gameHeight);
#define fxaa $fxaa

#define SET_POSITION(_v)                                                       \
    out.position = _v;                                                         \
    out.position.z = (out.position.z + out.position.w) / 2.0

// start of shader inputs/outputs, predetermined by Cemu. Do not touch
struct SupportBuffer {
    int4 remapped[2];
    float2 fragCoordScale;
};

#define GET_FRAGCOORD()                                                        \
    float4(in.position.xy *supportBuffer.fragCoordScale.xy, in.position.z,     \
           1.0 / in.position.w)
struct FragmentIn {
    float4 position [[position]];
    float4 passParameterSem2 [[user(locn0)]];
};

struct FragmentOut {
    float4 passPixelColor0 [[color(0)]];
};

// end of shader inputs/outputs
template <typename TextureT, typename CoordT>
float sampleCompareEmulate(TextureT tex, sampler samplr, CoordT coord,
                           float compareValue) {
    return compareValue < tex.sample(samplr, coord).x ? 1.0 : 0.0;
}
template <typename TextureT, typename CoordT>
float2 textureCalculateLod(TextureT tex, sampler samplr, CoordT coord) {
    float lod = tex.calculate_unclamped_lod(samplr, coord);
    return float2(floor(lod), fract(lod));
}
int clampFI32(int v) {
    if (v == 0x7FFFFFFF)
        return as_type<int>(1.0);
    else if (v == 0xFFFFFFFF)
        return as_type<int>(0.0);
    return as_type<int>(clamp(as_type<float>(v), 0.0, 1.0));
}
float mul_nonIEEE(float a, float b) {
    if (a == 0.0 || b == 0.0)
        return 0.0;
    return a * b;
}
fragment FragmentOut main0(FragmentIn in [[stage_in]],
                           float2 pointCoord [[point_coord]],
                           bool frontFacing [[front_facing]],
                           constant SupportBuffer &supportBuffer [[buffer(0)]],
                           texture2d<float> tex0 [[texture(0)]],
                           sampler samplr0 [[sampler(0)]],
                           texture2d<float> tex1 [[texture(1)]],
                           sampler samplr1 [[sampler(1)]]) {
    FragmentOut out;
#if fxaa == 0
    out.passPixelColor0 = tex0.sample(samplr0, in.passParameterSem2.xy);
#else
    int4 R0i = int4(0);
    int4 R1i = int4(0);
    int4 R2i = int4(0);
    int4 R3i = int4(0);
    int4 R4i = int4(0);
    int4 R5i = int4(0);
    int4 R6i = int4(0);
    int4 R123i = int4(0);
    int4 R124i = int4(0);
    int4 R125i = int4(0);
    int4 R126i = int4(0);
    int4 R127i = int4(0);
    int backupReg0i, backupReg1i, backupReg2i, backupReg3i, backupReg4i;
    int PV0ix = 0, PV0iy = 0, PV0iz = 0, PV0iw = 0, PV1ix = 0, PV1iy = 0,
        PV1iz = 0, PV1iw = 0;
    int PS0i = 0, PS1i = 0;
    int4 tempi = int4(0);
    float tempResultf;
    int tempResulti;
    int4 ARi = int4(0);
    bool predResult = true;
    bool activeMaskStack[2];
    bool activeMaskStackC[3];
    activeMaskStack[0] = false;
    activeMaskStackC[0] = false;
    activeMaskStackC[1] = false;
    activeMaskStack[0] = true;
    activeMaskStackC[0] = true;
    activeMaskStackC[1] = true;
    R0i = as_type<int4>(in.passParameterSem2);
    if (activeMaskStackC[1] == true) {
        R2i.xzw = as_type<int3>(
            tex1.gather(samplr1, float2(0.0001) + float2(as_type<float>(R0i.x),
                                                         as_type<float>(R0i.y)))
                .xzw);
        R1i.xz = as_type<int2>(
            tex1.gather(samplr1, float2(0.0001) + float2(as_type<float>(R0i.z),
                                                         as_type<float>(R0i.w)))
                .xz);
        R3i.xyzw =
            as_type<int4>(tex0.sample(samplr0, float2(as_type<float>(R0i.x),
                                                      as_type<float>(R0i.y)))
                              .xyzw);
        R0i.w = as_type<int>(
            tex1.sample(samplr1,
                        float2(as_type<float>(R0i.x), as_type<float>(R0i.y)),
                        int2(1, -1))
                .x);
        R1i.y = as_type<int>(
            tex1.sample(samplr1,
                        float2(as_type<float>(R0i.x), as_type<float>(R0i.y)),
                        int2(-1, 1))
                .x);
    }
    if (activeMaskStackC[1] == true) {
        activeMaskStack[1] = activeMaskStack[0];
        activeMaskStackC[2] = activeMaskStackC[1];
        // 0
        PV0ix = as_type<int>(min(as_type<float>(R1i.x), as_type<float>(R1i.z)) /
                             resX);
        PV0iy = as_type<int>(max(as_type<float>(R2i.x), as_type<float>(R2i.z)) *
                             resY);
        PV0iz = as_type<int>(max(as_type<float>(R1i.x), as_type<float>(R1i.z)) *
                             resX);
        PV0iw = as_type<int>(min(as_type<float>(R2i.x), as_type<float>(R2i.z)));
        // 1
        PV1ix = as_type<int>(max(as_type<float>(PV0iz), as_type<float>(PV0iy)));
        PV1iy = as_type<int>(min(as_type<float>(PV0ix), as_type<float>(PV0iw)));
        // 2
        PV0iz = as_type<int>(min(as_type<float>(R2i.w), as_type<float>(PV1iy)));
        PV0iw = as_type<int>(max(as_type<float>(R2i.w), as_type<float>(PV1ix)));
        // 3
        PV1ix = as_type<int>(
            mul_nonIEEE(as_type<float>(PV0iw),
                        as_type<float>(supportBuffer.remapped[0].x)));
        R1i.w = as_type<int>(as_type<float>(PV0iw) + -(as_type<float>(PV0iz)));
        // 4
        R2i.y = as_type<int>(max(as_type<float>(PV1ix),
                                 as_type<float>(supportBuffer.remapped[0].y)));
        // 5
        predResult = (as_type<float>(R1i.w) >= as_type<float>(R2i.y));
        activeMaskStack[1] = predResult;
        activeMaskStackC[2] = predResult == true && activeMaskStackC[1] == true;
    } else {
        activeMaskStack[1] = false;
        activeMaskStackC[2] = false;
    }
    if (activeMaskStackC[2] == true) {
        // 0
        R126i.x = as_type<int>(as_type<float>(R2i.z) + as_type<float>(R0i.w));
        R126i.y = as_type<int>(as_type<float>(R1i.x) + as_type<float>(R1i.y));
        R126i.z = as_type<int>(as_type<float>(R2i.z) + as_type<float>(R1i.x));
        R127i.w = as_type<int>(as_type<float>(R2i.x) + as_type<float>(R1i.z));
        R127i.y = R1i.z;
        R127i.y = as_type<int>(as_type<float>(R127i.y) * 2.0);
        // 1
        PV1ix = R2i.x;
        PV1ix = as_type<int>(as_type<float>(PV1ix) * 2.0);
        PV1iy = as_type<int>(as_type<float>(R1i.x) + as_type<float>(R0i.w));
        R127i.z = as_type<int>(-(as_type<float>(R2i.w)) * 2.0 +
                               as_type<float>(R126i.z));
        PV1iw = R127i.w;
        PS1i = as_type<int>(as_type<float>(R2i.z) + as_type<float>(R1i.y));
        // 2
        R127i.x = as_type<int>(-(as_type<float>(R2i.w)) * 2.0 +
                               as_type<float>(PV1iw));
        R1i.y = R2i.z;
        PV0iz = as_type<int>(as_type<float>(PS1i) + -(as_type<float>(PV1ix)));
        PV0iw =
            as_type<int>(as_type<float>(PV1iy) + -(as_type<float>(R127i.y)));
        PS0i = R126i.x;
        // 3
        backupReg0i = R127i.z;
        R123i.x = as_type<int>(-(as_type<float>(R1i.x)) * 2.0 +
                               as_type<float>(R126i.y));
        PV1iy =
            as_type<int>(max(as_type<float>(PV0iw), -(as_type<float>(PV0iw))));
        R127i.z =
            as_type<int>(max(as_type<float>(PV0iz), -(as_type<float>(PV0iz))));
        R123i.w =
            as_type<int>(-(as_type<float>(R1i.y)) * 2.0 + as_type<float>(PS0i));
        PS1i = as_type<int>(
            max(as_type<float>(backupReg0i), -(as_type<float>(backupReg0i))));
        PS1i = as_type<int>(as_type<float>(PS1i) * 2.0);
        // 4
        backupReg0i = R126i.y;
        PV0ix = as_type<int>(
            max(as_type<float>(R123i.x), -(as_type<float>(R123i.x))));
        R126i.y = as_type<int>(
            max(as_type<float>(R123i.w), -(as_type<float>(R123i.w))));
        PV0iz = as_type<int>(
            max(as_type<float>(R127i.x), -(as_type<float>(R127i.x))));
        PV0iz = as_type<int>(as_type<float>(PV0iz) * 2.0);
        PV0iw = as_type<int>(as_type<float>(PV1iy) + as_type<float>(PS1i));
        R126i.w =
            as_type<int>(as_type<float>(R126i.x) + as_type<float>(backupReg0i));
        // 5
        PV1ix = as_type<int>(as_type<float>(PV0ix) + as_type<float>(PV0iz));
        PV1iy = as_type<int>(as_type<float>(R127i.w) + as_type<float>(R126i.z));
        PV1iy = as_type<int>(as_type<float>(PV1iy) * 2.0);
        R127i.z = as_type<int>(as_type<float>(R127i.z) + as_type<float>(PV0iw));
        R127i.y = as_type<int>(1.0 / as_type<float>(R1i.w));
        // 6
        PV0ix = as_type<int>(as_type<float>(R126i.w) + as_type<float>(PV1iy));
        PV0iy = as_type<int>(as_type<float>(R126i.y) + as_type<float>(PV1ix));
        // 7
        PV1ix = ((as_type<float>(PV0iy) >= as_type<float>(R127i.z)) ? -1 : 0);
        PV1iy =
            as_type<int>(as_type<float>(PV0ix) * as_type<float>(0x3daaaaab));
        // 8
        PV0ix = as_type<int>(as_type<float>(R2i.w) + -(as_type<float>(PV1iy)));
        R4i.z = ((PV1ix == 0) ? (int(0x3f800000)) : (0));
        R5i.w = ((PV1ix == 0) ? (0) : (int(0x3f800000)));
        // 9
        R5i.x = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.w),
                        as_type<float>(supportBuffer.remapped[1].x)));
        PV1iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R4i.z),
                        as_type<float>(supportBuffer.remapped[1].x) / resX));
        PV1iz =
            as_type<int>(max(as_type<float>(PV0ix), -(as_type<float>(PV0ix))));
        R3i.w = as_type<int>(
            mul_nonIEEE(as_type<float>(R4i.z),
                        as_type<float>(supportBuffer.remapped[1].y) / resY));
        PS1i = as_type<int>(
            mul_nonIEEE(as_type<float>(R1i.x), as_type<float>(R4i.z)));
        // 10
        R127i.x = as_type<int>(as_type<float>(PV1iz) * as_type<float>(R127i.y));
        R127i.x = clampFI32(R127i.x);
        R127i.y = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.w),
                        as_type<float>(supportBuffer.remapped[1].y)) +
            as_type<float>(PV1iy));
        R127i.z = as_type<int>(
            mul_nonIEEE(as_type<float>(R1i.z), as_type<float>(R5i.w)) +
            as_type<float>(PS1i));
        PV0iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R2i.z), as_type<float>(R4i.z)));
        // 11
        R124i.x = as_type<int>(
            mul_nonIEEE(as_type<float>(R2i.x), as_type<float>(R5i.w)) +
            as_type<float>(PV0iw));
        PV1iy =
            as_type<int>(-(as_type<float>(R2i.w)) + as_type<float>(R127i.z));
        R123i.w = as_type<int>(as_type<float>(R127i.x) * 6.0 + -15.0);
        // 12
        R125i.x =
            as_type<int>(max(as_type<float>(PV1iy), -(as_type<float>(PV1iy))));
        PV0iy =
            as_type<int>(-(as_type<float>(R2i.w)) + as_type<float>(R124i.x));
        R123i.z = as_type<int>(
            mul_nonIEEE(as_type<float>(R127i.x), as_type<float>(R123i.w)) +
            10.0);
        // 13
        R126i.x =
            as_type<int>(max(as_type<float>(PV0iy), -(as_type<float>(PV0iy))));
        PV1iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R127i.x), as_type<float>(R123i.z)));
        // 14
        PV0ix = as_type<int>(
            mul_nonIEEE(as_type<float>(R127i.x), as_type<float>(PV1iy)));
        R126i.w =
            ((as_type<float>(R125i.x) >= as_type<float>(R126i.x)) ? -1 : 0);
        // 15
        R6i.x = as_type<int>(((R126i.w == 0) ? (as_type<float>(R127i.y))
                                             : (-(as_type<float>(R127i.y)))));
        R123i.z = ((R126i.w == 0) ? (R126i.x) : (R125i.x));
        PV1iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R127i.x), as_type<float>(PV0ix)));
        // 16
        PV0ix = as_type<int>(
            mul_nonIEEE(as_type<float>(R4i.z), as_type<float>(R6i.x)));
        PV0ix = as_type<int>(as_type<float>(PV0ix) / 2.0);
        R123i.y = ((R126i.w == 0) ? (R124i.x) : (R127i.z));
        R3i.z = as_type<int>(as_type<float>(PV1iw) * 0.75);
        PV0iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.w), as_type<float>(R6i.x)));
        PV0iw = as_type<int>(as_type<float>(PV0iw) / 2.0);
        R4i.x = as_type<int>(as_type<float>(R123i.z) * 0.25);
        // 17
        PV1ix = as_type<int>(as_type<float>(R0i.x) + as_type<float>(PV0ix));
        PV1iz = as_type<int>(as_type<float>(R0i.y) + as_type<float>(PV0iw));
        R4i.w = as_type<int>(as_type<float>(R2i.w) + as_type<float>(R123i.y));
        R4i.w = as_type<int>(as_type<float>(R4i.w) / 2.0);
        // 18
        R3i.x = as_type<int>(-(as_type<float>(R5i.x)) + as_type<float>(PV1ix));
        R3i.y = as_type<int>(-(as_type<float>(R3i.w)) + as_type<float>(PV1iz));
        R1i.z = as_type<int>(as_type<float>(R5i.x) + as_type<float>(PV1ix));
        R1i.w = as_type<int>(as_type<float>(R3i.w) + as_type<float>(PV1iz));
        R2i.x = as_type<int>(as_type<float>(R2i.w) + -(as_type<float>(R4i.w)));
    }
    if (activeMaskStackC[2] == true) {
        R1i.y = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R3i.x),
                                                         as_type<float>(R3i.y)))
                                 .x);
        R1i.x = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.z),
                                                         as_type<float>(R1i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        R2i.x = ((0.0 > as_type<float>(R2i.x)) ? -1 : 0);
        PV0iz = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.x));
        PV0iw = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.y));
        // 1
        PV1iy =
            as_type<int>(max(as_type<float>(PV0iw), -(as_type<float>(PV0iw))));
        PV1iz =
            as_type<int>(max(as_type<float>(PV0iz), -(as_type<float>(PV0iz))));
        // 2
        PV0ix = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iy)));
        PV0iy = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iz)));
        // 3
        R123i.z = ((as_type<float>(PV0iy) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0ix) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        R3i.x = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R5i.x)), as_type<float>(R123i.w)) +
            as_type<float>(R3i.x));
        R3i.y = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R3i.w)), as_type<float>(R123i.w)) +
            as_type<float>(R3i.y));
        R2i.z = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.z)) +
            as_type<float>(R1i.z));
        R2i.w = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.z)) +
            as_type<float>(R1i.w));
    }
    if (activeMaskStackC[2] == true) {
        R1i.w = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R3i.x),
                                                         as_type<float>(R3i.y)))
                                 .x);
        R1i.z = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R2i.z),
                                                         as_type<float>(R2i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0ix = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.w));
        PV0iy = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.z));
        // 1
        PV1ix =
            as_type<int>(max(as_type<float>(PV0iy), -(as_type<float>(PV0iy))));
        PV1iw =
            as_type<int>(max(as_type<float>(PV0ix), -(as_type<float>(PV0ix))));
        // 2
        PV0iz = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iw)));
        PV0iw = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1ix)));
        // 3
        R123i.z = ((as_type<float>(PV0iw) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0iz) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        R1i.x = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R5i.x)), as_type<float>(R123i.w)) +
            as_type<float>(R3i.x));
        R1i.y = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R3i.w)), as_type<float>(R123i.w)) +
            as_type<float>(R3i.y));
        R2i.z = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.z)) +
            as_type<float>(R2i.z));
        R2i.w = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.z)) +
            as_type<float>(R2i.w));
    }
    if (activeMaskStackC[2] == true) {
        R3i.y = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.x),
                                                         as_type<float>(R1i.y)))
                                 .x);
        R3i.x = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R2i.z),
                                                         as_type<float>(R2i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0ix = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R3i.y));
        PV0iw = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R3i.x));
        // 1
        PV1iz =
            as_type<int>(max(as_type<float>(PV0iw), -(as_type<float>(PV0iw))));
        PV1iw =
            as_type<int>(max(as_type<float>(PV0ix), -(as_type<float>(PV0ix))));
        // 2
        PV0iy = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iz)));
        PV0iz = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iw)));
        // 3
        R123i.y = ((as_type<float>(PV0iz) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.z = ((as_type<float>(PV0iy) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        R1i.x = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R5i.x)), as_type<float>(R123i.y)) +
            as_type<float>(R1i.x));
        R1i.y = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R3i.w)), as_type<float>(R123i.y)) +
            as_type<float>(R1i.y));
        R1i.z = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.z)) +
            as_type<float>(R2i.z));
        R1i.w = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.z)) +
            as_type<float>(R2i.w));
    }
    if (activeMaskStackC[2] == true) {
        R2i.w = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.x),
                                                         as_type<float>(R1i.y)))
                                 .x);
        R2i.z = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.z),
                                                         as_type<float>(R1i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0ix = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R2i.w));
        PV0iy = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R2i.z));
        // 1
        PV1ix =
            as_type<int>(max(as_type<float>(PV0iy), -(as_type<float>(PV0iy))));
        PV1iw =
            as_type<int>(max(as_type<float>(PV0ix), -(as_type<float>(PV0ix))));
        // 2
        PV0iz = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iw)));
        PV0iw = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1ix)));
        // 3
        R123i.z = ((as_type<float>(PV0iw) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0iz) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        R3i.x = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R5i.x)), as_type<float>(R123i.w)) +
            as_type<float>(R1i.x));
        R3i.y = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R3i.w)), as_type<float>(R123i.w)) +
            as_type<float>(R1i.y));
        R1i.z = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.z)) +
            as_type<float>(R1i.z));
        R1i.w = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.z)) +
            as_type<float>(R1i.w));
    }
    if (activeMaskStackC[2] == true) {
        R1i.y = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R3i.x),
                                                         as_type<float>(R3i.y)))
                                 .x);
        R1i.x = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.z),
                                                         as_type<float>(R1i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0ix = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.y));
        PV0iw = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.x));
        // 1
        PV1iz =
            as_type<int>(max(as_type<float>(PV0iw), -(as_type<float>(PV0iw))));
        PV1iw =
            as_type<int>(max(as_type<float>(PV0ix), -(as_type<float>(PV0ix))));
        // 2
        PV0iy = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iz)));
        PV0iz = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iw)));
        // 3
        R123i.y = ((as_type<float>(PV0iz) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.z = ((as_type<float>(PV0iy) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        R3i.x = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R5i.x)), as_type<float>(R123i.y)) +
            as_type<float>(R3i.x));
        R3i.y = as_type<int>(
            mul_nonIEEE(-(as_type<float>(R3i.w)), as_type<float>(R123i.y)) +
            as_type<float>(R3i.y));
        R2i.z = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.z)) +
            as_type<float>(R1i.z));
        R2i.w = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.z)) +
            as_type<float>(R1i.w));
    }
    if (activeMaskStackC[2] == true) {
        R1i.w = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R3i.x),
                                                         as_type<float>(R3i.y)))
                                 .x);
        R1i.z = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R2i.z),
                                                         as_type<float>(R2i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0ix = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.w));
        PV0iy = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.z));
        // 1
        PV1ix =
            as_type<int>(max(as_type<float>(PV0iy), -(as_type<float>(PV0iy))));
        PV1iw =
            as_type<int>(max(as_type<float>(PV0ix), -(as_type<float>(PV0ix))));
        // 2
        PV0iz = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iw)));
        PV0iw = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1ix)));
        // 3
        R123i.z = ((as_type<float>(PV0iw) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0iz) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        PV0ix = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.w)));
        PV0iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.z)));
        PV0iz = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.z)));
        PV0iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.w)));
        // 5
        R1i.x = as_type<int>(-(as_type<float>(PV0ix)) * 1.5 +
                             as_type<float>(R3i.x));
        R1i.y = as_type<int>(-(as_type<float>(PV0iw)) * 1.5 +
                             as_type<float>(R3i.y));
        R2i.z =
            as_type<int>(as_type<float>(PV0iz) * 1.5 + as_type<float>(R2i.z));
        R2i.w =
            as_type<int>(as_type<float>(PV0iy) * 1.5 + as_type<float>(R2i.w));
    }
    if (activeMaskStackC[2] == true) {
        R3i.y = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.x),
                                                         as_type<float>(R1i.y)))
                                 .x);
        R3i.x = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R2i.z),
                                                         as_type<float>(R2i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0iz = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R3i.y));
        PV0iw = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R3i.x));
        // 1
        PV1iy =
            as_type<int>(max(as_type<float>(PV0iz), -(as_type<float>(PV0iz))));
        PV1iz =
            as_type<int>(max(as_type<float>(PV0iw), -(as_type<float>(PV0iw))));
        // 2
        PV0ix = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iy)));
        PV0iy = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iz)));
        // 3
        R123i.x = ((as_type<float>(PV0iy) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0ix) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        PV0ix = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.x)));
        PV0ix = as_type<int>(as_type<float>(PV0ix) * 2.0);
        PV0iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.x)));
        PV0iy = as_type<int>(as_type<float>(PV0iy) * 2.0);
        PV0iz = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.w)));
        PV0iz = as_type<int>(as_type<float>(PV0iz) * 2.0);
        PV0iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.w)));
        PV0iw = as_type<int>(as_type<float>(PV0iw) * 2.0);
        // 5
        R1i.x = as_type<int>(as_type<float>(R1i.x) + -(as_type<float>(PV0iw)));
        R1i.y = as_type<int>(as_type<float>(R1i.y) + -(as_type<float>(PV0iz)));
        R1i.z = as_type<int>(as_type<float>(R2i.z) + as_type<float>(PV0ix));
        R1i.w = as_type<int>(as_type<float>(R2i.w) + as_type<float>(PV0iy));
    }
    if (activeMaskStackC[2] == true) {
        R2i.w = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.x),
                                                         as_type<float>(R1i.y)))
                                 .x);
        R2i.z = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.z),
                                                         as_type<float>(R1i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0iy = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R2i.z));
        PV0iz = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R2i.w));
        // 1
        PV1ix =
            as_type<int>(max(as_type<float>(PV0iy), -(as_type<float>(PV0iy))));
        PV1iy =
            as_type<int>(max(as_type<float>(PV0iz), -(as_type<float>(PV0iz))));
        // 2
        PV0ix = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iy)));
        PV0iw = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1ix)));
        // 3
        R123i.z = ((as_type<float>(PV0iw) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0ix) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        PV0ix = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.w)));
        PV0ix = as_type<int>(as_type<float>(PV0ix) * 2.0);
        PV0iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.z)));
        PV0iy = as_type<int>(as_type<float>(PV0iy) * 2.0);
        PV0iz = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.z)));
        PV0iz = as_type<int>(as_type<float>(PV0iz) * 2.0);
        PV0iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.w)));
        PV0iw = as_type<int>(as_type<float>(PV0iw) * 2.0);
        // 5
        R3i.x = as_type<int>(as_type<float>(R1i.x) + -(as_type<float>(PV0ix)));
        R3i.y = as_type<int>(as_type<float>(R1i.y) + -(as_type<float>(PV0iw)));
        R1i.z = as_type<int>(as_type<float>(R1i.z) + as_type<float>(PV0iz));
        R1i.w = as_type<int>(as_type<float>(R1i.w) + as_type<float>(PV0iy));
    }
    if (activeMaskStackC[2] == true) {
        R1i.y = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R3i.x),
                                                         as_type<float>(R3i.y)))
                                 .x);
        R1i.x = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.z),
                                                         as_type<float>(R1i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0iz = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.y));
        PV0iw = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.x));
        // 1
        PV1iy =
            as_type<int>(max(as_type<float>(PV0iz), -(as_type<float>(PV0iz))));
        PV1iz =
            as_type<int>(max(as_type<float>(PV0iw), -(as_type<float>(PV0iw))));
        // 2
        PV0ix = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iy)));
        PV0iy = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iz)));
        // 3
        R123i.x = ((as_type<float>(PV0iy) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0ix) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        PV0ix = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.x)));
        PV0ix = as_type<int>(as_type<float>(PV0ix) * 2.0);
        PV0iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.x)));
        PV0iy = as_type<int>(as_type<float>(PV0iy) * 2.0);
        PV0iz = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.w)));
        PV0iz = as_type<int>(as_type<float>(PV0iz) * 2.0);
        PV0iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.w)));
        PV0iw = as_type<int>(as_type<float>(PV0iw) * 2.0);
        // 5
        R3i.x = as_type<int>(as_type<float>(R3i.x) + -(as_type<float>(PV0iw)));
        R3i.y = as_type<int>(as_type<float>(R3i.y) + -(as_type<float>(PV0iz)));
        R2i.z = as_type<int>(as_type<float>(R1i.z) + as_type<float>(PV0ix));
        R2i.w = as_type<int>(as_type<float>(R1i.w) + as_type<float>(PV0iy));
    }
    if (activeMaskStackC[2] == true) {
        R1i.w = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R3i.x),
                                                         as_type<float>(R3i.y)))
                                 .x);
        R1i.z = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R2i.z),
                                                         as_type<float>(R2i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0iy = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.z));
        PV0iz = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.w));
        // 1
        PV1ix =
            as_type<int>(max(as_type<float>(PV0iy), -(as_type<float>(PV0iy))));
        PV1iy =
            as_type<int>(max(as_type<float>(PV0iz), -(as_type<float>(PV0iz))));
        // 2
        PV0ix = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iy)));
        PV0iw = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1ix)));
        // 3
        R123i.z = ((as_type<float>(PV0iw) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0ix) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        PV0ix = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.w)));
        PV0ix = as_type<int>(as_type<float>(PV0ix) * 2.0);
        PV0iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.z)));
        PV0iy = as_type<int>(as_type<float>(PV0iy) * 2.0);
        PV0iz = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.z)));
        PV0iz = as_type<int>(as_type<float>(PV0iz) * 2.0);
        PV0iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.w)));
        PV0iw = as_type<int>(as_type<float>(PV0iw) * 2.0);
        // 5
        R1i.x = as_type<int>(as_type<float>(R3i.x) + -(as_type<float>(PV0ix)));
        R1i.y = as_type<int>(as_type<float>(R3i.y) + -(as_type<float>(PV0iw)));
        R2i.z = as_type<int>(as_type<float>(R2i.z) + as_type<float>(PV0iz));
        R2i.w = as_type<int>(as_type<float>(R2i.w) + as_type<float>(PV0iy));
    }
    if (activeMaskStackC[2] == true) {
        R3i.y = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.x),
                                                         as_type<float>(R1i.y)))
                                 .x);
        R3i.x = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R2i.z),
                                                         as_type<float>(R2i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0iz = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R3i.y));
        PV0iw = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R3i.x));
        // 1
        PV1iy =
            as_type<int>(max(as_type<float>(PV0iz), -(as_type<float>(PV0iz))));
        PV1iz =
            as_type<int>(max(as_type<float>(PV0iw), -(as_type<float>(PV0iw))));
        // 2
        PV0ix = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iy)));
        PV0iy = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iz)));
        // 3
        R123i.x = ((as_type<float>(PV0iy) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0ix) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        PV0ix = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.x)));
        PV0ix = as_type<int>(as_type<float>(PV0ix) * 4.0);
        PV0iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.x)));
        PV0iy = as_type<int>(as_type<float>(PV0iy) * 4.0);
        PV0iz = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.w)));
        PV0iz = as_type<int>(as_type<float>(PV0iz) * 4.0);
        PV0iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.w)));
        PV0iw = as_type<int>(as_type<float>(PV0iw) * 4.0);
        // 5
        R1i.x = as_type<int>(as_type<float>(R1i.x) + -(as_type<float>(PV0iw)));
        R1i.y = as_type<int>(as_type<float>(R1i.y) + -(as_type<float>(PV0iz)));
        R1i.z = as_type<int>(as_type<float>(R2i.z) + as_type<float>(PV0ix));
        R1i.w = as_type<int>(as_type<float>(R2i.w) + as_type<float>(PV0iy));
    }
    if (activeMaskStackC[2] == true) {
        R2i.w = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.x),
                                                         as_type<float>(R1i.y)))
                                 .x);
        R2i.z = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.z),
                                                         as_type<float>(R1i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0iy = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R2i.z));
        PV0iz = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R2i.w));
        // 1
        PV1ix =
            as_type<int>(max(as_type<float>(PV0iy), -(as_type<float>(PV0iy))));
        PV1iy =
            as_type<int>(max(as_type<float>(PV0iz), -(as_type<float>(PV0iz))));
        // 2
        PV0ix = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1iy)));
        PV0iw = as_type<int>(as_type<float>(R4i.x) + -(as_type<float>(PV1ix)));
        // 3
        R123i.z = ((as_type<float>(PV0iw) >= 0.0) ? (as_type<int>(1.0)) : (0));
        R123i.w = ((as_type<float>(PV0ix) >= 0.0) ? (as_type<int>(1.0)) : (0));
        // 4
        PV0ix = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.w)));
        PV0iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.x), as_type<float>(R123i.z)));
        PV0iz = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.z)));
        PV0iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R3i.w), as_type<float>(R123i.w)));
        // 5
        R5i.x = as_type<int>(-(as_type<float>(PV0ix)) * 8.0 +
                             as_type<float>(R1i.x));
        R5i.y = as_type<int>(-(as_type<float>(PV0iw)) * 8.0 +
                             as_type<float>(R1i.y));
        R1i.z =
            as_type<int>(as_type<float>(PV0iy) * 8.0 + as_type<float>(R1i.z));
        R1i.w =
            as_type<int>(as_type<float>(PV0iz) * 8.0 + as_type<float>(R1i.w));
    }
    if (activeMaskStackC[2] == true) {
        R1i.y = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R5i.x),
                                                         as_type<float>(R5i.y)))
                                 .x);
        R1i.x = as_type<int>(tex1.sample(samplr1, float2(as_type<float>(R1i.z),
                                                         as_type<float>(R1i.w)))
                                 .x);
    }
    if (activeMaskStackC[2] == true) {
        // 0
        PV0ix = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.x));
        PV0iy = as_type<int>(as_type<float>(R0i.x) + -(as_type<float>(R5i.x)));
        PV0iz = as_type<int>(-(as_type<float>(R4i.w)) + as_type<float>(R1i.y));
        R126i.w =
            as_type<int>(as_type<float>(R0i.y) + -(as_type<float>(R5i.y)));
        PS0i = as_type<int>(-(as_type<float>(R0i.x)) + as_type<float>(R1i.z));
        // 1
        PV1ix = as_type<int>(-(as_type<float>(R0i.y)) + as_type<float>(R1i.w));
        PV1iy = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.w), as_type<float>(PS0i)));
        PV1iz = ((0.0 > as_type<float>(PV0iz)) ? -1 : 0);
        PV1iw = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.w), as_type<float>(PV0iy)));
        PS1i = ((0.0 > as_type<float>(PV0ix)) ? -1 : 0);
        // 2
        R123i.x = as_type<int>(
            mul_nonIEEE(as_type<float>(R4i.z), as_type<float>(PV1ix)) +
            as_type<float>(PV1iy));
        R127i.y = (PV1iz != R2i.x) ? -1 : 0;
        R123i.z = as_type<int>(
            mul_nonIEEE(as_type<float>(R4i.z), as_type<float>(R126i.w)) +
            as_type<float>(PV1iw));
        R126i.w = (PS1i != R2i.x) ? -1 : 0;
        // 3
        PV1ix = as_type<int>(as_type<float>(R123i.z) + as_type<float>(R123i.x));
        R126i.y =
            as_type<int>(min(as_type<float>(R123i.z), as_type<float>(R123i.x)));
        PV1iz = ((as_type<float>(R123i.x) > as_type<float>(R123i.z)) ? -1 : 0);
        // 4
        R127i.y = ((PV1iz == 0) ? (R126i.w) : (R127i.y));
        PS0i = as_type<int>(1.0 / as_type<float>(PV1ix));
        // 5
        PV1iz = as_type<int>(as_type<float>(R126i.y) * as_type<float>(PS0i));
        // 6
        PV0iy = as_type<int>(-(as_type<float>(PV1iz)) + 0.5);
        // 7
        R123i.x = ((R127i.y == 0) ? (0) : (PV0iy));
        // 8
        PV0iw =
            as_type<int>(max(as_type<float>(R3i.z), as_type<float>(R123i.x)));
        // 9
        PV1iz = as_type<int>(
            mul_nonIEEE(as_type<float>(R6i.x), as_type<float>(PV0iw)));
        // 10
        R0i.x = as_type<int>(
            mul_nonIEEE(as_type<float>(R4i.z), as_type<float>(PV1iz)) +
            as_type<float>(R0i.x));
        R0i.y = as_type<int>(
            mul_nonIEEE(as_type<float>(R5i.w), as_type<float>(PV1iz)) +
            as_type<float>(R0i.y));
    }
    if (activeMaskStackC[2] == true) {
        R3i.xyzw =
            as_type<int4>(tex0.sample(samplr0, float2(as_type<float>(R0i.x),
                                                      as_type<float>(R0i.y)))
                              .xyzw);
    }
    activeMaskStackC[1] =
        activeMaskStack[0] == true && activeMaskStackC[0] == true;
    // export
    out.passPixelColor0 =
        as_type<float4>(float4(as_type<float>(R3i.x), as_type<float>(R3i.y),
                               as_type<float>(R3i.z), as_type<float>(R3i.w)));
#endif
    return out;
}
