#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 pnorm(double);
double sqrt(double);
int mest1(int n, double xbar, double pv, double g, double *xl, double *xu) {
  double w;
  if (n < 1 || g <= 0.0 || g >= 1.0)
    return 999;
  w = pnorm((1.0 + g) * 0.5) * sqrt(pv / (double)n);
  *xl = xbar - w;
  *xu = xbar + w;
  return 0;
}


x86 assembly (clang, -O0):
<mest1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     1171 <mest1+0x51>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jae    1171 <mest1+0x51>
movsd  -0x20(%rbp),%xmm0
movsd  0xe99(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     117d <mest1+0x5d>
movl   $0x3e7,-0x4(%rbp)
jmp    11ef <mest1+0xcf>
movsd  0xe7b(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe76(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <pnorm@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mest1>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
ucomisd 0xed0(%rip),%xmm2
mov    $0x3e7,%eax
jae    11db <mest1+0xbb>
mov    %edi,%ebp
test   %edi,%edi
jle    11db <mest1+0xbb>
xorpd  %xmm3,%xmm3
ucomisd %xmm2,%xmm3
jae    11db <mest1+0xbb>
mov    %rdx,%r14
mov    %rsi,%rbx
movsd  %xmm0,0x8(%rsp)
addsd  0xe99(%rip),%xmm2
mulsd  0xe99(%rip),%xmm2
movapd %xmm2,%xmm0
movsd  %xmm1,(%rsp)
call   1030 <pnorm@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movapd %xmm0,%xmm2
movsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
ucomisd 0xe6d(%rip),%xmm0
jb     11ab <mest1+0x8b>
sqrtsd %xmm0,%xmm0
jmp    11ba <mest1+0x9a>
movsd  %xmm2,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,(%rbx)
addsd  %xmm1,%xmm2
movsd  %xmm2,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mest1(i32 %0, double %1, double %2, double %3, double* %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double*
%13 = alloca double*
%14 = alloca double
store i32 %0, i32* %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double* %4, double** %12
store double* %5, double** %13
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 1
br i1 %16, label %23, label %17
17: ; preds = %6
%18 = load double, double* %11
%19 = fcmp ole double %18, 0.000000e+00
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load double, double* %11
%22 = fcmp oge double %21, 1.000000e+00
br i1 %22, label %23, label %24
23: ; preds = %20, %17, %6
store i32 999, i32* %7
br label %43
24: ; preds = %20
%25 = load double, double* %11
%26 = fadd double 1.000000e+00, %25
%27 = fmul double %26, 5.000000e-01
%28 = call double @pnorm(double %27)
%29 = load double, double* %10
%30 = load i32, i32* %8
%31 = sitofp i32 %30 to double
%32 = fdiv double %29, %31
%33 = call double @sqrt(double %32)
%34 = fmul double %28, %33
store double %34, double* %14
%35 = load double, double* %9
%36 = load double, double* %14
%37 = fsub double %35, %36
%38 = load double*, double** %12
store double %37, double* %38
%39 = load double, double* %9
%40 = load double, double* %14
%41 = fadd double %39, %40
%42 = load double*, double** %13
store double %41, double* %42
store i32 0, i32* %7
br label %43
43: ; preds = %24, %23
%44 = load i32, i32* %7
ret i32 %44
}

LLVM IR (-O2):
define i32 @mest1(i32 %0, double %1, double %2, double %3, double* nocapture writeonly %4, double* nocapture writeonly %5) {
%7 = icmp slt i32 %0, 1
%8 = fcmp ole double %3, 0.000000e+00
%9 = or i1 %7, %8
%10 = fcmp oge double %3, 1.000000e+00
%11 = or i1 %10, %9
br i1 %11, label %22, label %12
12: ; preds = %6
%13 = fadd double %3, 1.000000e+00
%14 = fmul double %13, 5.000000e-01
%15 = tail call double @pnorm(double %14)
%16 = sitofp i32 %0 to double
%17 = fdiv double %2, %16
%18 = tail call double @sqrt(double %17)
%19 = fmul double %15, %18
%20 = fsub double %1, %19
store double %20, double* %4
%21 = fadd double %19, %1
store double %21, double* %5
br label %22
22: ; preds = %6, %12
%23 = phi i32 [ 0, %12 ], [ 999, %6 ]
ret i32 %23
}