#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 */
float powi(float, int);
float nthroot(int n, float a, int maxiter) {
  int i;
  float x = 1.f, nf = (float)n;
  for (i = 0; i < maxiter; i++)
    x = ((nf - 1) * a * powi(x, n) + 1) / (a * nf * powi(x, n - 1));
  return 1.f / x;
}


x86 assembly (clang, -O0):
<nthroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movss  %xmm0,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movss  0xed5(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
cvtsi2ssl -0x4(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d9 <nthroot+0xc9>
movss  -0x18(%rbp),%xmm0
movss  0xea6(%rip),%xmm1
subss  %xmm1,%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x14(%rbp),%xmm0
mov    -0x4(%rbp),%edi
call   1030 <powi@plt>
movaps %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  0xe77(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
call   1030 <powi@plt>
movss  -0x20(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x1c(%rbp),%xmm0
mulss  %xmm2,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1141 <nthroot+0x31>
movss  0xe1f(%rip),%xmm0
divss  -0x14(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nthroot>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movss  0xee0(%rip),%xmm1
test   %esi,%esi
jle    11a6 <nthroot+0x96>
mov    %esi,%ebx
mov    %edi,%r14d
xorps  %xmm1,%xmm1
cvtsi2ss %edi,%xmm1
movss  0xec8(%rip),%xmm2
addss  %xmm1,%xmm2
mulss  %xmm0,%xmm2
movss  %xmm2,(%rsp)
mulss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
lea    -0x1(%r14),%ebp
movss  0xea1(%rip),%xmm0
nop
movss  %xmm0,0xc(%rsp)
mov    %r14d,%edi
call   1030 <powi@plt>
mulss  (%rsp),%xmm0
addss  0xe85(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
movss  0xc(%rsp),%xmm0
mov    %ebp,%edi
call   1030 <powi@plt>
movss  0x8(%rsp),%xmm1
mulss  0x4(%rsp),%xmm0
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0xffffffff,%ebx
jne    1160 <nthroot+0x50>
movss  0xe52(%rip),%xmm0
divss  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define float @nthroot(i32 %0, float %1, i32 %2) {
%4 = sitofp i32 %0 to float
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = fadd float %4, -1.000000e+00
%8 = fmul float %7, %1
%9 = fmul float %4, %1
%10 = add nsw i32 %0, -1
br label %11
11: ; preds = %6, %11
%12 = phi i32 [ 0, %6 ], [ %19, %11 ]
%13 = phi float [ 1.000000e+00, %6 ], [ %18, %11 ]
%14 = tail call float @powi(float %13, i32 %0)
%15 = tail call float @llvm.fmuladd.f32(float %8, float %14, float 1.000000e+00)
%16 = tail call float @powi(float %13, i32 %10)
%17 = fmul float %9, %16
%18 = fdiv float %15, %17
%19 = add nuw nsw i32 %12, 1
%20 = icmp eq i32 %19, %2
br i1 %20, label %21, label %11
21: ; preds = %11, %3
%22 = phi float [ 1.000000e+00, %3 ], [ %18, %11 ]
%23 = fdiv float 1.000000e+00, %22
ret float %23
}