#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);
int /*<<< orphan*/ fesetround(int);
double log(double);
double sqrt(double);
double IBBasicNthRoot(double x, int n, int round, double epsilon) {
  double y;
  if (x == 1.0) {
    return (1.0);
  } else if (x == 0.0) {
    return (0.0);
  } else if (n == 2) {
    if (round == 1) {
      fesetround(3);
    } else {
      fesetround(2);
    }
    return (sqrt(x));
  } else {
    fesetround(0);
    if (x < 0.0) {
      y = -(exp((1.0 / n) * log(-(x))));
    } else {
      y = exp((1.0 / n) * log(x));
    }
    if (round == 1) {
      fesetround(3);
      return (y - epsilon);
    } else {
      fesetround(2);
      return (y + epsilon);
    }
  }
}


x86 assembly (clang, -O0):
<IBBasicNthRoot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe9b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1187 <IBBasicNthRoot+0x47>
jp     1187 <IBBasicNthRoot+0x47>
movsd  0xe83(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e2 <IBBasicNthRoot+0x1a2>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ac <IBBasicNthRoot+0x6c>
jp     11ac <IBBasicNthRoot+0x6c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e2 <IBBasicNthRoot+0x1a2>
cmpl   $0x2,-0x14(%rbp)
jne    11ed <IBBasicNthRoot+0xad>
cmpl   $0x1,-0x18(%rbp)
jne    11cf <IBBasicNthRoot+0x8f>
mov    $0x3,%edi
call   1030 <fesetround@plt>
jmp    11d9 <IBBasicNthRoot+0x99>
mov    $0x2,%edi
call   1030 <fesetround@plt>
movsd  -0x10(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    12e2 <IBBasicNthRoot+0x1a2>
xor    %edi,%edi
call   1030 <fesetround@plt>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    126b <IBBasicNthRoot+0x12b>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xdf1(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <exp@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12a1 <IBBasicNthRoot+0x161>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xd88(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    12c9 <IBBasicNthRoot+0x189>
mov    $0x3,%edi
call   1030 <fesetround@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e2 <IBBasicNthRoot+0x1a2>
mov    $0x2,%edi
call   1030 <fesetround@plt>
movsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IBBasicNthRoot>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movsd  0xeb2(%rip),%xmm2
ucomisd %xmm2,%xmm0
jne    1156 <IBBasicNthRoot+0x16>
jnp    1162 <IBBasicNthRoot+0x22>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    116d <IBBasicNthRoot+0x2d>
jp     116d <IBBasicNthRoot+0x2d>
movapd %xmm2,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
mov    %esi,%ebx
mov    %edi,%ebp
movapd %xmm0,(%rsp)
cmp    $0x2,%edi
jne    11a4 <IBBasicNthRoot+0x64>
xor    %edi,%edi
cmp    $0x1,%ebx
sete   %dil
or     $0x2,%edi
call   1030 <fesetround@plt>
xorpd  %xmm1,%xmm1
movapd (%rsp),%xmm0
ucomisd %xmm1,%xmm0
jb     11fb <IBBasicNthRoot+0xbb>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
jmp    1162 <IBBasicNthRoot+0x22>
movsd  %xmm1,0x20(%rsp)
xor    %edi,%edi
call   1030 <fesetround@plt>
xorpd  %xmm1,%xmm1
movapd (%rsp),%xmm0
ucomisd %xmm0,%xmm1
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  0xe33(%rip),%xmm2
divsd  %xmm1,%xmm2
movsd  %xmm2,0x18(%rsp)
jbe    1206 <IBBasicNthRoot+0xc6>
xorpd  0xe2f(%rip),%xmm0
call   1050 <log@plt>
mulsd  0x18(%rsp),%xmm0
call   1040 <exp@plt>
xorpd  0xe17(%rip),%xmm0
jmp    1216 <IBBasicNthRoot+0xd6>
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <sqrt@plt>
call   1050 <log@plt>
mulsd  0x18(%rsp),%xmm0
call   1040 <exp@plt>
movapd %xmm0,(%rsp)
cmp    $0x1,%ebx
jne    123a <IBBasicNthRoot+0xfa>
mov    $0x3,%edi
call   1030 <fesetround@plt>
movapd (%rsp),%xmm2
subsd  0x20(%rsp),%xmm2
jmp    1162 <IBBasicNthRoot+0x22>
mov    $0x2,%edi
call   1030 <fesetround@plt>
movapd (%rsp),%xmm2
addsd  0x20(%rsp),%xmm2
jmp    1162 <IBBasicNthRoot+0x22>

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

LLVM IR (-O2):
define double @IBBasicNthRoot(double %0, i32 %1, i32 %2, double %3) {
%5 = fcmp oeq double %0, 1.000000e+00
br i1 %5, label %39, label %6
6: ; preds = %4
%7 = fcmp oeq double %0, 0.000000e+00
br i1 %7, label %39, label %8
8: ; preds = %6
%9 = icmp eq i32 %1, 2
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = icmp eq i32 %2, 1
%12 = select i1 %11, i32 3, i32 2
%13 = tail call i32 @fesetround(i32 %12)
%14 = tail call double @sqrt(double %0)
br label %39
15: ; preds = %8
%16 = tail call i32 @fesetround(i32 0)
%17 = fcmp olt double %0, 0.000000e+00
%18 = sitofp i32 %1 to double
%19 = fdiv double 1.000000e+00, %18
br i1 %17, label %20, label %26
20: ; preds = %15
%21 = fneg double %0
%22 = tail call double @log(double %21)
%23 = fmul double %19, %22
%24 = tail call double @exp(double %23)
%25 = fneg double %24
br label %30
26: ; preds = %15
%27 = tail call double @log(double %0)
%28 = fmul double %19, %27
%29 = tail call double @exp(double %28)
br label %30
30: ; preds = %26, %20
%31 = phi double [ %25, %20 ], [ %29, %26 ]
%32 = icmp eq i32 %2, 1
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = tail call i32 @fesetround(i32 3)
%35 = fsub double %31, %3
br label %39
36: ; preds = %30
%37 = tail call i32 @fesetround(i32 2)
%38 = fadd double %31, %3
br label %39
39: ; preds = %6, %4, %36, %33, %10
%40 = phi double [ %14, %10 ], [ %35, %33 ], [ %38, %36 ], [ 1.000000e+00, %4 ], [ 0.000000e+00, %6 ]
ret double %40
}