#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 df(float);
float f(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  float s = 0, a;
  int i, n;
  float r1, r2;
  printf("Enter approximation range");
  scanf("%f%f", &r1, &r2);
  while (f(r1) < 0) {
    printf("%f", f(r1));
    r1++;
  }
  a = r1 + (1 + r1) / 2;
  printf("Initial approximation is %f", a);
  printf("Enter n\n");
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    s = a - (f(a) / df(a));
    a = s;
  }
  printf("%f\n", s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
movss  -0x18(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jbe    11c7 <main+0x87>
movss  -0x18(%rbp),%xmm0
call   1030 <f@plt>
cvtss2sd %xmm0,%xmm0
lea    0xe97(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0xe4c(%rip),%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    117b <main+0x3b>
movss  -0x18(%rbp),%xmm0
movss  0xe30(%rip),%xmm1
addss  -0x18(%rbp),%xmm1
movss  0xe1f(%rip),%xmm2
divss  %xmm2,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe29(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe32(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    128d <main+0x14d>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0xc(%rbp),%xmm0
call   1060 <df@plt>
movss  -0x24(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x20(%rbp),%xmm0
divss  %xmm2,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122c <main+0xec>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdb2(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x1c(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
movss  0x10(%rsp),%xmm0
call   1040 <f@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jbe    11da <main+0x8a>
lea    0xeab(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movss  0x10(%rsp),%xmm0
call   1040 <f@plt>
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movss  0x10(%rsp),%xmm0
addss  0xe39(%rip),%xmm0
movss  %xmm0,0x10(%rsp)
call   1040 <f@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
ja     11a0 <main+0x50>
movss  0x10(%rsp),%xmm0
movss  0xe18(%rip),%xmm1
addss  %xmm0,%xmm1
mulss  0xe10(%rip),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe1b(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1d(%rip),%rdi
xor    %ebx,%ebx
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0x14(%rsp)
jle    1295 <main+0x145>
movss  0xc(%rsp),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  %xmm0,0xc(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <f@plt>
movss  %xmm0,0x18(%rsp)
movss  0xc(%rsp),%xmm0
call   1070 <df@plt>
movss  0x18(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
subss  %xmm1,%xmm0
add    $0x1,%ebx
cmp    0x14(%rsp),%ebx
jl     1250 <main+0x100>
cvtss2sd %xmm0,%xmm0
jmp    1298 <main+0x148>
xorps  %xmm0,%xmm0
lea    0xda7(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter approximation range\00"
@.str.1 = [5 x i8] c"%f%f\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [28 x i8] c"Initial approximation is %f\00"
@.str.4 = [9 x i8] c"Enter n\0A\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
%7 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %6, float* %7)
br label %10
10: ; preds = %14, %0
%11 = load float, float* %6
%12 = call float @f(float %11)
%13 = fcmp olt float %12, 0.000000e+00
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load float, float* %6
%16 = call float @f(float %15)
%17 = fpext float %16 to double
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double %17)
%19 = load float, float* %6
%20 = fadd float %19, 1.000000e+00
store float %20, float* %6
br label %10
21: ; preds = %10
%22 = load float, float* %6
%23 = load float, float* %6
%24 = fadd float 1.000000e+00, %23
%25 = fdiv float %24, 2.000000e+00
%26 = fadd float %22, %25
store float %26, float* %3
%27 = load float, float* %3
%28 = fpext float %27 to double
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), double %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %5)
store i32 0, i32* %4
br label %32
32: ; preds = %45, %21
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load float, float* %3
%38 = load float, float* %3
%39 = call float @f(float %38)
%40 = load float, float* %3
%41 = call float @df(float %40)
%42 = fdiv float %39, %41
%43 = fsub float %37, %42
store float %43, float* %2
%44 = load float, float* %2
store float %44, float* %3
br label %45
45: ; preds = %36
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %32
48: ; preds = %32
%49 = load float, float* %2
%50 = fpext float %49 to double
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %50)
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@.str = [26 x i8] c"Enter approximation range\00"
@.str.1 = [5 x i8] c"%f%f\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [28 x i8] c"Initial approximation is %f\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [4 x i8] c"%f\0A\00"
@str = [8 x i8] c"Enter n\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = bitcast i32* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = bitcast float* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %2, float* %3)
%9 = load float, float* %2
%10 = call float @f(float %9)
%11 = fcmp olt float %10, 0.000000e+00
br i1 %11, label %12, label %21
12: ; preds = %0, %12
%13 = load float, float* %2
%14 = call float @f(float %13)
%15 = fpext float %14 to double
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double %15)
%17 = load float, float* %2
%18 = fadd float %17, 1.000000e+00
store float %18, float* %2
%19 = call float @f(float %18)
%20 = fcmp olt float %19, 0.000000e+00
br i1 %20, label %12, label %21
21: ; preds = %12, %0
%22 = load float, float* %2
%23 = fadd float %22, 1.000000e+00
%24 = fmul float %23, 5.000000e-01
%25 = fadd float %22, %24
%26 = fpext float %25 to double
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), double %26)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%30 = load i32, i32* %1
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %21, %32
%33 = phi i32 [ %39, %32 ], [ 0, %21 ]
%34 = phi float [ %38, %32 ], [ %25, %21 ]
%35 = call float @f(float %34)
%36 = call float @df(float %34)
%37 = fdiv float %35, %36
%38 = fsub float %34, %37
%39 = add nuw nsw i32 %33, 1
%40 = load i32, i32* %1
%41 = icmp slt i32 %39, %40
br i1 %41, label %32, label %42
42: ; preds = %32
%43 = fpext float %38 to double
br label %44
44: ; preds = %42, %21
%45 = phi double [ %43, %42 ], [ 0.000000e+00, %21 ]
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %45)
ret i32 0
}