#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 */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ assert(int);
double pow1pm1(double const, int const);
int /*<<< orphan*/ puts(char *);
double CorrectPval(const double p, const int n, const int method) {
  double res;
  assert(p >= 0. && p <= 1.);
  assert(n > 0);
  assert(method == 0 || method == 1);
  switch (method) {
  case 0:
    res = n * p;
    break;
  case 1:
    res = -pow1pm1(-p, n);
    break;
  default:
    puts("Unknown method in CorrectPval");
    abort();
  }
  res = (res <= 1.) ? res : 1.;
  assert(res >= 0. && res <= 1.);
  return res;
}


x86 assembly (clang, -O0):
<CorrectPval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x19(%rbp)
jb     117d <CorrectPval+0x3d>
movsd  0xe8e(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
setae  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x1,%al
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x1a(%rbp)
je     11b4 <CorrectPval+0x74>
cmpl   $0x1,-0x10(%rbp)
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
movzbl %al,%edi
and    $0x1,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     11e6 <CorrectPval+0xa6>
jmp    11d5 <CorrectPval+0x95>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
je     11fa <CorrectPval+0xba>
jmp    123f <CorrectPval+0xff>
cvtsi2sdl -0xc(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1252 <CorrectPval+0x112>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0xc(%rbp),%edi
call   1060 <pow1pm1@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1252 <CorrectPval+0x112>
lea    0xdc2(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1030 <abort@plt>
movsd  0xda6(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1274 <CorrectPval+0x134>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1286 <CorrectPval+0x146>
movsd  0xd84(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1286 <CorrectPval+0x146>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
jb     12ba <CorrectPval+0x17a>
movsd  0xd51(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
setae  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CorrectPval>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
movsd  0xea7(%rip),%xmm1
movapd %xmm0,(%rsp)
ucomisd %xmm0,%xmm1
mov    %esi,%ebp
mov    %edi,%ebx
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
xor    %edi,%edi
test   %ebx,%ebx
setg   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmp    $0x2,%ebp
setb   %dil
call   1050 <assert@plt>
cmp    $0x1,%ebp
je     11a9 <CorrectPval+0x69>
movapd (%rsp),%xmm1
test   %ebp,%ebp
jne    11f0 <CorrectPval+0xb0>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  %xmm1,%xmm0
jmp    11c5 <CorrectPval+0x85>
movapd (%rsp),%xmm0
xorpd  0xe5a(%rip),%xmm0
mov    %ebx,%edi
call   1060 <pow1pm1@plt>
xorpd  0xe4b(%rip),%xmm0
minsd  0xe33(%rip),%xmm0
movapd %xmm0,(%rsp)
xorpd  %xmm1,%xmm1
xor    %edi,%edi
ucomisd %xmm1,%xmm0
setae  %dil
call   1050 <assert@plt>
movaps (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Unknown method in CorrectPval\00"
define double @CorrectPval(double %0, i32 %1, i32 %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store double %0, double* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load double, double* %4
%9 = fcmp oge double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load double, double* %4
%12 = fcmp ole double %11, 1.000000e+00
br label %13
13: ; preds = %10, %3
%14 = phi i1 [ false, %3 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %13
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 1
br label %26
26: ; preds = %23, %13
%27 = phi i1 [ true, %13 ], [ %25, %23 ]
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %6
switch i32 %30, label %42 [
i32 0, label %31
i32 1, label %36
]
31: ; preds = %26
%32 = load i32, i32* %5
%33 = sitofp i32 %32 to double
%34 = load double, double* %4
%35 = fmul double %33, %34
store double %35, double* %7
br label %45
36: ; preds = %26
%37 = load double, double* %4
%38 = fneg double %37
%39 = load i32, i32* %5
%40 = call double @pow1pm1(double %38, i32 %39)
%41 = fneg double %40
store double %41, double* %7
br label %45
42: ; preds = %26
%43 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%44 = call i32 (...) @abort()
unreachable
45: ; preds = %36, %31
%46 = load double, double* %7
%47 = fcmp ole double %46, 1.000000e+00
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = load double, double* %7
br label %51
50: ; preds = %45
br label %51
51: ; preds = %50, %48
%52 = phi double [ %49, %48 ], [ 1.000000e+00, %50 ]
store double %52, double* %7
%53 = load double, double* %7
%54 = fcmp oge double %53, 0.000000e+00
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load double, double* %7
%57 = fcmp ole double %56, 1.000000e+00
br label %58
58: ; preds = %55, %51
%59 = phi i1 [ false, %51 ], [ %57, %55 ]
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = load double, double* %7
ret double %62
}

LLVM IR (-O2):
@.str = [30 x i8] c"Unknown method in CorrectPval\00"
define double @CorrectPval(double %0, i32 %1, i32 %2) {
%4 = fcmp oge double %0, 0.000000e+00
%5 = fcmp ole double %0, 1.000000e+00
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp sgt i32 %1, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp ult i32 %2, 2
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
switch i32 %2, label %22 [
i32 0, label %15
i32 1, label %18
]
15: ; preds = %3
%16 = sitofp i32 %1 to double
%17 = fmul double %16, %0
br label %25
18: ; preds = %3
%19 = fneg double %0
%20 = tail call double @pow1pm1(double %19, i32 %1)
%21 = fneg double %20
br label %25
22: ; preds = %3
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 (...) @abort()
unreachable
25: ; preds = %18, %15
%26 = phi double [ %21, %18 ], [ %17, %15 ]
%27 = fcmp ole double %26, 1.000000e+00
%28 = select i1 %27, double %26, double 1.000000e+00
%29 = fcmp oge double %28, 0.000000e+00
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
ret double %28
}