#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 f(double);
double g(double);
int /*<<< orphan*/ printf(char *, int);
int main() {
  double x0, x1, diff;
  int i = 0;
  x0 = 1;
  do {
    x1 = x0 - f(x0) / g(x0);
    diff = x0 > x1 ? (x0 - x1) : x1 - x0;
    x0 = x1;
    i++;
  } while (diff > 0.00001);
  printf("The Root correct upto 4 decimal places if %.4lf ", x1);
  printf("\nNo of Iterations required: %d", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <g@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11b4 <main+0x84>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11c3 <main+0x93>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1153 <main+0x23>
cvttsd2si -0x18(%rbp),%esi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xor    %ebx,%ebx
movsd  0xec1(%rip),%xmm3
nop
movsd  %xmm3,0x18(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x8(%rsp)
call   1030 <f@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <g@plt>
movsd  0x18(%rsp),%xmm3
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
subsd  %xmm1,%xmm3
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm0
subsd  %xmm3,%xmm0
movapd %xmm3,%xmm1
subsd  %xmm2,%xmm1
movapd %xmm2,%xmm4
movapd %xmm3,%xmm2
cmpltsd %xmm4,%xmm2
andpd  %xmm2,%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
add    $0x1,%ebx
ucomisd 0xe54(%rip),%xmm2
ja     1140 <main+0x10>
cvttsd2si %xmm3,%esi
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [49 x i8] c"The Root correct upto 4 decimal places if %.4lf \00"
@.str.1 = [31 x i8] c"\0ANo of Iterations required: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store double 1.000000e+00, double* %2
br label %6
6: ; preds = %30, %0
%7 = load double, double* %2
%8 = load double, double* %2
%9 = call double @f(double %8)
%10 = load double, double* %2
%11 = call double @g(double %10)
%12 = fdiv double %9, %11
%13 = fsub double %7, %12
store double %13, double* %3
%14 = load double, double* %2
%15 = load double, double* %3
%16 = fcmp ogt double %14, %15
br i1 %16, label %17, label %21
17: ; preds = %6
%18 = load double, double* %2
%19 = load double, double* %3
%20 = fsub double %18, %19
br label %25
21: ; preds = %6
%22 = load double, double* %3
%23 = load double, double* %2
%24 = fsub double %22, %23
br label %25
25: ; preds = %21, %17
%26 = phi double [ %20, %17 ], [ %24, %21 ]
store double %26, double* %4
%27 = load double, double* %3
store double %27, double* %2
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %30
30: ; preds = %25
%31 = load double, double* %4
%32 = fcmp ogt double %31, 1.000000e-05
br i1 %32, label %6, label %33
33: ; preds = %30
%34 = load double, double* %3
%35 = fptosi double %34 to i32
%36 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %5
%38 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [49 x i8] c"The Root correct upto 4 decimal places if %.4lf \00"
@.str.1 = [31 x i8] c"\0ANo of Iterations required: %d\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi double [ 1.000000e+00, %0 ], [ %7, %1 ]
%3 = phi i32 [ 0, %0 ], [ %12, %1 ]
%4 = tail call double @f(double %2)
%5 = tail call double @g(double %2)
%6 = fdiv double %4, %5
%7 = fsub double %2, %6
%8 = fcmp ogt double %2, %7
%9 = fsub double %2, %7
%10 = fsub double %7, %2
%11 = select i1 %8, double %9, double %10
%12 = add nuw nsw i32 %3, 1
%13 = fcmp ogt double %11, 1.000000e-05
br i1 %13, label %1, label %14
14: ; preds = %1
%15 = fptosi double %7 to i32
%16 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %12)
ret i32 0
}