#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 */
int /*<<< orphan*/ add_sample_to_sum_f(float, float *, float *);
int /*<<< orphan*/ dump_out(float *, float **, int);
void xscale_down_ga(unsigned char *in, int in_width, float *out, int out_width,
                    float *coeff_buf, int *border_buf) {
  int i, j;
  float alpha, sum[2][4] = {{0.0f}};
  for (i = 0; i < out_width; i++) {
    for (j = border_buf[0]; j > 0; j--) {
      alpha = in[1] / 255.0f;
      add_sample_to_sum_f(in[0] * alpha, coeff_buf, sum[0]);
      add_sample_to_sum_f(alpha, coeff_buf, sum[1]);
      in += 2;
      coeff_buf += 4;
    }
    dump_out(out, sum, 2);
    out += 2;
    border_buf++;
  }
}


x86 assembly (clang, -O0):
<xscale_down_ga>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1232 <xscale_down_ga+0x102>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    11fa <xscale_down_ga+0xca>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cvtsi2ss %eax,%xmm0
movss  0xe68(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cvtsi2ss %eax,%xmm0
mulss  -0x3c(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1050 <add_sample_to_sum_f@plt>
movss  -0x3c(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
lea    -0x60(%rbp),%rsi
add    $0x10,%rsi
call   1050 <add_sample_to_sum_f@plt>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    117a <xscale_down_ga+0x4a>
mov    -0x18(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x2,%edx
call   1030 <dump_out@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1165 <xscale_down_ga+0x35>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xscale_down_ga>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
mov    %ecx,0x8(%rsp)
test   %ecx,%ecx
jle    120b <xscale_down_ga+0xeb>
mov    %r8,%rbx
mov    %rdx,%r12
mov    %rdi,%rbp
xor    %r14d,%r14d
lea    0x30(%rsp),%r13
lea    0x20(%rsp),%r15
jmp    118d <xscale_down_ga+0x6d>
nop
mov    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <dump_out@plt>
add    $0x8,%r12
mov    0x18(%rsp),%r9
add    $0x4,%r9
add    $0x1,%r14d
cmp    0x8(%rsp),%r14d
je     120b <xscale_down_ga+0xeb>
mov    %r12,0x10(%rsp)
mov    (%r9),%r12d
test   %r12d,%r12d
mov    %r9,0x18(%rsp)
jle    1160 <xscale_down_ga+0x40>
add    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%rbp),%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
divss  0xe3d(%rip),%xmm1
movss  %xmm1,0xc(%rsp)
movzbl 0x0(%rbp),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
mulss  %xmm1,%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <add_sample_to_sum_f@plt>
movss  0xc(%rsp),%xmm0
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <add_sample_to_sum_f@plt>
add    $0x2,%rbp
add    $0x10,%rbx
add    $0xffffffff,%r12d
cmp    $0x1,%r12d
ja     11b0 <xscale_down_ga+0x90>
jmp    1160 <xscale_down_ga+0x40>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @xscale_down_ga(i8* %0, i32 %1, float* %2, i32 %3, float* %4, i32* %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca float*
%10 = alloca i32
%11 = alloca float*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca float
%16 = alloca [2 x [4 x float]]
store i8* %0, i8** %7
store i32 %1, i32* %8
store float* %2, float** %9
store i32 %3, i32* %10
store float* %4, float** %11
store i32* %5, i32** %12
%17 = bitcast [2 x [4 x float]]* %16 to i8*
store i32 0, i32* %13
br label %18
18: ; preds = %68, %6
%19 = load i32, i32* %13
%20 = load i32, i32* %10
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %71
22: ; preds = %18
%23 = load i32*, i32** %12
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = load i32, i32* %24
store i32 %25, i32* %14
br label %26
26: ; preds = %56, %22
%27 = load i32, i32* %14
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %59
29: ; preds = %26
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = sitofp i32 %33 to float
%35 = fdiv float %34, 2.550000e+02
store float %35, float* %15
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = sitofp i32 %39 to float
%41 = load float, float* %15
%42 = fmul float %40, %41
%43 = load float*, float** %11
%44 = getelementptr inbounds [2 x [4 x float]], [2 x [4 x float]]* %16, i64 0, i64 0
%45 = getelementptr inbounds [4 x float], [4 x float]* %44, i64 0, i64 0
%46 = call i32 @add_sample_to_sum_f(float %42, float* %43, float* %45)
%47 = load float, float* %15
%48 = load float*, float** %11
%49 = getelementptr inbounds [2 x [4 x float]], [2 x [4 x float]]* %16, i64 0, i64 1
%50 = getelementptr inbounds [4 x float], [4 x float]* %49, i64 0, i64 0
%51 = call i32 @add_sample_to_sum_f(float %47, float* %48, float* %50)
%52 = load i8*, i8** %7
%53 = getelementptr inbounds i8, i8* %52, i64 2
store i8* %53, i8** %7
%54 = load float*, float** %11
%55 = getelementptr inbounds float, float* %54, i64 4
store float* %55, float** %11
br label %56
56: ; preds = %29
%57 = load i32, i32* %14
%58 = add nsw i32 %57, -1
store i32 %58, i32* %14
br label %26
59: ; preds = %26
%60 = load float*, float** %9
%61 = getelementptr inbounds [2 x [4 x float]], [2 x [4 x float]]* %16, i64 0, i64 0
%62 = bitcast [4 x float]* %61 to float**
%63 = call i32 @dump_out(float* %60, float** %62, i32 2)
%64 = load float*, float** %9
%65 = getelementptr inbounds float, float* %64, i64 2
store float* %65, float** %9
%66 = load i32*, i32** %12
%67 = getelementptr inbounds i32, i32* %66, i32 1
store i32* %67, i32** %12
br label %68
68: ; preds = %59
%69 = load i32, i32* %13
%70 = add nsw i32 %69, 1
store i32 %70, i32* %13
br label %18
71: ; preds = %18
ret void
}

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