#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 */
scalar_t__ ceil(int);
double fabs(int);
int floor(double);
int pow(int, double);
void wts_cell_calc_h(double inc, int *px1, int *pxwidth, double *pp1,
                     double memw) {
  double minrep = pow(2, memw) * 50 / pow(2, 7.5);
  int m1 = 0, m2 = 0;
  double e1, e2;
  int uacc;
  e1 = 1e5;
  e2 = 1e5;
  for (uacc = (int)ceil(minrep * inc); uacc <= floor(2 * minrep * inc);
       uacc++) {
    int mt;
    double et;
    mt = (int)floor(uacc / inc + 1e-5);
    et = uacc / inc - mt + mt * 0.001;
    if (et < e1) {
      e1 = et;
      m1 = mt;
    }
    mt = (int)ceil(uacc / inc - 1e-5);
    et = mt - uacc / inc + mt * 0.001;
    if (et < e2) {
      e2 = et;
      m2 = mt;
    }
  }
  if (m1 == m2) {
    *px1 = m1;
    *pxwidth = m1;
    *pp1 = 1.0;
  } else {
    *px1 = m1;
    *pxwidth = m1 + m2;
    e1 = fabs(m1 * inc - floor(0.5 + m1 * inc));
    e2 = fabs(m2 * inc - floor(0.5 + m2 * inc));
    *pp1 = e2 / (e1 + e2);
  }
}


x86 assembly (clang, -O0):
<wts_cell_calc_h>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
imul   $0x32,%eax,%eax
mov    %eax,-0x5c(%rbp)
mov    $0x2,%edi
movsd  0xe85(%rip),%xmm0
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movsd  0xe51(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe44(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x60(%rbp)
movsd  0xe2b(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1060 <floor@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
cmp    %ecx,%eax
jg     12f6 <wts_cell_calc_h+0x1b6>
cvtsi2sdl -0x4c(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  0xe1d(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
mov    %eax,-0x50(%rbp)
cvtsi2sdl -0x4c(%rbp),%xmm1
divsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x50(%rbp),%xmm0
subsd  %xmm0,%xmm1
cvtsi2sdl -0x50(%rbp),%xmm0
movsd  0xde9(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1270 <wts_cell_calc_h+0x130>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x34(%rbp)
cvtsi2sdl -0x4c(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  0xdae(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
mov    %eax,-0x50(%rbp)
cvtsi2sdl -0x50(%rbp),%xmm1
cvtsi2sdl -0x4c(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
subsd  %xmm0,%xmm1
cvtsi2sdl -0x50(%rbp),%xmm0
movsd  0xd76(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12e3 <wts_cell_calc_h+0x1a3>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    12e8 <wts_cell_calc_h+0x1a8>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11d7 <wts_cell_calc_h+0x97>
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    1329 <wts_cell_calc_h+0x1e9>
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movsd  0xd00(%rip),%xmm0
movsd  %xmm0,(%rax)
jmp    1435 <wts_cell_calc_h+0x2f5>
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xcb0(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
movsd  -0x80(%rbp),%xmm0
movsd  -0x78(%rbp),%xmm2
cvtsi2sd %eax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <fabs@plt>
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
cvtsi2sdl -0x38(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xc42(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
movsd  -0x70(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
cvtsi2sd %eax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <fabs@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
addsd  -0x48(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wts_cell_calc_h>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
movsd  %xmm0,0x10(%rsp)
mov    $0x2,%edi
movapd %xmm1,%xmm0
call   1050 <pow@plt>
imul   $0x32,%eax,%ebx
movsd  0xe8a(%rip),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x18(%rsp)
mulsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
mov    %rax,%rbx
movsd  0x18(%rsp),%xmm0
addsd  %xmm0,%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
call   1060 <floor@plt>
xor    %ebp,%ebp
cmp    %ebx,%eax
jl     12d8 <wts_cell_calc_h+0x198>
mov    %r14,0x30(%rsp)
xor    %r13d,%r13d
movsd  0xe2d(%rip),%xmm0
movapd %xmm0,%xmm1
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x28(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
addsd  0xdf9(%rip),%xmm0
call   1060 <floor@plt>
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm0
subsd  %xmm2,%xmm0
movsd  0xddf(%rip),%xmm1
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  0x20(%rsp),%xmm0
ucomisd %xmm2,%xmm0
cmova  %eax,%ebp
minsd  %xmm0,%xmm2
movsd  %xmm2,0x20(%rsp)
movapd %xmm3,%xmm0
addsd  0xdbc(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movapd %xmm1,%xmm0
subsd  0x8(%rsp),%xmm0
mulsd  0xd92(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0x28(%rsp),%xmm0
ucomisd %xmm1,%xmm0
cmova  %eax,%r13d
minsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0x1(%rbx),%r14d
movsd  0x18(%rsp),%xmm0
call   1060 <floor@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
cmp    %eax,%ebx
mov    %r14d,%ebx
jl     11f0 <wts_cell_calc_h+0xb0>
cmp    %r13d,%ebp
movsd  0x10(%rsp),%xmm0
jne    12ec <wts_cell_calc_h+0x1ac>
mov    0x30(%rsp),%r14
mov    %ebp,(%r12)
mov    %ebp,(%r15)
movsd  0xd49(%rip),%xmm0
jmp    138c <wts_cell_calc_h+0x24c>
mov    %ebp,(%r12)
lea    0x0(%r13,%rbp,1),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mov    %eax,(%r15)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
addsd  0xd13(%rip),%xmm0
call   1060 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <fabs@plt>
movsd  %xmm0,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %r13d,%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x28(%rsp)
movsd  0xcd2(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x28(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <fabs@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm0
mov    0x30(%rsp),%r14
movsd  %xmm0,(%r14)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @wts_cell_calc_h(double %0, i32* %1, i32* %2, double* %3, double %4) {
%6 = alloca double
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca i32
%17 = alloca i32
%18 = alloca double
store double %0, double* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store double* %3, double** %9
store double %4, double* %10
%19 = load double, double* %10
%20 = call i32 @pow(i32 2, double %19)
%21 = mul nsw i32 %20, 50
%22 = call i32 @pow(i32 2, double 7.500000e+00)
%23 = sdiv i32 %21, %22
%24 = sitofp i32 %23 to double
store double %24, double* %11
store i32 0, i32* %12
store i32 0, i32* %13
store double 1.000000e+05, double* %14
store double 1.000000e+05, double* %15
%25 = load double, double* %11
%26 = load double, double* %6
%27 = fmul double %25, %26
%28 = fptosi double %27 to i32
%29 = call i64 @ceil(i32 %28)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %16
br label %31
31: ; preds = %88, %5
%32 = load i32, i32* %16
%33 = load double, double* %11
%34 = fmul double 2.000000e+00, %33
%35 = load double, double* %6
%36 = fmul double %34, %35
%37 = call i32 @floor(double %36)
%38 = icmp sle i32 %32, %37
br i1 %38, label %39, label %91
39: ; preds = %31
%40 = load i32, i32* %16
%41 = sitofp i32 %40 to double
%42 = load double, double* %6
%43 = fdiv double %41, %42
%44 = fadd double %43, 1.000000e-05
%45 = call i32 @floor(double %44)
store i32 %45, i32* %17
%46 = load i32, i32* %16
%47 = sitofp i32 %46 to double
%48 = load double, double* %6
%49 = fdiv double %47, %48
%50 = load i32, i32* %17
%51 = sitofp i32 %50 to double
%52 = fsub double %49, %51
%53 = load i32, i32* %17
%54 = sitofp i32 %53 to double
%55 = call double @llvm.fmuladd.f64(double %54, double 1.000000e-03, double %52)
store double %55, double* %18
%56 = load double, double* %18
%57 = load double, double* %14
%58 = fcmp olt double %56, %57
br i1 %58, label %59, label %62
59: ; preds = %39
%60 = load double, double* %18
store double %60, double* %14
%61 = load i32, i32* %17
store i32 %61, i32* %12
br label %62
62: ; preds = %59, %39
%63 = load i32, i32* %16
%64 = sitofp i32 %63 to double
%65 = load double, double* %6
%66 = fdiv double %64, %65
%67 = fsub double %66, 1.000000e-05
%68 = fptosi double %67 to i32
%69 = call i64 @ceil(i32 %68)
%70 = trunc i64 %69 to i32
store i32 %70, i32* %17
%71 = load i32, i32* %17
%72 = sitofp i32 %71 to double
%73 = load i32, i32* %16
%74 = sitofp i32 %73 to double
%75 = load double, double* %6
%76 = fdiv double %74, %75
%77 = fsub double %72, %76
%78 = load i32, i32* %17
%79 = sitofp i32 %78 to double
%80 = call double @llvm.fmuladd.f64(double %79, double 1.000000e-03, double %77)
store double %80, double* %18
%81 = load double, double* %18
%82 = load double, double* %15
%83 = fcmp olt double %81, %82
br i1 %83, label %84, label %87
84: ; preds = %62
%85 = load double, double* %18
store double %85, double* %15
%86 = load i32, i32* %17
store i32 %86, i32* %13
br label %87
87: ; preds = %84, %62
br label %88
88: ; preds = %87
%89 = load i32, i32* %16
%90 = add nsw i32 %89, 1
store i32 %90, i32* %16
br label %31
91: ; preds = %31
%92 = load i32, i32* %12
%93 = load i32, i32* %13
%94 = icmp eq i32 %92, %93
br i1 %94, label %95, label %101
95: ; preds = %91
%96 = load i32, i32* %12
%97 = load i32*, i32** %7
store i32 %96, i32* %97
%98 = load i32, i32* %12
%99 = load i32*, i32** %8
store i32 %98, i32* %99
%100 = load double*, double** %9
store double 1.000000e+00, double* %100
br label %140
101: ; preds = %91
%102 = load i32, i32* %12
%103 = load i32*, i32** %7
store i32 %102, i32* %103
%104 = load i32, i32* %12
%105 = load i32, i32* %13
%106 = add nsw i32 %104, %105
%107 = load i32*, i32** %8
store i32 %106, i32* %107
%108 = load i32, i32* %12
%109 = sitofp i32 %108 to double
%110 = load double, double* %6
%111 = load i32, i32* %12
%112 = sitofp i32 %111 to double
%113 = load double, double* %6
%114 = call double @llvm.fmuladd.f64(double %112, double %113, double 5.000000e-01)
%115 = call i32 @floor(double %114)
%116 = sitofp i32 %115 to double
%117 = fneg double %116
%118 = call double @llvm.fmuladd.f64(double %109, double %110, double %117)
%119 = fptosi double %118 to i32
%120 = call double @fabs(i32 %119)
store double %120, double* %14
%121 = load i32, i32* %13
%122 = sitofp i32 %121 to double
%123 = load double, double* %6
%124 = load i32, i32* %13
%125 = sitofp i32 %124 to double
%126 = load double, double* %6
%127 = call double @llvm.fmuladd.f64(double %125, double %126, double 5.000000e-01)
%128 = call i32 @floor(double %127)
%129 = sitofp i32 %128 to double
%130 = fneg double %129
%131 = call double @llvm.fmuladd.f64(double %122, double %123, double %130)
%132 = fptosi double %131 to i32
%133 = call double @fabs(i32 %132)
store double %133, double* %15
%134 = load double, double* %15
%135 = load double, double* %14
%136 = load double, double* %15
%137 = fadd double %135, %136
%138 = fdiv double %134, %137
%139 = load double*, double** %9
store double %138, double* %139
br label %140
140: ; preds = %101, %95
ret void
}

LLVM IR (-O2):
define void @wts_cell_calc_h(double %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, double* nocapture writeonly %3, double %4) {
%6 = tail call i32 @pow(i32 2, double %4)
%7 = mul nsw i32 %6, 50
%8 = tail call i32 @pow(i32 2, double 7.500000e+00)
%9 = sdiv i32 %7, %8
%10 = sitofp i32 %9 to double
%11 = fmul double %10, %0
%12 = fptosi double %11 to i32
%13 = tail call i64 @ceil(i32 %12)
%14 = trunc i64 %13 to i32
%15 = fmul double %10, 2.000000e+00
%16 = fmul double %15, %0
%17 = tail call i32 @floor(double %16)
%18 = icmp slt i32 %17, %14
br i1 %18, label %50, label %19
19: ; preds = %5, %19
%20 = phi i32 [ %45, %19 ], [ %14, %5 ]
%21 = phi double [ %44, %19 ], [ 1.000000e+05, %5 ]
%22 = phi double [ %34, %19 ], [ 1.000000e+05, %5 ]
%23 = phi i32 [ %43, %19 ], [ 0, %5 ]
%24 = phi i32 [ %33, %19 ], [ 0, %5 ]
%25 = sitofp i32 %20 to double
%26 = fdiv double %25, %0
%27 = fadd double %26, 1.000000e-05
%28 = tail call i32 @floor(double %27)
%29 = sitofp i32 %28 to double
%30 = fsub double %26, %29
%31 = tail call double @llvm.fmuladd.f64(double %29, double 1.000000e-03, double %30)
%32 = fcmp olt double %31, %22
%33 = select i1 %32, i32 %28, i32 %24
%34 = select i1 %32, double %31, double %22
%35 = fadd double %26, -1.000000e-05
%36 = fptosi double %35 to i32
%37 = tail call i64 @ceil(i32 %36)
%38 = trunc i64 %37 to i32
%39 = sitofp i32 %38 to double
%40 = fsub double %39, %26
%41 = tail call double @llvm.fmuladd.f64(double %39, double 1.000000e-03, double %40)
%42 = fcmp olt double %41, %21
%43 = select i1 %42, i32 %38, i32 %23
%44 = select i1 %42, double %41, double %21
%45 = add nsw i32 %20, 1
%46 = tail call i32 @floor(double %16)
%47 = icmp slt i32 %20, %46
br i1 %47, label %19, label %48
48: ; preds = %19
%49 = icmp eq i32 %33, %43
br i1 %49, label %50, label %52
50: ; preds = %5, %48
%51 = phi i32 [ %33, %48 ], [ 0, %5 ]
store i32 %51, i32* %1
store i32 %51, i32* %2
br label %72
52: ; preds = %48
store i32 %33, i32* %1
%53 = add nsw i32 %43, %33
store i32 %53, i32* %2
%54 = sitofp i32 %33 to double
%55 = tail call double @llvm.fmuladd.f64(double %54, double %0, double 5.000000e-01)
%56 = tail call i32 @floor(double %55)
%57 = sitofp i32 %56 to double
%58 = fneg double %57
%59 = tail call double @llvm.fmuladd.f64(double %54, double %0, double %58)
%60 = fptosi double %59 to i32
%61 = tail call double @fabs(i32 %60)
%62 = sitofp i32 %43 to double
%63 = tail call double @llvm.fmuladd.f64(double %62, double %0, double 5.000000e-01)
%64 = tail call i32 @floor(double %63)
%65 = sitofp i32 %64 to double
%66 = fneg double %65
%67 = tail call double @llvm.fmuladd.f64(double %62, double %0, double %66)
%68 = fptosi double %67 to i32
%69 = tail call double @fabs(i32 %68)
%70 = fadd double %61, %69
%71 = fdiv double %69, %70
br label %72
72: ; preds = %52, %50
%73 = phi double [ %71, %52 ], [ 1.000000e+00, %50 ]
store double %73, double* %3
ret void
}