#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 f(float);
float g(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main() {
  float x0, x1, h;
  printf("Enter first approximation");
  scanf("%f", &x0);
  do {
    x1 = x0 - f(x0) / g(x0);
    h = x1 > x0 ? x1 - x0 : x0 - x1;
    x0 = x1;
  } while (h > 0.000001);
  printf("Result: %f", x1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <g@plt>
movss  -0x18(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x14(%rbp),%xmm0
divss  %xmm2,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    11cd <main+0x8d>
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11dc <main+0x9c>
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdff(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     116d <main+0x2d>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe07(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed1(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <scanf@plt>
movss  0x10(%rsp),%xmm0
nopl   0x0(%rax)
movss  %xmm0,0xc(%rsp)
call   1030 <f@plt>
movss  %xmm0,0x14(%rsp)
movss  0x10(%rsp),%xmm0
call   1050 <g@plt>
movss  0x14(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x10(%rsp),%xmm3
movss  0xc(%rsp),%xmm1
subss  %xmm3,%xmm1
movaps %xmm3,%xmm2
subss  0xc(%rsp),%xmm2
cmpltss 0xc(%rsp),%xmm3
andps  %xmm3,%xmm1
andnps %xmm2,%xmm3
orps   %xmm1,%xmm3
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
ucomisd 0xe16(%rip),%xmm1
ja     1170 <main+0x30>
cvtss2sd %xmm0,%xmm0
lea    0xe2b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter first approximation\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [11 x i8] c"Result: %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
br label %7
7: ; preds = %29, %0
%8 = load float, float* %2
%9 = load float, float* %2
%10 = call float @f(float %9)
%11 = load float, float* %2
%12 = call float @g(float %11)
%13 = fdiv float %10, %12
%14 = fsub float %8, %13
store float %14, float* %3
%15 = load float, float* %3
%16 = load float, float* %2
%17 = fcmp ogt float %15, %16
br i1 %17, label %18, label %22
18: ; preds = %7
%19 = load float, float* %3
%20 = load float, float* %2
%21 = fsub float %19, %20
br label %26
22: ; preds = %7
%23 = load float, float* %2
%24 = load float, float* %3
%25 = fsub float %23, %24
br label %26
26: ; preds = %22, %18
%27 = phi float [ %21, %18 ], [ %25, %22 ]
store float %27, float* %4
%28 = load float, float* %3
store float %28, float* %2
br label %29
29: ; preds = %26
%30 = load float, float* %4
%31 = fpext float %30 to double
%32 = fcmp ogt double %31, 0x3EB0C6F7A0B5ED8D
br i1 %32, label %7, label %33
33: ; preds = %29
%34 = load float, float* %3
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"Enter first approximation\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [11 x i8] c"Result: %f\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%5 = load float, float* %1
br label %6
6: ; preds = %6, %0
%7 = phi float [ %12, %6 ], [ %5, %0 ]
%8 = call float @f(float %7)
%9 = load float, float* %1
%10 = call float @g(float %9)
%11 = fdiv float %8, %10
%12 = fsub float %7, %11
%13 = load float, float* %1
%14 = fcmp ogt float %12, %13
%15 = fsub float %12, %13
%16 = fsub float %13, %12
%17 = select i1 %14, float %15, float %16
store float %12, float* %1
%18 = fpext float %17 to double
%19 = fcmp ogt double %18, 0x3EB0C6F7A0B5ED8D
br i1 %19, label %6, label %20
20: ; preds = %6
%21 = fpext float %12 to double
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %21)
ret i32 0
}