#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 */
float clampf(float);
unsigned char linear_sample_to_srgb(float);
unsigned char round(float);
int /*<<< orphan*/ shift_left_f(float *);
void yscale_out_rgba(float *sums, int width, unsigned char *out) {
  int i, j;
  float alpha;
  for (i = 0; i < width; i++) {
    alpha = clampf(sums[12]);
    if (alpha != 0) {
      for (j = 0; j < 3; j++) {
        sums[j * 4] /= alpha;
      }
    }
    for (j = 0; j < 3; j++) {
      out[j] = linear_sample_to_srgb(clampf(sums[j * 4]));
      shift_left_f(sums + j * 4);
    }
    out[3] = round(alpha * 255.0f);
    shift_left_f(sums + 12);
    sums += 16;
    out += 4;
  }
}


x86 assembly (clang, -O0):
<yscale_out_rgba>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1287 <yscale_out_rgba+0x147>
mov    -0x8(%rbp),%rax
movss  0x30(%rax),%xmm0
call   1040 <clampf@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1195 <yscale_out_rgba+0x55>
jp     1195 <yscale_out_rgba+0x55>
jmp    11d9 <yscale_out_rgba+0x99>
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jge    11d4 <yscale_out_rgba+0x94>
movss  -0x24(%rbp),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119c <yscale_out_rgba+0x5c>
jmp    11d9 <yscale_out_rgba+0x99>
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jge    1239 <yscale_out_rgba+0xf9>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
call   1040 <clampf@plt>
call   1030 <linear_sample_to_srgb@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1060 <shift_left_f@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e0 <yscale_out_rgba+0xa0>
movss  0xdbf(%rip),%xmm0
mulss  -0x24(%rbp),%xmm0
call   1050 <round@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x8(%rbp),%rdi
add    $0x30,%rdi
call   1060 <shift_left_f@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <yscale_out_rgba+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yscale_out_rgba>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1245 <yscale_out_rgba+0x105>
mov    %rdx,%r14
mov    %rdi,%rbx
add    $0x20,%rbx
mov    %esi,%r13d
xor    %ebp,%ebp
jmp    11ee <yscale_out_rgba+0xae>
nopw   0x0(%rax,%rax,1)
call   1040 <clampf@plt>
call   1030 <linear_sample_to_srgb@plt>
mov    %al,(%r14,%rbp,4)
mov    %r12,%rdi
call   1060 <shift_left_f@plt>
lea    -0x10(%rbx),%r12
movss  -0x10(%rbx),%xmm0
call   1040 <clampf@plt>
call   1030 <linear_sample_to_srgb@plt>
mov    %al,0x1(%r14,%rbp,4)
mov    %r12,%rdi
call   1060 <shift_left_f@plt>
movss  (%rbx),%xmm0
call   1040 <clampf@plt>
call   1030 <linear_sample_to_srgb@plt>
mov    %al,0x2(%r14,%rbp,4)
mov    %rbx,%rdi
call   1060 <shift_left_f@plt>
movss  0x4(%rsp),%xmm0
mulss  0xe31(%rip),%xmm0
call   1050 <round@plt>
mov    %al,0x3(%r14,%rbp,4)
mov    %r15,%rdi
call   1060 <shift_left_f@plt>
add    $0x40,%rbx
add    $0x1,%rbp
cmp    %ebp,%r13d
je     1245 <yscale_out_rgba+0x105>
lea    -0x20(%rbx),%r12
lea    0x10(%rbx),%r15
movss  0x10(%rbx),%xmm0
call   1040 <clampf@plt>
movaps %xmm0,%xmm3
ucomiss 0xdfa(%rip),%xmm0
movss  -0x20(%rbx),%xmm0
movss  %xmm3,0x4(%rsp)
jne    121d <yscale_out_rgba+0xdd>
jnp    1170 <yscale_out_rgba+0x30>
divss  %xmm3,%xmm0
movss  %xmm0,-0x20(%rbx)
movss  -0x10(%rbx),%xmm1
movss  (%rbx),%xmm2
divss  %xmm3,%xmm1
movss  %xmm1,-0x10(%rbx)
divss  %xmm3,%xmm2
movss  %xmm2,(%rbx)
jmp    1170 <yscale_out_rgba+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @yscale_out_rgba(float* %0, i32 %1, i8* nocapture writeonly %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %47
5: ; preds = %3, %22
%6 = phi float* [ %43, %22 ], [ %0, %3 ]
%7 = phi i32 [ %45, %22 ], [ 0, %3 ]
%8 = phi i8* [ %44, %22 ], [ %2, %3 ]
%9 = getelementptr inbounds float, float* %6, i64 12
%10 = load float, float* %9
%11 = tail call float @clampf(float %10)
%12 = fcmp une float %11, 0.000000e+00
%13 = load float, float* %6
br i1 %12, label %14, label %22
14: ; preds = %5
%15 = fdiv float %13, %11
store float %15, float* %6
%16 = getelementptr inbounds float, float* %6, i64 4
%17 = load float, float* %16
%18 = fdiv float %17, %11
store float %18, float* %16
%19 = getelementptr inbounds float, float* %6, i64 8
%20 = load float, float* %19
%21 = fdiv float %20, %11
store float %21, float* %19
br label %22
22: ; preds = %5, %14
%23 = phi float [ %15, %14 ], [ %13, %5 ]
%24 = tail call float @clampf(float %23)
%25 = tail call zeroext i8 @linear_sample_to_srgb(float %24)
store i8 %25, i8* %8
%26 = tail call i32 @shift_left_f(float* %6)
%27 = getelementptr inbounds float, float* %6, i64 4
%28 = load float, float* %27
%29 = tail call float @clampf(float %28)
%30 = tail call zeroext i8 @linear_sample_to_srgb(float %29)
%31 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %30, i8* %31
%32 = tail call i32 @shift_left_f(float* %27)
%33 = getelementptr inbounds float, float* %6, i64 8
%34 = load float, float* %33
%35 = tail call float @clampf(float %34)
%36 = tail call zeroext i8 @linear_sample_to_srgb(float %35)
%37 = getelementptr inbounds i8, i8* %8, i64 2
store i8 %36, i8* %37
%38 = tail call i32 @shift_left_f(float* %33)
%39 = fmul float %11, 2.550000e+02
%40 = tail call zeroext i8 @round(float %39)
%41 = getelementptr inbounds i8, i8* %8, i64 3
store i8 %40, i8* %41
%42 = tail call i32 @shift_left_f(float* %9)
%43 = getelementptr inbounds float, float* %6, i64 16
%44 = getelementptr inbounds i8, i8* %8, i64 4
%45 = add nuw nsw i32 %7, 1
%46 = icmp eq i32 %45, %1
br i1 %46, label %47, label %5
47: ; preds = %22, %3
ret void
}