#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);
float get_f(float, float **, size_t);
float get_f_prime(float, float **, size_t);
int /*<<< orphan*/ isnan(float);
int pow(int, int);
int /*<<< orphan*/ printf(char *, int, ...);
void newrap_root_array(float f[][2], float **f_p, size_t size, float x0,
                       char loop) {
  int steps = 0;
  float x1, y, y_prime;
  printf("Starting from %g:\n", x0);
  while (++steps < 10000) {
    y = get_f(x0, f, size);
    y_prime = get_f_prime(x0, f_p, size);
    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_array(f, f_p, size, -x0, 0);
}


x86 assembly (clang, -O0):
<newrap_root_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
movl   $0x0,-0x24(%rbp)
cvttss2si -0x1c(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmp    $0x2710,%eax
jge    1287 <newrap_root_array+0x117>
movss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <get_f@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x1c(%rbp),%xmm0
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <get_f_prime@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
call   1060 <fabs@plt>
mov    %eax,-0x34(%rbp)
mov    $0xa,%edi
mov    $0xfffffff2,%esi
call   1090 <pow@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    1218 <newrap_root_array+0xa8>
jmp    1287 <newrap_root_array+0x117>
movss  -0x1c(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm1
divss  -0x30(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
subss  -0x1c(%rbp),%xmm0
call   1060 <fabs@plt>
mov    %eax,-0x3c(%rbp)
movss  -0x28(%rbp),%xmm0
call   1060 <fabs@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
mov    $0xa,%edi
mov    $0xfffffff9,%esi
call   1090 <pow@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    1278 <newrap_root_array+0x108>
jmp    1287 <newrap_root_array+0x117>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11a8 <newrap_root_array+0x38>
movss  -0x28(%rbp),%xmm0
call   1080 <isnan@plt>
cmp    $0x0,%eax
jne    12b9 <newrap_root_array+0x149>
mov    -0x24(%rbp),%esi
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd66(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12ca <newrap_root_array+0x15a>
mov    -0x24(%rbp),%esi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpb   $0x0,-0x1d(%rbp)
je     12f9 <newrap_root_array+0x189>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movss  -0x1c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
xor    %ecx,%ecx
call   1070 <newrap_root_array@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newrap_root_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,0x4(%rsp)
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
nopl   0x0(%rax,%rax,1)
movaps %xmm0,0x10(%rsp)
cvttss2si %xmm0,%esi
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movaps 0x10(%rsp),%xmm0
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <get_f@plt>
movss  %xmm0,0xc(%rsp)
movaps 0x10(%rsp),%xmm0
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <get_f_prime@plt>
movss  %xmm0,0x8(%rsp)
call   1060 <fabs@plt>
mov    $0xa,%edi
mov    $0xfffffff2,%esi
call   1080 <pow@plt>
movaps 0x10(%rsp),%xmm1
mov    $0x1,%r13d
movaps %xmm1,%xmm2
cs nopw 0x0(%rax,%rax,1)
nop
movaps %xmm1,0x10(%rsp)
movss  0xc(%rsp),%xmm0
divss  0x8(%rsp),%xmm0
subss  %xmm0,%xmm2
movss  %xmm2,(%rsp)
subss  %xmm1,%xmm2
movaps %xmm2,%xmm0
call   1060 <fabs@plt>
mov    %eax,%ebp
movss  (%rsp),%xmm0
call   1060 <fabs@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%ebp
mov    $0xa,%edi
mov    $0xfffffff9,%esi
call   1080 <pow@plt>
cmp    %eax,%ebp
jl     12b0 <newrap_root_array+0x150>
cmp    $0x270f,%r13d
movss  (%rsp),%xmm2
je     12c0 <newrap_root_array+0x160>
movaps %xmm2,%xmm0
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <get_f@plt>
movss  %xmm0,0xc(%rsp)
movss  (%rsp),%xmm0
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <get_f_prime@plt>
movss  %xmm0,0x8(%rsp)
call   1060 <fabs@plt>
mov    %eax,%r12d
mov    $0xa,%edi
mov    $0xfffffff2,%esi
call   1080 <pow@plt>
movss  (%rsp),%xmm2
add    $0x1,%r13d
movaps %xmm2,%xmm1
cmp    %eax,%r12d
jge    11f0 <newrap_root_array+0x90>
jmp    12c6 <newrap_root_array+0x166>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x4(%rsp),%ebp
movss  (%rsp),%xmm2
jmp    12d2 <newrap_root_array+0x172>
nopl   0x0(%rax,%rax,1)
mov    $0x2710,%r13d
movaps %xmm2,%xmm0
movaps %xmm2,0x10(%rsp)
mov    0x4(%rsp),%ebp
movaps %xmm2,%xmm0
call   1070 <isnan@plt>
test   %eax,%eax
je     1300 <newrap_root_array+0x1a0>
lea    0xd5f(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %bpl,%bpl
jne    131f <newrap_root_array+0x1bf>
jmp    1338 <newrap_root_array+0x1d8>
cs nopw 0x0(%rax,%rax,1)
movaps 0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd13(%rip),%rdi
mov    %r13d,%esi
mov    $0x1,%al
call   1050 <printf@plt>
test   %bpl,%bpl
je     1338 <newrap_root_array+0x1d8>
movaps 0x10(%rsp),%xmm0
xorps  0xcd5(%rip),%xmm0
movl   $0x0,0x4(%rsp)
jmp    1180 <newrap_root_array+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_array([2 x float]* %0, float** %1, i64 %2, float %3, i8 signext %4) {
%6 = alloca [2 x float]*
%7 = alloca float**
%8 = alloca i64
%9 = alloca float
%10 = alloca i8
%11 = alloca i32
%12 = alloca float
%13 = alloca float
%14 = alloca float
store [2 x float]* %0, [2 x float]** %6
store float** %1, float*** %7
store i64 %2, i64* %8
store float %3, float* %9
store i8 %4, i8* %10
store i32 0, i32* %11
%15 = load float, float* %9
%16 = fptosi float %15 to i32
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %53, %5
%19 = load i32, i32* %11
%20 = add nsw i32 %19, 1
store i32 %20, i32* %11
%21 = icmp slt i32 %20, 10000
br i1 %21, label %22, label %55
22: ; preds = %18
%23 = load float, float* %9
%24 = load [2 x float]*, [2 x float]** %6
%25 = bitcast [2 x float]* %24 to float**
%26 = load i64, i64* %8
%27 = call float @get_f(float %23, float** %25, i64 %26)
store float %27, float* %13
%28 = load float, float* %9
%29 = load float**, float*** %7
%30 = load i64, i64* %8
%31 = call float @get_f_prime(float %28, float** %29, i64 %30)
store float %31, float* %14
%32 = load float, float* %14
%33 = call i32 @fabs(float %32)
%34 = call i32 @pow(i32 10, i32 -14)
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %22
br label %55
37: ; preds = %22
%38 = load float, float* %9
%39 = load float, float* %13
%40 = load float, float* %14
%41 = fdiv float %39, %40
%42 = fsub float %38, %41
store float %42, float* %12
%43 = load float, float* %12
%44 = load float, float* %9
%45 = fsub float %43, %44
%46 = call i32 @fabs(float %45)
%47 = load float, float* %12
%48 = call i32 @fabs(float %47)
%49 = sdiv i32 %46, %48
%50 = call i32 @pow(i32 10, i32 -7)
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %37
br label %55
53: ; preds = %37
%54 = load float, float* %12
store float %54, float* %9
br label %18
55: ; preds = %52, %36, %18
%56 = load float, float* %12
%57 = call i32 @isnan(float %56)
%58 = icmp ne i32 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %55
%60 = load i32, i32* %11
%61 = load float, float* %9
%62 = fpext float %61 to double
%63 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %60, double %62)
br label %67
64: ; preds = %55
%65 = load i32, i32* %11
%66 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64, %59
%68 = load i8, i8* %10
%69 = icmp ne i8 %68, 0
br i1 %69, label %70, label %76
70: ; preds = %67
%71 = load [2 x float]*, [2 x float]** %6
%72 = load float**, float*** %7
%73 = load i64, i64* %8
%74 = load float, float* %9
%75 = fneg float %74
br label %76
76: ; preds = %70, %67
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_array([2 x float]* %0, float** %1, i64 %2, float %3, i8 signext %4) {
%6 = bitcast [2 x float]* %0 to float**
br label %7
7: ; preds = %51, %5
%8 = phi float [ %3, %5 ], [ %52, %51 ]
%9 = phi i8 [ %4, %5 ], [ 0, %51 ]
%10 = fptosi float %8 to i32
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = tail call float @get_f(float %8, float** %6, i64 %2)
%13 = tail call float @get_f_prime(float %8, float** %1, i64 %2)
%14 = tail call i32 @fabs(float %13)
%15 = tail call i32 @pow(i32 10, i32 -14)
%16 = icmp sge i32 %14, %15
br label %26
17: ; preds = %26
%18 = add nuw nsw i32 %30, 1
%19 = icmp eq i32 %18, 10000
br i1 %19, label %39, label %20
20: ; preds = %17
%21 = tail call float @get_f(float %32, float** %6, i64 %2)
%22 = tail call float @get_f_prime(float %32, float** %1, i64 %2)
%23 = tail call i32 @fabs(float %22)
%24 = tail call i32 @pow(i32 10, i32 -14)
%25 = icmp slt i32 %23, %24
br i1 %25, label %39, label %26
26: ; preds = %7, %20
%27 = phi float [ %22, %20 ], [ %13, %7 ]
%28 = phi float [ %21, %20 ], [ %12, %7 ]
%29 = phi float [ %32, %20 ], [ %8, %7 ]
%30 = phi i32 [ %18, %20 ], [ 1, %7 ]
%31 = fdiv float %28, %27
%32 = fsub float %29, %31
%33 = fsub float %32, %29
%34 = tail call i32 @fabs(float %33)
%35 = tail call i32 @fabs(float %32)
%36 = sdiv i32 %34, %35
%37 = tail call i32 @pow(i32 10, i32 -7)
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %17
39: ; preds = %17, %20, %26
%40 = phi float [ %29, %26 ], [ %32, %20 ], [ %32, %17 ]
%41 = phi i32 [ %30, %26 ], [ %18, %20 ], [ 10000, %17 ]
%42 = tail call i32 @isnan(float %32)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = fpext float %40 to double
%46 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %41, double %45)
br label %49
47: ; preds = %39
%48 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %49
49: ; preds = %47, %44
%50 = icmp eq i8 %9, 0
br i1 %50, label %53, label %51
51: ; preds = %49
%52 = fneg float %40
br label %7
53: ; preds = %49
ret void
}