#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 f1(double);
double f_prime1(double);
int fabs(double);
int /*<<< orphan*/ printf(char *, ...);
double newtons_method(double x_0, double error_tol, double max_iters) {
  int count = 0;
  double x_new = x_0;
  printf("Now calculating \n");
  printf(". \n");
  printf(".. \n\n");
  do {
    x_0 = x_new;
    count++;
    if (f_prime1(x_0) == 0) {
      printf("f_prime( x_old ) is zero!\n");
      break;
    }
    x_new = x_0 - f1(x_0) / f_prime1(x_0);
  } while (fabs(x_new - x_0) > (error_tol && (count <= max_iters)));
  printf("Results: \n");
  printf("x_0 = %lf \n", x_0);
  printf("x_new = %lf \n", x_new);
  printf("Number of iterations = %d \n", count);
  printf("count = %d \n", count);
  printf("error_tol = %lf \n", error_tol);
  if (count > max_iters) {
    printf("Iteration did not convereg.\n\n");
  } else {
    printf("Iteration did convereg.\n\n");
  }
  return x_new;
}


x86 assembly (clang, -O0):
<newtons_method>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1060 <f_prime1@plt>
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d5 <newtons_method+0x95>
jp     11d5 <newtons_method+0x95>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126e <newtons_method+0x12e>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <f1@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1060 <f_prime1@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
jne    1246 <newtons_method+0x106>
jp     1246 <newtons_method+0x106>
jmp    125a <newtons_method+0x11a>
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x39(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x39(%rbp),%cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
jg     1192 <newtons_method+0x52>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
lea    0xdba(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xdb3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xdb5(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cvtsi2sdl -0x1c(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    12fa <newtons_method+0x1ba>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1308 <newtons_method+0x1c8>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newtons_method>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movsd  %xmm2,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,(%rsp)
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
lea    0xef3(%rip),%rdi
call   1030 <puts@plt>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rsp),%xmm0
mov    %ecx,%r14d
movsd  %xmm0,0x8(%rsp)
call   1070 <f_prime1@plt>
ucomisd 0xe45(%rip),%xmm0
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,0x10(%rsp)
jne    11d1 <newtons_method+0x81>
jnp    1251 <newtons_method+0x101>
movsd  0x18(%rsp),%xmm0
ucomisd 0xe21(%rip),%xmm0
setp   %al
setne  %bl
or     %al,%bl
movsd  0x8(%rsp),%xmm0
call   1060 <f1@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <f_prime1@plt>
movsd  (%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,(%rsp)
subsd  %xmm1,%xmm0
call   1050 <fabs@plt>
movsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
ucomisd %xmm1,%xmm0
setae  %cl
and    %bl,%cl
movzbl %cl,%edx
lea    0x1(%r14),%ecx
cmp    %edx,%eax
movapd %xmm1,%xmm0
jg     11a0 <newtons_method+0x50>
jmp    126e <newtons_method+0x11e>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
lea    0xd81(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd79(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd74(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd7f(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd7b(%rip),%rdi
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
ucomisd 0x20(%rsp),%xmm0
lea    0xda9(%rip),%rax
lea    0xd89(%rip),%rdi
cmova  %rax,%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Now calculating \0A\00"
@.str.1 = [4 x i8] c". \0A\00"
@.str.2 = [6 x i8] c".. \0A\0A\00"
@.str.3 = [27 x i8] c"f_prime( x_old ) is zero!\0A\00"
@.str.4 = [11 x i8] c"Results: \0A\00"
@.str.5 = [12 x i8] c"x_0 = %lf \0A\00"
@.str.6 = [14 x i8] c"x_new = %lf \0A\00"
@.str.7 = [28 x i8] c"Number of iterations = %d \0A\00"
@.str.8 = [13 x i8] c"count = %d \0A\00"
@.str.9 = [18 x i8] c"error_tol = %lf \0A\00"
@.str.10 = [30 x i8] c"Iteration did not convereg.\0A\0A\00"
@.str.11 = [26 x i8] c"Iteration did convereg.\0A\0A\00"
define double @newtons_method(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
store i32 0, i32* %7
%9 = load double, double* %4
store double %9, double* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %42, %3
%14 = load double, double* %8
store double %14, double* %4
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
%17 = load double, double* %4
%18 = call double @f_prime1(double %17)
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %46
22: ; preds = %13
%23 = load double, double* %4
%24 = load double, double* %4
%25 = call double @f1(double %24)
%26 = load double, double* %4
%27 = call double @f_prime1(double %26)
%28 = fdiv double %25, %27
%29 = fsub double %23, %28
store double %29, double* %8
br label %30
30: ; preds = %22
%31 = load double, double* %8
%32 = load double, double* %4
%33 = fsub double %31, %32
%34 = call i32 @fabs(double %33)
%35 = load double, double* %5
%36 = fcmp une double %35, 0.000000e+00
br i1 %36, label %37, label %42
37: ; preds = %30
%38 = load i32, i32* %7
%39 = sitofp i32 %38 to double
%40 = load double, double* %6
%41 = fcmp ole double %39, %40
br label %42
42: ; preds = %37, %30
%43 = phi i1 [ false, %30 ], [ %41, %37 ]
%44 = zext i1 %43 to i32
%45 = icmp sgt i32 %34, %44
br i1 %45, label %13, label %46
46: ; preds = %42, %20
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%48 = load double, double* %4
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %48)
%50 = load double, double* %8
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), double %50)
%52 = load i32, i32* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %7
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %54)
%56 = load double, double* %5
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), double %56)
%58 = load i32, i32* %7
%59 = sitofp i32 %58 to double
%60 = load double, double* %6
%61 = fcmp ogt double %59, %60
br i1 %61, label %62, label %64
62: ; preds = %46
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
br label %66
64: ; preds = %46
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0))
br label %66
66: ; preds = %64, %62
%67 = load double, double* %8
ret double %67
}

LLVM IR (-O2):
@.str.5 = [12 x i8] c"x_0 = %lf \0A\00"
@.str.6 = [14 x i8] c"x_new = %lf \0A\00"
@.str.7 = [28 x i8] c"Number of iterations = %d \0A\00"
@.str.8 = [13 x i8] c"count = %d \0A\00"
@.str.9 = [18 x i8] c"error_tol = %lf \0A\00"
@str = [17 x i8] c"Now calculating \00"
@str.12 = [3 x i8] c". \00"
@str.13 = [5 x i8] c".. \0A\00"
@str.14 = [10 x i8] c"Results: \00"
@str.15 = [25 x i8] c"Iteration did convereg.\0A\00"
@str.16 = [29 x i8] c"Iteration did not convereg.\0A\00"
@str.17 = [26 x i8] c"f_prime( x_old ) is zero!\00"
define double @newtons_method(double %0, double %1, double %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.12, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.13, i64 0, i64 0))
%7 = fcmp une double %1, 0.000000e+00
br label %8
8: ; preds = %17, %3
%9 = phi i32 [ 0, %3 ], [ %11, %17 ]
%10 = phi double [ %0, %3 ], [ %21, %17 ]
%11 = add nuw nsw i32 %9, 1
%12 = tail call double @f_prime1(double %10)
%13 = fcmp oeq double %12, 0.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.17, i64 0, i64 0))
%16 = sitofp i32 %11 to double
br label %29
17: ; preds = %8
%18 = tail call double @f1(double %10)
%19 = tail call double @f_prime1(double %10)
%20 = fdiv double %18, %19
%21 = fsub double %10, %20
%22 = fsub double %21, %10
%23 = tail call i32 @fabs(double %22)
%24 = sitofp i32 %11 to double
%25 = fcmp ole double %24, %2
%26 = select i1 %7, i1 %25, i1 false
%27 = zext i1 %26 to i32
%28 = icmp sgt i32 %23, %27
br i1 %28, label %8, label %29
29: ; preds = %17, %14
%30 = phi double [ %16, %14 ], [ %24, %17 ]
%31 = phi double [ %10, %14 ], [ %21, %17 ]
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.14, i64 0, i64 0))
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %10)
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), double %31)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %11)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %11)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), double %1)
%38 = fcmp ogt double %30, %2
%39 = select i1 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @str.16, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @str.15, i64 0, i64 0)
%40 = tail call i32 @puts(i8* dereferenceable(1) %39)
ret double %31
}