#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 pow(double, double);
double nth_root(double a, double n) {
  double guess = 1.0, newn;
  int i;
  for (i = 0; i < 100; i++) {
    guess = ((n - 1) * guess + a / pow(guess, (n - 1))) / n;
    if (newn == guess) {
      return guess;
    }
    newn = guess;
  }
  return guess;
}


x86 assembly (clang, -O0):
<nth_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0xed6(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x64,-0x2c(%rbp)
jge    11ea <nth_root+0xda>
movsd  -0x18(%rbp),%xmm0
movsd  0xeb3(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe84(%rip),%xmm2
subsd  %xmm2,%xmm1
call   1030 <pow@plt>
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x38(%rbp),%xmm0
divsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    11d2 <nth_root+0xc2>
jp     11d2 <nth_root+0xc2>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f4 <nth_root+0xe4>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1136 <nth_root+0x26>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nth_root>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm0,0x18(%rsp)
movsd  0xedd(%rip),%xmm0
movsd  %xmm1,0x20(%rsp)
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xecd(%rip),%xmm0
mov    $0x63,%ebx
movsd  %xmm0,0x10(%rsp)
movsd  %xmm0,0x28(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <pow@plt>
movsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
divsd  0x20(%rsp),%xmm0
sub    $0x1,%ebx
setb   %al
movsd  0x28(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    1191 <nth_root+0x81>
jnp    1195 <nth_root+0x85>
test   %al,%al
je     1140 <nth_root+0x30>
add    $0x30,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double @nth_root(double %0, double %1) {
%3 = fadd double %1, -1.000000e+00
br label %4
4: ; preds = %4, %2
%5 = phi i32 [ 0, %2 ], [ %13, %4 ]
%6 = phi double [ undef, %2 ], [ %11, %4 ]
%7 = phi double [ 1.000000e+00, %2 ], [ %11, %4 ]
%8 = tail call double @pow(double %7, double %3)
%9 = fdiv double %0, %8
%10 = tail call double @llvm.fmuladd.f64(double %3, double %7, double %9)
%11 = fdiv double %10, %1
%12 = fcmp oeq double %6, %11
%13 = add nuw nsw i32 %5, 1
%14 = icmp eq i32 %13, 100
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %16, label %4
16: ; preds = %4
ret double %11
}