#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
imReduceHalfBox1sRGB(unsigned char *dst, unsigned char *src, int bytesperpixel,
                     int bytesperline, float *dithersum) {
  int i, offset[4];
  float sum0;
  offset[0] = 0;
  offset[1] = bytesperpixel;
  offset[2] = bytesperline;
  offset[3] = bytesperline + bytesperpixel;
  sum0 = 0.0f;
  for (i = 0; i < 4; i++)
    sum0 += srgb2linear((float)src[offset[i] + 0]);
  dst[0] = (unsigned char)(fmaxf(
      0.0f, fminf(255.0f, linear2srgb(sum0 * 0.25f) + 0.5f)));
  return;
}


x86 assembly (clang, -O0):
<imReduceHalfBox1sRGB>:
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)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11c6 <imReduceHalfBox1sRGB+0x86>
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,%xmm0
addss  -0x44(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1185 <imReduceHalfBox1sRGB+0x45>
movss  0xe3a(%rip),%xmm0
mulss  -0x44(%rbp),%xmm0
call   1030 <linear2srgb@plt>
cvtsi2ss %rax,%xmm0
movss  0xe1f(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%rdi
movss  0xe0a(%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)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imReduceHalfBox1sRGB>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
lea    (%r15,%r12,1),%ebp
movzbl (%rsi),%eax
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0xc(%rsp)
movslq %r12d,%rax
movzbl (%rbx,%rax,1),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movslq %r15d,%rax
movzbl (%rbx,%rax,1),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movslq %ebp,%rax
movzbl (%rbx,%rax,1),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1040 <srgb2linear@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xc(%rsp),%xmm0
mulss  0xe13(%rip),%xmm0
call   1030 <linear2srgb@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xe02(%rip),%xmm0
cvttss2si %xmm0,%rdi
movss  0xdf9(%rip),%xmm0
call   1050 <fminf@plt>
xorps  %xmm0,%xmm0
mov    %eax,%edi
call   1060 <fmaxf@plt>
mov    %al,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @imReduceHalfBox1sRGB(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
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
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 0
store i32 0, i32* %14
%15 = load i32, i32* %8
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 1
store i32 %15, i32* %16
%17 = load i32, i32* %9
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 2
store i32 %17, i32* %18
%19 = load i32, i32* %9
%20 = load i32, i32* %8
%21 = add nsw i32 %19, %20
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 3
store i32 %21, i32* %22
store float 0.000000e+00, float* %13
store i32 0, i32* %11
br label %23
23: ; preds = %41, %5
%24 = load i32, i32* %11
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %44
26: ; preds = %23
%27 = load i8*, i8** %7
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 0
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %27, i64 %33
%35 = load i8, i8* %34
%36 = uitofp i8 %35 to float
%37 = call i64 @srgb2linear(float %36)
%38 = sitofp i64 %37 to float
%39 = load float, float* %13
%40 = fadd float %39, %38
store float %40, float* %13
br label %41
41: ; preds = %26
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %23
44: ; preds = %23
%45 = load float, float* %13
%46 = fmul float %45, 2.500000e-01
%47 = call i64 @linear2srgb(float %46)
%48 = sitofp i64 %47 to float
%49 = fadd float %48, 5.000000e-01
%50 = fptosi float %49 to i64
%51 = call i32 @fminf(float 2.550000e+02, i64 %50)
%52 = call i64 @fmaxf(float 0.000000e+00, i32 %51)
%53 = trunc i64 %52 to i8
%54 = load i8*, i8** %6
%55 = getelementptr inbounds i8, i8* %54, i64 0
store i8 %53, i8* %55
ret void
}

LLVM IR (-O2):
define void @imReduceHalfBox1sRGB(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 = sext i32 %2 to i64
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = uitofp i8 %13 to float
%15 = tail call i64 @srgb2linear(float %14)
%16 = sitofp i64 %15 to float
%17 = fadd float %10, %16
%18 = sext i32 %3 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = uitofp i8 %20 to float
%22 = tail call i64 @srgb2linear(float %21)
%23 = sitofp i64 %22 to float
%24 = fadd float %17, %23
%25 = sext i32 %6 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = load i8, i8* %26
%28 = uitofp i8 %27 to float
%29 = tail call i64 @srgb2linear(float %28)
%30 = sitofp i64 %29 to float
%31 = fadd float %24, %30
%32 = fmul float %31, 2.500000e-01
%33 = tail call i64 @linear2srgb(float %32)
%34 = sitofp i64 %33 to float
%35 = fadd float %34, 5.000000e-01
%36 = fptosi float %35 to i64
%37 = tail call i32 @fminf(float 2.550000e+02, i64 %36)
%38 = tail call i64 @fmaxf(float 0.000000e+00, i32 %37)
%39 = trunc i64 %38 to i8
store i8 %39, i8* %0
ret void
}