#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ fmaxf(float, int /*<<< orphan*/);
int /*<<< orphan*/ fminf(float, scalar_t__);
scalar_t__ linear2srgb(float);
scalar_t__ srgb2linear(float);
__attribute__((always_)) void
imReduceHalfBox2sRGB(unsigned char *dst, unsigned char *src, int bytesperpixel,
                     int bytesperline, float *dithersum) {
  int i, offset[4];
  float sum0, sum1;
  offset[0] = 0;
  offset[1] = bytesperpixel;
  offset[2] = bytesperline;
  offset[3] = bytesperline + bytesperpixel;
  sum0 = 0.0f;
  sum1 = 0.0f;
  for (i = 0; i < 4; i++) {
    sum0 += srgb2linear((float)src[offset[i] + 0]);
    sum1 += srgb2linear((float)src[offset[i] + 1]);
  }
  dst[0] = (unsigned char)(fmaxf(
      0.0f, fminf(255.0f, linear2srgb(sum0 * 0.25f) + 0.5f)));
  dst[1] = (unsigned char)(fmaxf(
      0.0f, fminf(255.0f, linear2srgb(sum1 * 0.25f) + 0.5f)));
  return;
}


x86 assembly (clang, -O0):
<imReduceHalfBox2sRGB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x44(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11fc <imReduceHalfBox2sRGB+0xbc>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movslq -0x40(%rbp,%rcx,4),%rcx
movzbl (%rax,%rcx,1),%eax
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
cvtsi2ss %rax,%xmm1
movss  -0x44(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x10(%rbp),%rcx
movslq -0x24(%rbp),%rax
movslq -0x40(%rbp,%rax,4),%rax
movzbl 0x1(%rax,%rcx,1),%eax
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
cvtsi2ss %rax,%xmm0
addss  -0x48(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118d <imReduceHalfBox2sRGB+0x4d>
movss  0xe04(%rip),%xmm0
mulss  -0x44(%rbp),%xmm0
call   1030 <linear2srgb@plt>
cvtsi2ss %rax,%xmm0
movss  0xde9(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%rdi
movss  0xdd4(%rip),%xmm0
call   1050 <fminf@plt>
mov    %eax,%edi
xorps  %xmm0,%xmm0
call   1060 <fmaxf@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
movss  0xdbd(%rip),%xmm0
mulss  -0x48(%rbp),%xmm0
call   1030 <linear2srgb@plt>
cvtsi2ss %rax,%xmm0
movss  0xda2(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%rdi
movss  0xd8d(%rip),%xmm0
call   1050 <fminf@plt>
mov    %eax,%edi
xorps  %xmm0,%xmm0
call   1060 <fmaxf@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imReduceHalfBox2sRGB>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
lea    (%r15,%r12,1),%r13d
movzbl (%rsi),%eax
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,(%rsp)
movzbl 0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0x4(%rsp)
movslq %r12d,%rbp
movzbl (%rbx,%rbp,1),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  (%rsp),%xmm0
movss  %xmm0,(%rsp)
movzbl 0x1(%rbx,%rbp,1),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0x4(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
movslq %r15d,%rbp
movzbl (%rbx,%rbp,1),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  (%rsp),%xmm0
movss  %xmm0,(%rsp)
movzbl 0x1(%rbx,%rbp,1),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0x4(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
movslq %r13d,%rbp
movzbl (%rbx,%rbp,1),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  (%rsp),%xmm0
movss  %xmm0,(%rsp)
movzbl 0x1(%rbx,%rbp,1),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0x4(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
movss  (%rsp),%xmm0
mulss  0xd83(%rip),%xmm0
call   1030 <linear2srgb@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xd72(%rip),%xmm0
cvttss2si %xmm0,%rdi
movss  0xd69(%rip),%xmm0
call   1050 <fminf@plt>
xorps  %xmm0,%xmm0
mov    %eax,%edi
call   1060 <fmaxf@plt>
mov    %al,(%r14)
movss  0x4(%rsp),%xmm0
mulss  0xd41(%rip),%xmm0
call   1030 <linear2srgb@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xd30(%rip),%xmm0
cvttss2si %xmm0,%rdi
movss  0xd27(%rip),%xmm0
call   1050 <fminf@plt>
xorps  %xmm0,%xmm0
mov    %eax,%edi
call   1060 <fmaxf@plt>
mov    %al,0x1(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @imReduceHalfBox2sRGB(i8* %0, i8* %1, i32 %2, i32 %3, float* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca float*
%11 = alloca i32
%12 = alloca [4 x i32]
%13 = alloca float
%14 = alloca float
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store float* %4, float** %10
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 0
store i32 0, i32* %15
%16 = load i32, i32* %8
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 1
store i32 %16, i32* %17
%18 = load i32, i32* %9
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 2
store i32 %18, i32* %19
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = add nsw i32 %20, %21
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 3
store i32 %22, i32* %23
store float 0.000000e+00, float* %13
store float 0.000000e+00, float* %14
store i32 0, i32* %11
br label %24
24: ; preds = %56, %5
%25 = load i32, i32* %11
%26 = icmp slt i32 %25, 4
br i1 %26, label %27, label %59
27: ; preds = %24
%28 = load i8*, i8** %7
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = add nsw i32 %32, 0
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %28, i64 %34
%36 = load i8, i8* %35
%37 = uitofp i8 %36 to float
%38 = call i64 @srgb2linear(float %37)
%39 = sitofp i64 %38 to float
%40 = load float, float* %13
%41 = fadd float %40, %39
store float %41, float* %13
%42 = load i8*, i8** %7
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %42, i64 %48
%50 = load i8, i8* %49
%51 = uitofp i8 %50 to float
%52 = call i64 @srgb2linear(float %51)
%53 = sitofp i64 %52 to float
%54 = load float, float* %14
%55 = fadd float %54, %53
store float %55, float* %14
br label %56
56: ; preds = %27
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %24
59: ; preds = %24
%60 = load float, float* %13
%61 = fmul float %60, 2.500000e-01
%62 = call i64 @linear2srgb(float %61)
%63 = sitofp i64 %62 to float
%64 = fadd float %63, 5.000000e-01
%65 = fptosi float %64 to i64
%66 = call i32 @fminf(float 2.550000e+02, i64 %65)
%67 = call i64 @fmaxf(float 0.000000e+00, i32 %66)
%68 = trunc i64 %67 to i8
%69 = load i8*, i8** %6
%70 = getelementptr inbounds i8, i8* %69, i64 0
store i8 %68, i8* %70
%71 = load float, float* %14
%72 = fmul float %71, 2.500000e-01
%73 = call i64 @linear2srgb(float %72)
%74 = sitofp i64 %73 to float
%75 = fadd float %74, 5.000000e-01
%76 = fptosi float %75 to i64
%77 = call i32 @fminf(float 2.550000e+02, i64 %76)
%78 = call i64 @fmaxf(float 0.000000e+00, i32 %77)
%79 = trunc i64 %78 to i8
%80 = load i8*, i8** %6
%81 = getelementptr inbounds i8, i8* %80, i64 1
store i8 %79, i8* %81
ret void
}

LLVM IR (-O2):
define void @imReduceHalfBox2sRGB(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2, i32 %3, float* nocapture readnone %4) {
%6 = add nsw i32 %3, %2
%7 = load i8, i8* %1
%8 = uitofp i8 %7 to float
%9 = tail call i64 @srgb2linear(float %8)
%10 = sitofp i64 %9 to float
%11 = getelementptr inbounds i8, i8* %1, i64 1
%12 = load i8, i8* %11
%13 = uitofp i8 %12 to float
%14 = tail call i64 @srgb2linear(float %13)
%15 = sitofp i64 %14 to float
%16 = sext i32 %2 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
%19 = uitofp i8 %18 to float
%20 = tail call i64 @srgb2linear(float %19)
%21 = sitofp i64 %20 to float
%22 = fadd float %10, %21
%23 = add nsw i32 %2, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
%26 = load i8, i8* %25
%27 = uitofp i8 %26 to float
%28 = tail call i64 @srgb2linear(float %27)
%29 = sitofp i64 %28 to float
%30 = fadd float %15, %29
%31 = sext i32 %3 to i64
%32 = getelementptr inbounds i8, i8* %1, i64 %31
%33 = load i8, i8* %32
%34 = uitofp i8 %33 to float
%35 = tail call i64 @srgb2linear(float %34)
%36 = sitofp i64 %35 to float
%37 = fadd float %22, %36
%38 = add nsw i32 %3, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %1, i64 %39
%41 = load i8, i8* %40
%42 = uitofp i8 %41 to float
%43 = tail call i64 @srgb2linear(float %42)
%44 = sitofp i64 %43 to float
%45 = fadd float %30, %44
%46 = sext i32 %6 to i64
%47 = getelementptr inbounds i8, i8* %1, i64 %46
%48 = load i8, i8* %47
%49 = uitofp i8 %48 to float
%50 = tail call i64 @srgb2linear(float %49)
%51 = sitofp i64 %50 to float
%52 = fadd float %37, %51
%53 = add nsw i32 %6, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %1, i64 %54
%56 = load i8, i8* %55
%57 = uitofp i8 %56 to float
%58 = tail call i64 @srgb2linear(float %57)
%59 = sitofp i64 %58 to float
%60 = fadd float %45, %59
%61 = fmul float %52, 2.500000e-01
%62 = tail call i64 @linear2srgb(float %61)
%63 = sitofp i64 %62 to float
%64 = fadd float %63, 5.000000e-01
%65 = fptosi float %64 to i64
%66 = tail call i32 @fminf(float 2.550000e+02, i64 %65)
%67 = tail call i64 @fmaxf(float 0.000000e+00, i32 %66)
%68 = trunc i64 %67 to i8
store i8 %68, i8* %0
%69 = fmul float %60, 2.500000e-01
%70 = tail call i64 @linear2srgb(float %69)
%71 = sitofp i64 %70 to float
%72 = fadd float %71, 5.000000e-01
%73 = fptosi float %72 to i64
%74 = tail call i32 @fminf(float 2.550000e+02, i64 %73)
%75 = tail call i64 @fmaxf(float 0.000000e+00, i32 %74)
%76 = trunc i64 %75 to i8
%77 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %76, i8* %77
ret void
}