#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 exp(double);
double fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double sqrt(double);
int /*<<< orphan*/ stderr;
double KSpercent(double value, long n) {
  int i;
  double mult, temp, term, previous_term, percent;
  value /= sqrt((double)n);
  value *= 0.12 + sqrt((double)n) + 0.11 / sqrt((double)n);
  mult = 2.0;
  percent = 0.0;
  temp = -2.0 * value * value;
  previous_term = 0.0;
  for (i = 1; i < 150; i++) {
    term = mult * exp(temp * i * i);
    percent += term;
    if (fabs(term) < 0.005 * fabs(previous_term) ||
        fabs(term) < 0.0000001 * percent)
      return 1.0 - percent;
    mult = -mult;
    previous_term = term;
  }
  fprintf(stderr, "WARNING: KSpercent failed to converge\n");
  return (percent < 0.0 ? 0.0 : percent);
}


x86 assembly (clang, -O0):
<KSpercent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xea5(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  0xe79(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe57(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe3a(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x96,-0x1c(%rbp)
jge    12e4 <KSpercent+0x1b4>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm1
movaps 0xdfd(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm2
movaps 0xded(%rip),%xmm0
pand   %xmm0,%xmm2
movsd  0xdc1(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     1294 <KSpercent+0x164>
movsd  -0x38(%rbp),%xmm1
movaps 0xdc7(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xda3(%rip),%xmm0
mulsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12ab <KSpercent+0x17b>
movsd  0xd94(%rip),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1328 <KSpercent+0x1f8>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e4 <KSpercent+0xb4>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
call   1030 <fprintf@plt>
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1314 <KSpercent+0x1e4>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    131e <KSpercent+0x1ee>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KSpercent>:
push   %rbx
sub    $0x30,%rsp
movapd %xmm0,%xmm2
cvtsi2sd %rdi,%xmm4
sqrtsd %xmm4,%xmm3
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm4
movapd %xmm3,%xmm0
movsd  %xmm2,0x20(%rsp)
movsd  %xmm3,0x10(%rsp)
movsd  %xmm4,0x8(%rsp)
jae    1181 <KSpercent+0x51>
movapd %xmm4,%xmm0
call   1050 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  0x8(%rsp),%xmm4
movsd  0x10(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
ucomisd %xmm1,%xmm4
movapd %xmm3,%xmm5
jae    11b4 <KSpercent+0x84>
movsd  %xmm0,(%rsp)
movapd %xmm4,%xmm0
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm4
movsd  0x10(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
movapd %xmm0,%xmm5
movsd  (%rsp),%xmm0
addsd  0xe44(%rip),%xmm5
divsd  %xmm0,%xmm2
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
ucomisd %xmm1,%xmm4
jae    11f8 <KSpercent+0xc8>
movapd %xmm4,%xmm0
movsd  %xmm2,0x20(%rsp)
movsd  %xmm5,0x10(%rsp)
call   1050 <sqrt@plt>
movsd  0x10(%rsp),%xmm5
movsd  0x20(%rsp),%xmm2
movapd %xmm0,%xmm3
movsd  0xe08(%rip),%xmm0
divsd  %xmm3,%xmm0
addsd  %xmm0,%xmm5
mulsd  %xmm5,%xmm2
movsd  0xdfc(%rip),%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xdee(%rip),%xmm4
mov    $0x1,%ebx
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd %xmm4,0x20(%rsp)
movapd %xmm0,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
call   1040 <exp@plt>
movapd 0x20(%rsp),%xmm4
mulsd  %xmm4,%xmm0
movsd  (%rsp),%xmm3
addsd  %xmm0,%xmm3
movapd %xmm0,%xmm1
movapd 0xdbb(%rip),%xmm2
andpd  %xmm2,%xmm1
movapd 0x10(%rsp),%xmm5
andpd  %xmm2,%xmm5
mulsd  0xd85(%rip),%xmm5
ucomisd %xmm1,%xmm5
movapd %xmm3,%xmm2
mulsd  0xd7d(%rip),%xmm2
ja     12ef <KSpercent+0x1bf>
ucomisd %xmm1,%xmm2
ja     12ef <KSpercent+0x1bf>
movsd  %xmm3,(%rsp)
xorpd  0xd90(%rip),%xmm4
add    $0x1,%ebx
cmp    $0x96,%ebx
jne    1240 <KSpercent+0x110>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
call   1030 <fprintf@plt>
xorpd  %xmm0,%xmm0
maxsd  (%rsp),%xmm0
jmp    12fb <KSpercent+0x1cb>
movsd  0xd39(%rip),%xmm0
subsd  %xmm3,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"WARNING: KSpercent failed to converge\0A\00"
define double @KSpercent(double %0, i64 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i64
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %4
store i64 %1, i64* %5
%12 = load i64, i64* %5
%13 = sitofp i64 %12 to double
%14 = call double @sqrt(double %13)
%15 = load double, double* %4
%16 = fdiv double %15, %14
store double %16, double* %4
%17 = load i64, i64* %5
%18 = sitofp i64 %17 to double
%19 = call double @sqrt(double %18)
%20 = fadd double 1.200000e-01, %19
%21 = load i64, i64* %5
%22 = sitofp i64 %21 to double
%23 = call double @sqrt(double %22)
%24 = fdiv double 1.100000e-01, %23
%25 = fadd double %20, %24
%26 = load double, double* %4
%27 = fmul double %26, %25
store double %27, double* %4
store double 2.000000e+00, double* %7
store double 0.000000e+00, double* %11
%28 = load double, double* %4
%29 = fmul double -2.000000e+00, %28
%30 = load double, double* %4
%31 = fmul double %29, %30
store double %31, double* %8
store double 0.000000e+00, double* %10
store i32 1, i32* %6
br label %32
32: ; preds = %68, %2
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 150
br i1 %34, label %35, label %71
35: ; preds = %32
%36 = load double, double* %7
%37 = load double, double* %8
%38 = load i32, i32* %6
%39 = sitofp i32 %38 to double
%40 = fmul double %37, %39
%41 = load i32, i32* %6
%42 = sitofp i32 %41 to double
%43 = fmul double %40, %42
%44 = call double @exp(double %43)
%45 = fmul double %36, %44
store double %45, double* %9
%46 = load double, double* %9
%47 = load double, double* %11
%48 = fadd double %47, %46
store double %48, double* %11
%49 = load double, double* %9
%50 = call double @llvm.fabs.f64(double %49)
%51 = load double, double* %10
%52 = call double @llvm.fabs.f64(double %51)
%53 = fmul double 5.000000e-03, %52
%54 = fcmp olt double %50, %53
br i1 %54, label %61, label %55
55: ; preds = %35
%56 = load double, double* %9
%57 = call double @llvm.fabs.f64(double %56)
%58 = load double, double* %11
%59 = fmul double 0x3E7AD7F29ABCAF48, %58
%60 = fcmp olt double %57, %59
br i1 %60, label %61, label %64
61: ; preds = %55, %35
%62 = load double, double* %11
%63 = fsub double 1.000000e+00, %62
store double %63, double* %3
br label %81
64: ; preds = %55
%65 = load double, double* %7
%66 = fneg double %65
store double %66, double* %7
%67 = load double, double* %9
store double %67, double* %10
br label %68
68: ; preds = %64
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %32
71: ; preds = %32
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%74 = load double, double* %11
%75 = fcmp olt double %74, 0.000000e+00
br i1 %75, label %76, label %77
76: ; preds = %71
br label %79
77: ; preds = %71
%78 = load double, double* %11
br label %79
79: ; preds = %77, %76
%80 = phi double [ 0.000000e+00, %76 ], [ %78, %77 ]
store double %80, double* %3
br label %81
81: ; preds = %79, %61
%82 = load double, double* %3
ret double %82
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"WARNING: KSpercent failed to converge\0A\00"
define double @KSpercent(double %0, i64 %1) {
%3 = sitofp i64 %1 to double
%4 = tail call double @sqrt(double %3)
%5 = fdiv double %0, %4
%6 = tail call double @sqrt(double %3)
%7 = fadd double %6, 1.200000e-01
%8 = tail call double @sqrt(double %3)
%9 = fdiv double 1.100000e-01, %8
%10 = fadd double %7, %9
%11 = fmul double %5, %10
%12 = fmul double %11, -2.000000e+00
%13 = fmul double %11, %12
br label %14
14: ; preds = %2, %34
%15 = phi double [ 0.000000e+00, %2 ], [ %24, %34 ]
%16 = phi double [ 0.000000e+00, %2 ], [ %23, %34 ]
%17 = phi i32 [ 1, %2 ], [ %36, %34 ]
%18 = phi double [ 2.000000e+00, %2 ], [ %35, %34 ]
%19 = sitofp i32 %17 to double
%20 = fmul double %13, %19
%21 = fmul double %20, %19
%22 = tail call double @exp(double %21)
%23 = fmul double %18, %22
%24 = fadd double %15, %23
%25 = tail call double @llvm.fabs.f64(double %23)
%26 = tail call double @llvm.fabs.f64(double %16)
%27 = fmul double %26, 5.000000e-03
%28 = fcmp olt double %25, %27
%29 = fmul double %24, 0x3E7AD7F29ABCAF48
%30 = fcmp olt double %25, %29
%31 = select i1 %28, i1 true, i1 %30
br i1 %31, label %32, label %34
32: ; preds = %14
%33 = fsub double 1.000000e+00, %24
br label %43
34: ; preds = %14
%35 = fneg double %18
%36 = add nuw nsw i32 %17, 1
%37 = icmp eq i32 %36, 150
br i1 %37, label %38, label %14
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%41 = fcmp olt double %24, 0.000000e+00
%42 = select i1 %41, double 0.000000e+00, double %24
br label %43
43: ; preds = %38, %32
%44 = phi double [ %33, %32 ], [ %42, %38 ]
ret double %44
}