#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 DBL_EPSILON;
double pow_(double, int);
double root(int n, double x) {
  double d, r = 1;
  if (!x) {
    return 0;
  }
  if (n < 1 || (x < 0 && !(n & 1))) {
    return 0.0 / 0.0;
  }
  do {
    d = (x / pow_(r, n - 1) - r) / n;
    r += d;
  } while (d >= DBL_EPSILON * 10 || d <= -DBL_EPSILON * 10);
  return r;
}


x86 assembly (clang, -O0):
<root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  0xed8(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1152 <root+0x42>
jp     1152 <root+0x42>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1230 <root+0x120>
cmpl   $0x1,-0xc(%rbp)
jl     1179 <root+0x69>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    118b <root+0x7b>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    118b <root+0x7b>
movsd  0xe87(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1230 <root+0x120>
jmp    1190 <root+0x80>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1030 <pow_@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
subsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    0x2e04(%rip),%rax
imul   $0xa,(%rax),%eax
cvtsi2sd %eax,%xmm1
mov    $0x1,%al
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    121b <root+0x10b>
movsd  -0x20(%rbp),%xmm1
xor    %eax,%eax
mov    0x2de0(%rip),%rcx
sub    (%rcx),%eax
imul   $0xa,%eax,%eax
cvtsi2sd %eax,%xmm0
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1190 <root+0x80>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<root>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorpd  %xmm2,%xmm2
movsd  %xmm0,(%rsp)
ucomisd %xmm2,%xmm0
jne    112c <root+0x1c>
jnp    11c9 <root+0xb9>
mov    %edi,%ebx
movsd  0xeca(%rip),%xmm2
test   %edi,%edi
jle    11c9 <root+0xb9>
xorpd  %xmm0,%xmm0
ucomisd (%rsp),%xmm0
jbe    1154 <root+0x44>
mov    %ebx,%eax
and    $0x1,%eax
je     11c9 <root+0xb9>
cvtsi2sd %ebx,%xmm3
add    $0xffffffff,%ebx
movsd  0xea5(%rip),%xmm2
mov    0x2e7e(%rip),%r14
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
mov    %ebx,%edi
call   1030 <pow_@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
subsd  %xmm2,%xmm1
divsd  %xmm3,%xmm1
addsd  %xmm1,%xmm2
mov    (%r14),%eax
add    %eax,%eax
lea    (%rax,%rax,4),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
ucomisd %xmm0,%xmm1
jae    1170 <root+0x60>
lea    (%rax,%rax,4),%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd %xmm1,%xmm0
jae    1170 <root+0x60>
movapd %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@DBL_EPSILON = global i32 0
define double @root(i32 %0, double %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
store double 1.000000e+00, double* %7
%8 = load double, double* %5
%9 = fcmp une double %8, 0.000000e+00
br i1 %9, label %11, label %10
10: ; preds = %2
store double 0.000000e+00, double* %3
br label %55
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 1
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = load double, double* %5
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32, i32* %4
%19 = and i32 %18, 1
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %17, %11
store double 0x7FF8000000000000, double* %3
br label %55
22: ; preds = %17, %14
br label %23
23: ; preds = %51, %22
%24 = load double, double* %5
%25 = load double, double* %7
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
%28 = call double @pow_(double %25, i32 %27)
%29 = fdiv double %24, %28
%30 = load double, double* %7
%31 = fsub double %29, %30
%32 = load i32, i32* %4
%33 = sitofp i32 %32 to double
%34 = fdiv double %31, %33
store double %34, double* %6
%35 = load double, double* %6
%36 = load double, double* %7
%37 = fadd double %36, %35
store double %37, double* %7
br label %38
38: ; preds = %23
%39 = load double, double* %6
%40 = load i32, i32* @DBL_EPSILON
%41 = mul nsw i32 %40, 10
%42 = sitofp i32 %41 to double
%43 = fcmp oge double %39, %42
br i1 %43, label %51, label %44
44: ; preds = %38
%45 = load double, double* %6
%46 = load i32, i32* @DBL_EPSILON
%47 = sub nsw i32 0, %46
%48 = mul nsw i32 %47, 10
%49 = sitofp i32 %48 to double
%50 = fcmp ole double %45, %49
br label %51
51: ; preds = %44, %38
%52 = phi i1 [ true, %38 ], [ %50, %44 ]
br i1 %52, label %23, label %53
53: ; preds = %51
%54 = load double, double* %7
store double %54, double* %3
br label %55
55: ; preds = %53, %21, %10
%56 = load double, double* %3
ret double %56
}

LLVM IR (-O2):
@DBL_EPSILON = global i32 0
define double @root(i32 %0, double %1) {
%3 = fcmp une double %1, 0.000000e+00
br i1 %3, label %4, label %30
4: ; preds = %2
%5 = icmp slt i32 %0, 1
br i1 %5, label %30, label %6
6: ; preds = %4
%7 = fcmp olt double %1, 0.000000e+00
%8 = and i32 %0, 1
%9 = icmp eq i32 %8, 0
%10 = and i1 %7, %9
br i1 %10, label %30, label %11
11: ; preds = %6
%12 = add nsw i32 %0, -1
%13 = sitofp i32 %0 to double
br label %14
14: ; preds = %29, %11
%15 = phi double [ 1.000000e+00, %11 ], [ %20, %29 ]
%16 = tail call double @pow_(double %15, i32 %12)
%17 = fdiv double %1, %16
%18 = fsub double %17, %15
%19 = fdiv double %18, %13
%20 = fadd double %15, %19
%21 = load i32, i32* @DBL_EPSILON
%22 = mul nsw i32 %21, 10
%23 = sitofp i32 %22 to double
%24 = fcmp ult double %19, %23
br i1 %24, label %25, label %29
25: ; preds = %14
%26 = mul i32 %21, -10
%27 = sitofp i32 %26 to double
%28 = fcmp ugt double %19, %27
br i1 %28, label %30, label %29
29: ; preds = %25, %14
br label %14
30: ; preds = %25, %4, %6, %2
%31 = phi double [ 0.000000e+00, %2 ], [ 0x7FF8000000000000, %6 ], [ 0x7FF8000000000000, %4 ], [ %20, %25 ]
ret double %31
}