#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 = 1., 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;
  while (dx > eps) {
    ++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);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe90(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe72(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe54(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <scanf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    12de <main+0x19e>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x1e,-0x44(%rbp)
jle    1220 <main+0xe0>
lea    0xe3f(%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    127e <main+0x13e>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  -0x40(%rbp),%xmm0
movsd  0xd7d(%rip),%xmm1
call   1050 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movaps 0xd65(%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    0xdc6(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    11e5 <main+0xa5>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeca(%rip),%rbx
lea    0x30(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x28(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
movsd  0xe30(%rip),%xmm0
ucomisd 0x8(%rsp),%xmm0
jbe    1281 <main+0x131>
mov    $0x1,%ebx
movsd  (%rsp),%xmm0
lea    0xe71(%rip),%r14
nopl   (%rax)
cmp    $0x1f,%ebx
je     128b <main+0x13b>
movsd  %xmm0,0x10(%rsp)
movsd  0x28(%rsp),%xmm0
movsd  (%rsp),%xmm1
movsd  0x30(%rsp),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1294 <main+0x144>
movsd  0xdda(%rip),%xmm1
call   1060 <pow@plt>
movsd  %xmm0,0x20(%rsp)
movsd  %xmm0,(%rsp)
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
andpd  0xdcc(%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 0x8(%rsp),%xmm0
movsd  0x20(%rsp),%xmm0
ja     11f0 <main+0xa0>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe23(%rip),%rdi
jmp    129b <main+0x14b>
lea    0xde9(%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 double 1.000000e+00, double* %7
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 = %44, %0
%20 = load double, double* %7
%21 = load double, double* %4
%22 = fcmp ogt double %20, %21
br i1 %22, label %23, label %58
23: ; preds = %19
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 1
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp sgt i32 %26, 30
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = load double, double* %3
%33 = load double, double* %2
%34 = load double, double* %5
%35 = fmul double %33, %34
%36 = load double, double* %5
%37 = fneg double %35
%38 = call double @llvm.fmuladd.f64(double %37, double %36, double %32)
store double %38, double* %8
%39 = load double, double* %8
%40 = fcmp olt double %39, 0.000000e+00
br i1 %40, label %41, label %44
41: ; preds = %31
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %31
%45 = load double, double* %8
%46 = call double @pow(double %45, double 2.000000e-01)
store double %46, double* %5
%47 = load double, double* %5
%48 = load double, double* %6
%49 = fsub double %47, %48
%50 = load double, double* %5
%51 = fdiv double %49, %50
%52 = call double @llvm.fabs.f64(double %51)
store double %52, double* %7
%53 = load double, double* %5
store double %53, double* %6
%54 = load i32, i32* %9
%55 = load double, double* %5
%56 = load double, double* %7
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %54, double %55, double %56)
br label %19
58: ; preds = %19
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* %3
%18 = fcmp olt double %17, 1.000000e+00
br i1 %18, label %19, label %48
19: ; preds = %0
%20 = load double, double* %4
br label %21
21: ; preds = %19, %40
%22 = phi i32 [ %24, %40 ], [ 0, %19 ]
%23 = phi double [ %41, %40 ], [ %20, %19 ]
%24 = add nuw nsw i32 %22, 1
%25 = icmp eq i32 %22, 30
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load double, double* %2
%31 = load double, double* %1
%32 = load double, double* %4
%33 = fneg double %31
%34 = fmul double %32, %33
%35 = call double @llvm.fmuladd.f64(double %34, double %32, double %30)
%36 = fcmp olt double %35, 0.000000e+00
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %29
%41 = call double @pow(double %35, double 2.000000e-01)
store double %41, double* %4
%42 = fsub double %41, %23
%43 = fdiv double %42, %41
%44 = call double @llvm.fabs.f64(double %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %24, double %41, double %44)
%46 = load double, double* %3
%47 = fcmp ogt double %44, %46
br i1 %47, label %21, label %48
48: ; preds = %40, %0
ret i32 0
}