#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 fabs(double);
double pow(double, int);
double root(int pwr, double num) {
  double left = 1;
  double right = num;
  double ans = num;
  while (fabs(pow(ans, pwr) - num) > 0.001) {
    if (pow(ans, pwr) > num) {
      right = ans;
    } else {
      left = ans;
    }
    ans = (left + right) / 2;
  }
  return ans;
}


x86 assembly (clang, -O0):
<root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  0xed8(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x4(%rbp),%edi
call   1030 <pow@plt>
subsd  -0x10(%rbp),%xmm0
movaps 0xec6(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xea2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c1 <root+0xb1>
movsd  -0x28(%rbp),%xmm0
mov    -0x4(%rbp),%edi
call   1030 <pow@plt>
ucomisd -0x10(%rbp),%xmm0
jbe    1197 <root+0x87>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11a1 <root+0x91>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe5d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1141 <root+0x31>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<root>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm0,(%rsp)
mov    %edi,%ebx
call   1030 <pow@plt>
movsd  (%rsp),%xmm1
subsd  %xmm1,%xmm0
andpd  0xece(%rip),%xmm0
ucomisd 0xed6(%rip),%xmm0
jbe    11ff <root+0xef>
movsd  0xed0(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movapd %xmm1,%xmm2
movapd %xmm1,%xmm0
jmp    11c8 <root+0xb8>
nopw   0x0(%rax,%rax,1)
movsd  %xmm3,0x8(%rsp)
movsd  (%rsp),%xmm1
cmpltsd %xmm0,%xmm1
movapd 0x20(%rsp),%xmm0
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
addsd  %xmm3,%xmm0
mulsd  0xe8c(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
mov    %ebx,%edi
call   1030 <pow@plt>
movapd 0x10(%rsp),%xmm2
movsd  (%rsp),%xmm1
subsd  %xmm1,%xmm0
andpd  0xe48(%rip),%xmm0
ucomisd 0xe50(%rip),%xmm0
movsd  0x8(%rsp),%xmm0
jbe    1203 <root+0xf3>
movsd  %xmm0,0x8(%rsp)
movapd %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
mov    %ebx,%edi
call   1030 <pow@plt>
movapd 0x10(%rsp),%xmm2
ucomisd (%rsp),%xmm0
movapd %xmm2,%xmm3
ja     1160 <root+0x50>
movsd  0x8(%rsp),%xmm3
jmp    1160 <root+0x50>
movapd %xmm1,%xmm2
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @root(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 %0, i32* %3
store double %1, double* %4
store double 1.000000e+00, double* %5
%8 = load double, double* %4
store double %8, double* %6
%9 = load double, double* %4
store double %9, double* %7
br label %10
10: ; preds = %28, %2
%11 = load double, double* %7
%12 = load i32, i32* %3
%13 = call double @pow(double %11, i32 %12)
%14 = load double, double* %4
%15 = fsub double %13, %14
%16 = call double @llvm.fabs.f64(double %15)
%17 = fcmp ogt double %16, 1.000000e-03
br i1 %17, label %18, label %33
18: ; preds = %10
%19 = load double, double* %7
%20 = load i32, i32* %3
%21 = call double @pow(double %19, i32 %20)
%22 = load double, double* %4
%23 = fcmp ogt double %21, %22
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load double, double* %7
store double %25, double* %6
br label %28
26: ; preds = %18
%27 = load double, double* %7
store double %27, double* %5
br label %28
28: ; preds = %26, %24
%29 = load double, double* %5
%30 = load double, double* %6
%31 = fadd double %29, %30
%32 = fdiv double %31, 2.000000e+00
store double %32, double* %7
br label %10
33: ; preds = %10
%34 = load double, double* %7
ret double %34
}

LLVM IR (-O2):
define double @root(i32 %0, double %1) {
%3 = tail call double @pow(double %1, i32 %0)
%4 = fsub double %3, %1
%5 = tail call double @llvm.fabs.f64(double %4)
%6 = fcmp ogt double %5, 1.000000e-03
br i1 %6, label %7, label %21
7: ; preds = %2, %7
%8 = phi double [ %16, %7 ], [ %1, %2 ]
%9 = phi double [ %14, %7 ], [ %1, %2 ]
%10 = phi double [ %13, %7 ], [ 1.000000e+00, %2 ]
%11 = tail call double @pow(double %8, i32 %0)
%12 = fcmp ogt double %11, %1
%13 = select i1 %12, double %10, double %8
%14 = select i1 %12, double %8, double %9
%15 = fadd double %13, %14
%16 = fmul double %15, 5.000000e-01
%17 = tail call double @pow(double %16, i32 %0)
%18 = fsub double %17, %1
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = fcmp ogt double %19, 1.000000e-03
br i1 %20, label %7, label %21
21: ; preds = %7, %2
%22 = phi double [ %1, %2 ], [ %16, %7 ]
ret double %22
}