#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 */
unsigned char clamp8(float);
float clampf(float);
unsigned char f2i(float);
int /*<<< orphan*/ shift_left_f(float *);
void yscale_out_ga(float *sums, int width, unsigned char *out) {
  int i;
  float alpha;
  for (i = 0; i < width; i++) {
    alpha = clampf(sums[4]);
    if (alpha != 0) {
      sums[0] /= alpha;
    }
    out[0] = clamp8(sums[0]);
    shift_left_f(sums);
    out[1] = f2i(alpha * 255.0f);
    shift_left_f(sums + 4);
    sums += 8;
    out += 2;
  }
}


x86 assembly (clang, -O0):
<yscale_out_ga>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    1216 <yscale_out_ga+0xd6>
mov    -0x8(%rbp),%rax
movss  0x10(%rax),%xmm0
call   1040 <clampf@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1195 <yscale_out_ga+0x55>
jp     1195 <yscale_out_ga+0x55>
jmp    11aa <yscale_out_ga+0x6a>
movss  -0x20(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1030 <clamp8@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
call   1060 <shift_left_f@plt>
movss  0xe30(%rip),%xmm0
mulss  -0x20(%rbp),%xmm0
call   1050 <f2i@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
call   1060 <shift_left_f@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <yscale_out_ga+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yscale_out_ga>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    11ce <yscale_out_ga+0x8e>
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %esi,%r12d
xor    %r13d,%r13d
jmp    119e <yscale_out_ga+0x5e>
nop
call   1030 <clamp8@plt>
mov    %al,(%r14,%r13,2)
mov    %rbx,%rdi
call   1060 <shift_left_f@plt>
movss  0xc(%rsp),%xmm0
mulss  0xe81(%rip),%xmm0
call   1050 <f2i@plt>
mov    %al,0x1(%r14,%r13,2)
mov    %r15,%rdi
call   1060 <shift_left_f@plt>
add    $0x20,%rbx
add    $0x1,%r13
cmp    %r13d,%r12d
je     11ce <yscale_out_ga+0x8e>
lea    0x10(%rbx),%r15
movss  0x10(%rbx),%xmm0
call   1040 <clampf@plt>
movaps %xmm0,%xmm1
ucomiss 0xe4e(%rip),%xmm0
movss  (%rbx),%xmm0
movss  %xmm1,0xc(%rsp)
jne    11c4 <yscale_out_ga+0x84>
jnp    1160 <yscale_out_ga+0x20>
divss  %xmm1,%xmm0
movss  %xmm0,(%rbx)
jmp    1160 <yscale_out_ga+0x20>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @yscale_out_ga(float* %0, i32 %1, i8* nocapture writeonly %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %28
5: ; preds = %3, %16
%6 = phi float* [ %24, %16 ], [ %0, %3 ]
%7 = phi i32 [ %26, %16 ], [ 0, %3 ]
%8 = phi i8* [ %25, %16 ], [ %2, %3 ]
%9 = getelementptr inbounds float, float* %6, i64 4
%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 %16
14: ; preds = %5
%15 = fdiv float %13, %11
store float %15, float* %6
br label %16
16: ; preds = %5, %14
%17 = phi float [ %15, %14 ], [ %13, %5 ]
%18 = tail call zeroext i8 @clamp8(float %17)
store i8 %18, i8* %8
%19 = tail call i32 @shift_left_f(float* %6)
%20 = fmul float %11, 2.550000e+02
%21 = tail call zeroext i8 @f2i(float %20)
%22 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %21, i8* %22
%23 = tail call i32 @shift_left_f(float* %9)
%24 = getelementptr inbounds float, float* %6, i64 8
%25 = getelementptr inbounds i8, i8* %8, i64 2
%26 = add nuw nsw i32 %7, 1
%27 = icmp eq i32 %26, %1
br i1 %27, label %28, label %5
28: ; preds = %16, %3
ret void
}