#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 clip(double);
void contrast_bright(int *f, int w, int h, double p, double q) {
  int i, j;
  int pint, qint;
  pint = p * 65536;
  qint = q * 65536;
  for (j = 0; j < h; j++) {
    for (i = 0; i < w; i++) {
      *f = clip(p * (*f) + q);
      f++;
    }
  }
}


x86 assembly (clang, -O0):
<contrast_bright>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  0xecc(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
movsd  0xeb8(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ce <contrast_bright+0xbe>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bb <contrast_bright+0xab>
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
cvtsi2sdl (%rax),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <clip@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116e <contrast_bright+0x5e>
jmp    11c0 <contrast_bright+0xb0>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115b <contrast_bright+0x4b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contrast_bright>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %edx,%edx
jle    118c <contrast_bright+0x7c>
movapd %xmm0,%xmm2
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %r12d,%r12d
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
jmp    1149 <contrast_bright+0x39>
nopl   (%rax)
add    $0x1,%r12d
cmp    %r14d,%r12d
je     118c <contrast_bright+0x7c>
test   %r15d,%r15d
jle    1140 <contrast_bright+0x30>
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sdl (%rbx),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <clip@plt>
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
mov    %eax,(%rbx)
add    $0x4,%rbx
add    $0xffffffff,%ebp
jne    1160 <contrast_bright+0x50>
jmp    1140 <contrast_bright+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @contrast_bright(i32* %0, i32 %1, i32 %2, double %3, double %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double %3, double* %9
store double %4, double* %10
%15 = load double, double* %9
%16 = fmul double %15, 6.553600e+04
%17 = fptosi double %16 to i32
store i32 %17, i32* %13
%18 = load double, double* %10
%19 = fmul double %18, 6.553600e+04
%20 = fptosi double %19 to i32
store i32 %20, i32* %14
store i32 0, i32* %12
br label %21
21: ; preds = %45, %5
%22 = load i32, i32* %12
%23 = load i32, i32* %8
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %48
25: ; preds = %21
store i32 0, i32* %11
br label %26
26: ; preds = %41, %25
%27 = load i32, i32* %11
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %44
30: ; preds = %26
%31 = load double, double* %9
%32 = load i32*, i32** %6
%33 = load i32, i32* %32
%34 = sitofp i32 %33 to double
%35 = load double, double* %10
%36 = call double @llvm.fmuladd.f64(double %31, double %34, double %35)
%37 = call i32 @clip(double %36)
%38 = load i32*, i32** %6
store i32 %37, i32* %38
%39 = load i32*, i32** %6
%40 = getelementptr inbounds i32, i32* %39, i32 1
store i32* %40, i32** %6
br label %41
41: ; preds = %30
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %26
44: ; preds = %26
br label %45
45: ; preds = %44
%46 = load i32, i32* %12
%47 = add nsw i32 %46, 1
store i32 %47, i32* %12
br label %21
48: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @contrast_bright(i32* nocapture %0, i32 %1, i32 %2, double %3, double %4) {
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %26
7: ; preds = %5
%8 = icmp sgt i32 %1, 0
br label %9
9: ; preds = %7, %22
%10 = phi i32* [ %0, %7 ], [ %23, %22 ]
%11 = phi i32 [ 0, %7 ], [ %24, %22 ]
br i1 %8, label %12, label %22
12: ; preds = %9, %12
%13 = phi i32* [ %19, %12 ], [ %10, %9 ]
%14 = phi i32 [ %20, %12 ], [ 0, %9 ]
%15 = load i32, i32* %13
%16 = sitofp i32 %15 to double
%17 = tail call double @llvm.fmuladd.f64(double %3, double %16, double %4)
%18 = tail call i32 @clip(double %17)
store i32 %18, i32* %13
%19 = getelementptr inbounds i32, i32* %13, i64 1
%20 = add nuw nsw i32 %14, 1
%21 = icmp eq i32 %20, %1
br i1 %21, label %22, label %12
22: ; preds = %12, %9
%23 = phi i32* [ %10, %9 ], [ %19, %12 ]
%24 = add nuw nsw i32 %11, 1
%25 = icmp eq i32 %24, %2
br i1 %25, label %26, label %9
26: ; preds = %22, %5
ret void
}