#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 fabs(float);
int /*<<< orphan*/ isnan(float);
int pow(int, int);
int /*<<< orphan*/ printf(char *, int, ...);
void newrap_root(float (*f)(float), float (*f_prime)(float), float x0,
                 char loop) {
  int steps = 0;
  float x1, y, y_prime;
  printf("Starting from %g:\n", x0);
  while (++steps < 10000) {
    y = f(x0);
    y_prime = f_prime(x0);
    if (fabs(y_prime) < pow(10, -14)) {
      break;
    }
    x1 = x0 - y / y_prime;
    if (fabs(x1 - x0) / fabs(x1) < pow(10, -7)) {
      break;
    }
    x0 = x1;
  }
  if (!isnan(x1)) {
    printf("  After %d steps: found root %g\n", steps, x0);
  } else {
    printf("After %d steps: found no root\n", steps);
  }
  if (loop)
    newrap_root(f, f_prime, -x0, 0);
}


x86 assembly (clang, -O0):
<newrap_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
movl   $0x0,-0x1c(%rbp)
cvttss2si -0x14(%rbp),%esi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x2710,%eax
jge    1255 <newrap_root+0x105>
mov    -0x8(%rbp),%rax
movss  -0x14(%rbp),%xmm0
call   *%rax
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movss  -0x14(%rbp),%xmm0
call   *%rax
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,-0x2c(%rbp)
mov    $0xa,%edi
mov    $0xfffffff2,%esi
call   1070 <pow@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    11e6 <newrap_root+0x96>
jmp    1255 <newrap_root+0x105>
movss  -0x14(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
divss  -0x28(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,-0x34(%rbp)
movss  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    $0xa,%edi
mov    $0xfffffff9,%esi
call   1070 <pow@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jge    1246 <newrap_root+0xf6>
jmp    1255 <newrap_root+0x105>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1184 <newrap_root+0x34>
movss  -0x20(%rbp),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%eax
jne    1287 <newrap_root+0x137>
mov    -0x1c(%rbp),%esi
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd98(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1298 <newrap_root+0x148>
mov    -0x1c(%rbp),%esi
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpb   $0x0,-0x15(%rbp)
je     12c3 <newrap_root+0x173>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movss  -0x14(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
xor    %edx,%edx
call   1060 <newrap_root@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newrap_root>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
movaps %xmm0,0x10(%rsp)
cvttss2si %xmm0,%esi
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movaps 0x10(%rsp),%xmm0
call   *%rbx
movss  %xmm0,0xc(%rsp)
movaps 0x10(%rsp),%xmm0
call   *%r14
movss  %xmm0,0x8(%rsp)
call   1040 <fabs@plt>
mov    $0xa,%edi
mov    $0xfffffff2,%esi
call   1060 <pow@plt>
movaps 0x10(%rsp),%xmm1
mov    $0x1,%r12d
movaps %xmm1,%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movaps %xmm1,0x10(%rsp)
movss  0xc(%rsp),%xmm0
divss  0x8(%rsp),%xmm0
subss  %xmm0,%xmm2
movss  %xmm2,0x4(%rsp)
subss  %xmm1,%xmm2
movaps %xmm2,%xmm0
call   1040 <fabs@plt>
mov    %eax,%ebp
movss  0x4(%rsp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%ebp
mov    $0xa,%edi
mov    $0xfffffff9,%esi
call   1060 <pow@plt>
cmp    %eax,%ebp
jl     1270 <newrap_root+0x130>
cmp    $0x270f,%r12d
movss  0x4(%rsp),%xmm2
je     1280 <newrap_root+0x140>
movaps %xmm2,%xmm0
call   *%rbx
movss  %xmm0,0xc(%rsp)
movss  0x4(%rsp),%xmm0
call   *%r14
movss  %xmm0,0x8(%rsp)
call   1040 <fabs@plt>
mov    %eax,%r13d
mov    $0xa,%edi
mov    $0xfffffff2,%esi
call   1060 <pow@plt>
movss  0x4(%rsp),%xmm2
add    $0x1,%r12d
movaps %xmm2,%xmm1
cmp    %eax,%r13d
jge    11c0 <newrap_root+0x80>
jmp    1286 <newrap_root+0x146>
nopl   0x0(%rax,%rax,1)
movss  0x4(%rsp),%xmm2
jmp    128e <newrap_root+0x14e>
nopl   0x0(%rax,%rax,1)
mov    $0x2710,%r12d
movaps %xmm2,%xmm0
movaps %xmm2,0x10(%rsp)
movaps %xmm2,%xmm0
call   1050 <isnan@plt>
test   %eax,%eax
je     12c0 <newrap_root+0x180>
lea    0xda3(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r15b,%r15b
jne    12df <newrap_root+0x19f>
jmp    12f3 <newrap_root+0x1b3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movaps 0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd53(%rip),%rdi
mov    %r12d,%esi
mov    $0x1,%al
call   1030 <printf@plt>
test   %r15b,%r15b
je     12f3 <newrap_root+0x1b3>
movaps 0x10(%rsp),%xmm0
xorps  0xd15(%rip),%xmm0
xor    %r15d,%r15d
jmp    1160 <newrap_root+0x20>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Starting from %g:\0A\00"
@.str.1 = [33 x i8] c" After %d steps: found root %g\0A\00"
@.str.2 = [31 x i8] c"After %d steps: found no root\0A\00"
define void @newrap_root(float (float)* %0, float (float)* %1, float %2, i8 signext %3) {
%5 = alloca float (float)*
%6 = alloca float (float)*
%7 = alloca float
%8 = alloca i8
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = alloca float
store float (float)* %0, float (float)** %5
store float (float)* %1, float (float)** %6
store float %2, float* %7
store i8 %3, i8* %8
store i32 0, i32* %9
%13 = load float, float* %7
%14 = fptosi float %13 to i32
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %48, %4
%17 = load i32, i32* %9
%18 = add nsw i32 %17, 1
store i32 %18, i32* %9
%19 = icmp slt i32 %18, 10000
br i1 %19, label %20, label %50
20: ; preds = %16
%21 = load float (float)*, float (float)** %5
%22 = load float, float* %7
%23 = call float %21(float %22)
store float %23, float* %11
%24 = load float (float)*, float (float)** %6
%25 = load float, float* %7
%26 = call float %24(float %25)
store float %26, float* %12
%27 = load float, float* %12
%28 = call i32 @fabs(float %27)
%29 = call i32 @pow(i32 10, i32 -14)
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %20
br label %50
32: ; preds = %20
%33 = load float, float* %7
%34 = load float, float* %11
%35 = load float, float* %12
%36 = fdiv float %34, %35
%37 = fsub float %33, %36
store float %37, float* %10
%38 = load float, float* %10
%39 = load float, float* %7
%40 = fsub float %38, %39
%41 = call i32 @fabs(float %40)
%42 = load float, float* %10
%43 = call i32 @fabs(float %42)
%44 = sdiv i32 %41, %43
%45 = call i32 @pow(i32 10, i32 -7)
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %32
br label %50
48: ; preds = %32
%49 = load float, float* %10
store float %49, float* %7
br label %16
50: ; preds = %47, %31, %16
%51 = load float, float* %10
%52 = call i32 @isnan(float %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %59, label %54
54: ; preds = %50
%55 = load i32, i32* %9
%56 = load float, float* %7
%57 = fpext float %56 to double
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %55, double %57)
br label %62
59: ; preds = %50
%60 = load i32, i32* %9
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %59, %54
%63 = load i8, i8* %8
%64 = icmp ne i8 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load float (float)*, float (float)** %5
%67 = load float (float)*, float (float)** %6
%68 = load float, float* %7
%69 = fneg float %68
br label %70
70: ; preds = %65, %62
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Starting from %g:\0A\00"
@.str.1 = [33 x i8] c" After %d steps: found root %g\0A\00"
@.str.2 = [31 x i8] c"After %d steps: found no root\0A\00"
define void @newrap_root(float (float)* nocapture %0, float (float)* nocapture %1, float %2, i8 signext %3) {
br label %5
5: ; preds = %49, %4
%6 = phi float [ %2, %4 ], [ %50, %49 ]
%7 = phi i8 [ %3, %4 ], [ 0, %49 ]
%8 = fptosi float %6 to i32
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call float %0(float %6)
%11 = tail call float %1(float %6)
%12 = tail call i32 @fabs(float %11)
%13 = tail call i32 @pow(i32 10, i32 -14)
%14 = icmp sge i32 %12, %13
br label %24
15: ; preds = %24
%16 = add nuw nsw i32 %28, 1
%17 = icmp eq i32 %16, 10000
br i1 %17, label %37, label %18
18: ; preds = %15
%19 = tail call float %0(float %30)
%20 = tail call float %1(float %30)
%21 = tail call i32 @fabs(float %20)
%22 = tail call i32 @pow(i32 10, i32 -14)
%23 = icmp slt i32 %21, %22
br i1 %23, label %37, label %24
24: ; preds = %5, %18
%25 = phi float [ %20, %18 ], [ %11, %5 ]
%26 = phi float [ %19, %18 ], [ %10, %5 ]
%27 = phi float [ %30, %18 ], [ %6, %5 ]
%28 = phi i32 [ %16, %18 ], [ 1, %5 ]
%29 = fdiv float %26, %25
%30 = fsub float %27, %29
%31 = fsub float %30, %27
%32 = tail call i32 @fabs(float %31)
%33 = tail call i32 @fabs(float %30)
%34 = sdiv i32 %32, %33
%35 = tail call i32 @pow(i32 10, i32 -7)
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %15
37: ; preds = %15, %18, %24
%38 = phi float [ %27, %24 ], [ %30, %18 ], [ %30, %15 ]
%39 = phi i32 [ %28, %24 ], [ %16, %18 ], [ 10000, %15 ]
%40 = tail call i32 @isnan(float %30)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = fpext float %38 to double
%44 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %39, double %43)
br label %47
45: ; preds = %37
%46 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %47
47: ; preds = %45, %42
%48 = icmp eq i8 %7, 0
br i1 %48, label %51, label %49
49: ; preds = %47
%50 = fneg float %38
br label %5
51: ; preds = %47
ret void
}