#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 */
double pow(double, double);
int calcDistortion(int x, double gamma0, double gamma1) {
  double xf = (double)x / 300.0;
  double gamma;
  double yf;
  xf = (xf > 0.0 ? (xf < 1.0 ? xf : 1.0) : 0.0);
  gamma = gamma0 * pow((gamma1 / gamma0), xf);
  yf = pow(xf, gamma);
  return (int)((yf * 24576.0) + 0.5);
}


x86 assembly (clang, -O0):
<calcDistortion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xece(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1190 <calcDistortion+0x80>
movsd  0xeb3(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    116f <calcDistortion+0x5f>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1181 <calcDistortion+0x71>
movsd  0xe91(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1181 <calcDistortion+0x71>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    119d <calcDistortion+0x8d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    119d <calcDistortion+0x8d>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <pow@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe19(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe15(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcDistortion>:
sub    $0x28,%rsp
movapd %xmm1,%xmm3
movapd %xmm0,%xmm2
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
divsd  0xecf(%rip),%xmm0
xorpd  %xmm1,%xmm1
cmpltsd %xmm0,%xmm1
minsd  0xec6(%rip),%xmm0
andpd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
divsd  %xmm2,%xmm3
movapd %xmm3,%xmm0
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
call   1030 <pow@plt>
mulsd  0xe9a(%rip),%xmm0
addsd  0xe9a(%rip),%xmm0
cvttsd2si %xmm0,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
define i32 @calcDistortion(i32 %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
store double %2, double* %6
%10 = load i32, i32* %4
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, 3.000000e+02
store double %12, double* %7
%13 = load double, double* %7
%14 = fcmp ogt double %13, 0.000000e+00
br i1 %14, label %15, label %23
15: ; preds = %3
%16 = load double, double* %7
%17 = fcmp olt double %16, 1.000000e+00
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load double, double* %7
br label %21
20: ; preds = %15
br label %21
21: ; preds = %20, %18
%22 = phi double [ %19, %18 ], [ 1.000000e+00, %20 ]
br label %24
23: ; preds = %3
br label %24
24: ; preds = %23, %21
%25 = phi double [ %22, %21 ], [ 0.000000e+00, %23 ]
store double %25, double* %7
%26 = load double, double* %5
%27 = load double, double* %6
%28 = load double, double* %5
%29 = fdiv double %27, %28
%30 = load double, double* %7
%31 = call double @pow(double %29, double %30)
%32 = fmul double %26, %31
store double %32, double* %8
%33 = load double, double* %7
%34 = load double, double* %8
%35 = call double @pow(double %33, double %34)
store double %35, double* %9
%36 = load double, double* %9
%37 = call double @llvm.fmuladd.f64(double %36, double 2.457600e+04, double 5.000000e-01)
%38 = fptosi double %37 to i32
ret i32 %38
}

LLVM IR (-O2):
define i32 @calcDistortion(i32 %0, double %1, double %2) {
%4 = sitofp i32 %0 to double
%5 = fdiv double %4, 3.000000e+02
%6 = fcmp ogt double %5, 0.000000e+00
%7 = fcmp olt double %5, 1.000000e+00
%8 = select i1 %7, double %5, double 1.000000e+00
%9 = select i1 %6, double %8, double 0.000000e+00
%10 = fdiv double %2, %1
%11 = tail call double @pow(double %10, double %9)
%12 = fmul double %11, %1
%13 = tail call double @pow(double %9, double %12)
%14 = tail call double @llvm.fmuladd.f64(double %13, double 2.457600e+04, double 5.000000e-01)
%15 = fptosi double %14 to i32
ret i32 %15
}