#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 /*<<< orphan*/ exit(int);
double fabs(double);
double pow(double, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
int main() {
  double a, b, eps, x, x0, dx, d;
  int count = 0;
  printf("\na = ");
  scanf("%lf", &a);
  printf("b = ");
  scanf("%lf", &b);
  printf("eps = ");
  scanf("%lf", &eps);
  printf("\nInitial guess for x = ");
  scanf("%lf", &x);
  x0 = x;
  do {
    ++count;
    if (count > 30) {
      printf("\nError: no convergence\n");
      exit(1);
    }
    d = b - a * x * x;
    if (d < 0.) {
      printf("Error: complex roots - try another initial guess\n");
      exit(1);
    }
    x = pow(d, 0.2);
    dx = fabs((x - x0) / x);
    x0 = x;
    printf("Iter = %3d  x  = %8.4f   dx = %12.3e\n", count, x, dx);
  } while (dx > eps);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x44(%rbp)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe77(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe59(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <scanf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x1e,-0x44(%rbp)
jle    1203 <main+0xc3>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1261 <main+0x121>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  -0x40(%rbp),%xmm0
movsd  0xda2(%rip),%xmm1
call   1050 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movaps 0xd72(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x44(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xddb(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x38(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
ja     11d8 <main+0x98>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rbx
lea    0x40(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x38(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x30(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    $0x1,%ebx
movsd  0x8(%rsp),%xmm0
lea    0xe72(%rip),%r14
nopl   0x0(%rax)
cmp    $0x1f,%ebx
je     127d <main+0x12d>
movsd  %xmm0,0x10(%rsp)
movsd  0x38(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x40(%rsp),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1286 <main+0x136>
movsd  0xde1(%rip),%xmm1
call   1060 <pow@plt>
movsd  %xmm0,0x28(%rsp)
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
andpd  0xdca(%rip),%xmm1
movapd %xmm1,0x10(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%al
call   1040 <printf@plt>
add    $0x1,%ebx
movapd 0x10(%rsp),%xmm0
ucomisd 0x30(%rsp),%xmm0
movsd  0x28(%rsp),%xmm0
ja     11e0 <main+0x90>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe21(%rip),%rdi
jmp    128d <main+0x13d>
lea    0xde7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"\0Aa = \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [5 x i8] c"b = \00"
@.str.3 = [7 x i8] c"eps = \00"
@.str.4 = [24 x i8] c"\0AInitial guess for x = \00"
@.str.5 = [24 x i8] c"\0AError: no convergence\0A\00"
@.str.6 = [50 x i8] c"Error: complex roots - try another initial guess\0A\00"
@.str.7 = [38 x i8] c"Iter = %3d x = %8.4f dx = %12.3e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %4)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %5)
%18 = load double, double* %5
store double %18, double* %6
br label %19
19: ; preds = %54, %0
%20 = load i32, i32* %9
%21 = add nsw i32 %20, 1
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp sgt i32 %22, 30
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %19
%28 = load double, double* %3
%29 = load double, double* %2
%30 = load double, double* %5
%31 = fmul double %29, %30
%32 = load double, double* %5
%33 = fneg double %31
%34 = call double @llvm.fmuladd.f64(double %33, double %32, double %28)
store double %34, double* %8
%35 = load double, double* %8
%36 = fcmp olt double %35, 0.000000e+00
br i1 %36, label %37, label %40
37: ; preds = %27
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %27
%41 = load double, double* %8
%42 = call double @pow(double %41, double 2.000000e-01)
store double %42, double* %5
%43 = load double, double* %5
%44 = load double, double* %6
%45 = fsub double %43, %44
%46 = load double, double* %5
%47 = fdiv double %45, %46
%48 = call double @llvm.fabs.f64(double %47)
store double %48, double* %7
%49 = load double, double* %5
store double %49, double* %6
%50 = load i32, i32* %9
%51 = load double, double* %5
%52 = load double, double* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %50, double %51, double %52)
br label %54
54: ; preds = %40
%55 = load double, double* %7
%56 = load double, double* %4
%57 = fcmp ogt double %55, %56
br i1 %57, label %19, label %58
58: ; preds = %54
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"\0Aa = \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [5 x i8] c"b = \00"
@.str.3 = [7 x i8] c"eps = \00"
@.str.4 = [24 x i8] c"\0AInitial guess for x = \00"
@.str.7 = [38 x i8] c"Iter = %3d x = %8.4f dx = %12.3e\0A\00"
@str = [49 x i8] c"Error: complex roots - try another initial guess\00"
@str.8 = [23 x i8] c"\0AError: no convergence\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = bitcast double* %1 to i8*
%6 = bitcast double* %2 to i8*
%7 = bitcast double* %3 to i8*
%8 = bitcast double* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %4)
%17 = load double, double* %4
br label %18
18: ; preds = %37, %0
%19 = phi double [ %17, %0 ], [ %38, %37 ]
%20 = phi i32 [ 0, %0 ], [ %21, %37 ]
%21 = add nuw nsw i32 %20, 1
%22 = icmp eq i32 %20, 30
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = load double, double* %2
%28 = load double, double* %1
%29 = load double, double* %4
%30 = fneg double %28
%31 = fmul double %29, %30
%32 = call double @llvm.fmuladd.f64(double %31, double %29, double %27)
%33 = fcmp olt double %32, 0.000000e+00
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26
%38 = call double @pow(double %32, double 2.000000e-01)
store double %38, double* %4
%39 = fsub double %38, %19
%40 = fdiv double %39, %38
%41 = call double @llvm.fabs.f64(double %40)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %21, double %38, double %41)
%43 = load double, double* %3
%44 = fcmp ogt double %41, %43
br i1 %44, label %18, label %45
45: ; preds = %37
ret i32 0
}