import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_per_fused_add_bitwise_or_div_gt_maximum_mean_minimum_mul_pow_rsub_scalar_tensor_sqrt_sub_where_0(
    in_out_ptr1, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp67 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last')
    tmp68 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp70 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last')
    tmp71 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp80 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp81 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp83 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp84 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp0 = tl.full([1, 1], 2, tl.int64)
    tmp1 = tl.full([1, 1], 0, tl.int64)
    tmp3 = tmp0 < tmp0
    tmp4 = tl.load(in_ptr0 + tl.broadcast_to(4 * r0 + 2, [XBLOCK, RBLOCK]),
        tmp3, eviction_policy='evict_last', other=0.0)
    tmp5 = tl.load(in_ptr1 + tl.broadcast_to(4 * r0 + 2, [XBLOCK, RBLOCK]),
        tmp3, eviction_policy='evict_last', other=0.0)
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp7 = tl.full(tmp6.shape, 0.0, tmp6.dtype)
    tmp8 = tl.where(tmp3, tmp6, tmp7)
    tmp9 = tmp0 >= tmp0
    tl.full([1, 1], 4, tl.int64)
    tmp12 = tl.load(in_ptr0 + tl.broadcast_to(2 + 4 * r0 + 0, [XBLOCK,
        RBLOCK]), tmp9, eviction_policy='evict_last', other=0.0)
    tmp13 = tl.load(in_ptr1 + tl.broadcast_to(2 + 4 * r0 + 0, [XBLOCK,
        RBLOCK]), tmp9, eviction_policy='evict_last', other=0.0)
    tmp14 = triton_helpers.maximum(tmp12, tmp13)
    tmp15 = tl.full(tmp14.shape, 0.0, tmp14.dtype)
    tmp16 = tl.where(tmp9, tmp14, tmp15)
    tmp17 = tl.where(tmp3, tmp8, tmp16)
    tmp19 = tmp1 < tmp0
    tmp20 = tl.load(in_ptr0 + tl.broadcast_to(4 * r0 + 0, [XBLOCK, RBLOCK]),
        tmp19, eviction_policy='evict_last', other=0.0)
    tmp21 = tl.load(in_ptr1 + tl.broadcast_to(4 * r0 + 0, [XBLOCK, RBLOCK]),
        tmp19, eviction_policy='evict_last', other=0.0)
    tmp22 = triton_helpers.minimum(tmp20, tmp21)
    tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype)
    tmp24 = tl.where(tmp19, tmp22, tmp23)
    tmp25 = tmp1 >= tmp0
    tmp27 = tl.load(in_ptr0 + tl.broadcast_to(2 + 4 * r0 + -2, [XBLOCK,
        RBLOCK]), tmp25, eviction_policy='evict_last', other=0.0)
    tmp28 = tl.load(in_ptr1 + tl.broadcast_to(2 + 4 * r0 + -2, [XBLOCK,
        RBLOCK]), tmp25, eviction_policy='evict_last', other=0.0)
    tmp29 = triton_helpers.maximum(tmp27, tmp28)
    tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype)
    tmp31 = tl.where(tmp25, tmp29, tmp30)
    tmp32 = tl.where(tmp19, tmp24, tmp31)
    tmp33 = tmp17 - tmp32
    tmp34 = tl.full([1, 1], 3, tl.int64)
    tmp36 = tmp34 < tmp0
    tmp37 = tl.load(in_ptr0 + tl.broadcast_to(4 * r0 + 3, [XBLOCK, RBLOCK]),
        tmp36, eviction_policy='evict_last', other=0.0)
    tmp38 = tl.load(in_ptr1 + tl.broadcast_to(4 * r0 + 3, [XBLOCK, RBLOCK]),
        tmp36, eviction_policy='evict_last', other=0.0)
    tmp39 = triton_helpers.minimum(tmp37, tmp38)
    tmp40 = tl.full(tmp39.shape, 0.0, tmp39.dtype)
    tmp41 = tl.where(tmp36, tmp39, tmp40)
    tmp42 = tmp34 >= tmp0
    tmp44 = tl.load(in_ptr0 + tl.broadcast_to(2 + 4 * r0 + 1, [XBLOCK,
        RBLOCK]), tmp42, eviction_policy='evict_last', other=0.0)
    tmp45 = tl.load(in_ptr1 + tl.broadcast_to(2 + 4 * r0 + 1, [XBLOCK,
        RBLOCK]), tmp42, eviction_policy='evict_last', other=0.0)
    tmp46 = triton_helpers.maximum(tmp44, tmp45)
    tmp47 = tl.full(tmp46.shape, 0.0, tmp46.dtype)
    tmp48 = tl.where(tmp42, tmp46, tmp47)
    tmp49 = tl.where(tmp36, tmp41, tmp48)
    tmp50 = tl.full([1, 1], 1, tl.int64)
    tmp52 = tmp50 < tmp0
    tmp53 = tl.load(in_ptr0 + tl.broadcast_to(4 * r0 + 1, [XBLOCK, RBLOCK]),
        tmp52, eviction_policy='evict_last', other=0.0)
    tmp54 = tl.load(in_ptr1 + tl.broadcast_to(4 * r0 + 1, [XBLOCK, RBLOCK]),
        tmp52, eviction_policy='evict_last', other=0.0)
    tmp55 = triton_helpers.minimum(tmp53, tmp54)
    tmp56 = tl.full(tmp55.shape, 0.0, tmp55.dtype)
    tmp57 = tl.where(tmp52, tmp55, tmp56)
    tmp58 = tmp50 >= tmp0
    tmp60 = tl.load(in_ptr0 + tl.broadcast_to(2 + 4 * r0 + -1, [XBLOCK,
        RBLOCK]), tmp58, eviction_policy='evict_last', other=0.0)
    tmp61 = tl.load(in_ptr1 + tl.broadcast_to(2 + 4 * r0 + -1, [XBLOCK,
        RBLOCK]), tmp58, eviction_policy='evict_last', other=0.0)
    tmp62 = triton_helpers.maximum(tmp60, tmp61)
    tmp63 = tl.full(tmp62.shape, 0.0, tmp62.dtype)
    tmp64 = tl.where(tmp58, tmp62, tmp63)
    tmp65 = tl.where(tmp52, tmp57, tmp64)
    tmp66 = tmp49 - tmp65
    tmp69 = tmp67 > tmp68
    tmp72 = tmp70 > tmp71
    tmp73 = tmp69 | tmp72
    tmp74 = tl.where(tmp73, tmp1, tmp50)
    tmp75 = tmp74.to(tl.float32)
    tmp76 = triton_helpers.minimum(tmp68, tmp71)
    tmp77 = triton_helpers.maximum(tmp70, tmp67)
    tmp78 = tmp76 - tmp77
    tmp79 = tmp75 * tmp78
    tmp82 = tmp80 > tmp81
    tmp85 = tmp83 > tmp84
    tmp86 = tmp82 | tmp85
    tmp87 = tl.where(tmp86, tmp1, tmp50)
    tmp88 = tmp87.to(tl.float32)
    tmp89 = triton_helpers.minimum(tmp81, tmp84)
    tmp90 = triton_helpers.maximum(tmp83, tmp80)
    tmp91 = tmp89 - tmp90
    tmp92 = tmp88 * tmp91
    tmp93 = tmp79 * tmp92
    tmp94 = tmp68 - tmp70
    tmp95 = tmp81 - tmp83
    tmp96 = tmp94 * tmp95
    tmp97 = tmp71 - tmp67
    tmp98 = tmp84 - tmp80
    tmp99 = tmp97 * tmp98
    tmp100 = tmp96 + tmp99
    tmp101 = tmp100 - tmp93
    tmp102 = tmp67 + tmp71
    tmp103 = 0.5
    tmp104 = tmp102 * tmp103
    tmp105 = tmp70 + tmp68
    tmp106 = tmp105 * tmp103
    tmp107 = tmp104 - tmp106
    tmp108 = tmp107 * tmp107
    tmp109 = tmp80 + tmp84
    tmp110 = tmp109 * tmp103
    tmp111 = tmp83 + tmp81
    tmp112 = tmp111 * tmp103
    tmp113 = tmp110 - tmp112
    tmp114 = tmp113 * tmp113
    tmp115 = tmp108 + tmp114
    tmp116 = libdevice.sqrt(tmp115)
    tmp117 = tmp116 * tmp116
    tmp118 = tmp33 * tmp33
    tmp119 = tmp66 * tmp66
    tmp120 = tmp118 + tmp119
    tmp121 = libdevice.sqrt(tmp120)
    tmp122 = tmp121 * tmp121
    tmp123 = tmp117 / tmp122
    tmp124 = tmp93 / tmp101
    tmp125 = 1.0
    tmp126 = tmp125 - tmp124
    tmp127 = tmp126 + tmp123
    tmp128 = tl.broadcast_to(tmp127, [XBLOCK, RBLOCK])
    tmp130 = tl.sum(tmp128, 1)[:, None]
    tmp131 = 4.0
    tmp132 = tmp130 / tmp131
    tl.debug_barrier()
    tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp132, None)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4), (4, 1))
    assert_size_stride(arg1_1, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf5 = empty_strided_cuda((), (), torch.float32)
        buf6 = buf5
        del buf5
        get_raw_stream(0)
        triton_per_fused_add_bitwise_or_div_gt_maximum_mean_minimum_mul_pow_rsub_scalar_tensor_sqrt_sub_where_0[
            grid(1)](buf6, arg1_1, arg0_1, 1, 4, XBLOCK=1, num_warps=2,
            num_stages=1)
        del arg0_1
        del arg1_1
    return buf6,


class CIoUNew(nn.Module):

    def __init__(self):
        super(CIoUNew, self).__init__()

    def forward(self, input_0, input_1):
        arg0_1 = input_0
        arg1_1 = input_1
        output = call([arg0_1, arg1_1])
        return output[0]


Measured latency_ms: 0.015534