#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);
double log(double);
double pnorm(double);
double sqrt(double);
int rest(int n, double r0, double g, double *xl, double *xu) {
  double qn, w, w1, w2, w3;
  if (n < 4 || fabs(r0) >= 1.0 || g <= 0.0 || g >= 1.0)
    return 999;
  w = log((1.0 + r0) / (1.0 - r0)) * 0.5;
  w1 = pnorm((1.0 + g) * 0.5) / sqrt((double)(n - 3));
  w2 = exp(2.0 * (w - w1));
  w3 = exp(2.0 * (w + w1));
  *xl = (w2 - 1.0) / (w2 + 1.0);
  *xu = (w3 - 1.0) / (w3 + 1.0);
  return 0;
}


x86 assembly (clang, -O0):
<rest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11ae <rest+0x6e>
movsd  -0x10(%rbp),%xmm0
movaps 0xead(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe81(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    11ae <rest+0x6e>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jae    11ae <rest+0x6e>
movsd  -0x18(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ba <rest+0x7a>
movl   $0x3e7,-0x4(%rbp)
jmp    12cc <rest+0x18c>
movsd  0xe3e(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe31(%rip),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <log@plt>
movsd  0xe2b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe0a(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe0d(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <pnorm@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x3,%eax
cvtsi2sd %eax,%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movsd  0xdc5(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm1
addsd  -0x40(%rbp),%xmm1
movsd  0xda5(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xd82(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xd76(%rip),%xmm1
addsd  -0x48(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
movsd  0xd58(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xd4c(%rip),%xmm1
addsd  -0x50(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    $0x3e7,%eax
cmp    $0x4,%edi
jl     1280 <rest+0x140>
ucomisd 0xeb2(%rip),%xmm1
jae    1280 <rest+0x140>
movapd 0xe94(%rip),%xmm2
andpd  %xmm0,%xmm2
ucomisd 0xe98(%rip),%xmm2
jae    1280 <rest+0x140>
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
jae    1280 <rest+0x140>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
movsd  0xe74(%rip),%xmm3
movapd %xmm3,%xmm2
subsd  %xmm0,%xmm2
addsd  %xmm3,%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1050 <log@plt>
movsd  0xe59(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xe39(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <pnorm@plt>
movsd  %xmm0,0x8(%rsp)
add    $0xfffffffd,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
ucomisd 0xe30(%rip),%xmm0
jb     1200 <rest+0xc0>
sqrtsd %xmm0,%xmm0
jmp    1205 <rest+0xc5>
call   1060 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
subsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm0
call   1030 <exp@plt>
movsd  0xdd5(%rip),%xmm1
movsd  0x18(%rsp),%xmm4
movapd %xmm4,%xmm2
addsd  %xmm1,%xmm2
movsd  0xdaf(%rip),%xmm3
addsd  %xmm3,%xmm4
divsd  %xmm4,%xmm2
movsd  %xmm2,(%rbx)
addsd  %xmm0,%xmm1
addsd  %xmm3,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rest(i32 %0, double %1, double %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
store i32 %0, i32* %7
store double %1, double* %8
store double %2, double* %9
store double* %3, double** %10
store double* %4, double** %11
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 4
br i1 %18, label %29, label %19
19: ; preds = %5
%20 = load double, double* %8
%21 = call double @llvm.fabs.f64(double %20)
%22 = fcmp oge double %21, 1.000000e+00
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = load double, double* %9
%25 = fcmp ole double %24, 0.000000e+00
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load double, double* %9
%28 = fcmp oge double %27, 1.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %26, %23, %19, %5
store i32 999, i32* %6
br label %69
30: ; preds = %26
%31 = load double, double* %8
%32 = fadd double 1.000000e+00, %31
%33 = load double, double* %8
%34 = fsub double 1.000000e+00, %33
%35 = fdiv double %32, %34
%36 = call double @log(double %35)
%37 = fmul double %36, 5.000000e-01
store double %37, double* %13
%38 = load double, double* %9
%39 = fadd double 1.000000e+00, %38
%40 = fmul double %39, 5.000000e-01
%41 = call double @pnorm(double %40)
%42 = load i32, i32* %7
%43 = sub nsw i32 %42, 3
%44 = sitofp i32 %43 to double
%45 = call double @sqrt(double %44)
%46 = fdiv double %41, %45
store double %46, double* %14
%47 = load double, double* %13
%48 = load double, double* %14
%49 = fsub double %47, %48
%50 = fmul double 2.000000e+00, %49
%51 = call double @exp(double %50)
store double %51, double* %15
%52 = load double, double* %13
%53 = load double, double* %14
%54 = fadd double %52, %53
%55 = fmul double 2.000000e+00, %54
%56 = call double @exp(double %55)
store double %56, double* %16
%57 = load double, double* %15
%58 = fsub double %57, 1.000000e+00
%59 = load double, double* %15
%60 = fadd double %59, 1.000000e+00
%61 = fdiv double %58, %60
%62 = load double*, double** %10
store double %61, double* %62
%63 = load double, double* %16
%64 = fsub double %63, 1.000000e+00
%65 = load double, double* %16
%66 = fadd double %65, 1.000000e+00
%67 = fdiv double %64, %66
%68 = load double*, double** %11
store double %67, double* %68
store i32 0, i32* %6
br label %69
69: ; preds = %30, %29
%70 = load i32, i32* %6
ret i32 %70
}

LLVM IR (-O2):
define i32 @rest(i32 %0, double %1, double %2, double* nocapture writeonly %3, double* nocapture writeonly %4) {
%6 = icmp slt i32 %0, 4
br i1 %6, label %39, label %7
7: ; preds = %5
%8 = tail call double @llvm.fabs.f64(double %1)
%9 = fcmp oge double %8, 1.000000e+00
%10 = fcmp ole double %2, 0.000000e+00
%11 = or i1 %9, %10
%12 = fcmp oge double %2, 1.000000e+00
%13 = or i1 %12, %11
br i1 %13, label %39, label %14
14: ; preds = %7
%15 = fadd double %1, 1.000000e+00
%16 = fsub double 1.000000e+00, %1
%17 = fdiv double %15, %16
%18 = tail call double @log(double %17)
%19 = fmul double %18, 5.000000e-01
%20 = fadd double %2, 1.000000e+00
%21 = fmul double %20, 5.000000e-01
%22 = tail call double @pnorm(double %21)
%23 = add nsw i32 %0, -3
%24 = sitofp i32 %23 to double
%25 = tail call double @sqrt(double %24)
%26 = fdiv double %22, %25
%27 = fsub double %19, %26
%28 = fmul double %27, 2.000000e+00
%29 = tail call double @exp(double %28)
%30 = fadd double %19, %26
%31 = fmul double %30, 2.000000e+00
%32 = tail call double @exp(double %31)
%33 = fadd double %29, -1.000000e+00
%34 = fadd double %29, 1.000000e+00
%35 = fdiv double %33, %34
store double %35, double* %3
%36 = fadd double %32, -1.000000e+00
%37 = fadd double %32, 1.000000e+00
%38 = fdiv double %36, %37
store double %38, double* %4
br label %39
39: ; preds = %5, %7, %14
%40 = phi i32 [ 0, %14 ], [ 999, %7 ], [ 999, %5 ]
ret i32 %40
}