#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 fabs(double);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, double, double);
int main(void) {
  double x, last_x, f, df;
  int i = 1;
  x = 1.0;
  do {
    last_x = x;
    f = 2 * x * x * x - 4 * x * x + 3 * x - 6;
    df = 6 * x * x - 8 * x + 3;
    x = x - f / df;
    printf("[%3d]x=%10g, |x_new-x_old|=%15g\n", i++, x, fabs(last_x - x));
  } while (fabs(last_x - x) > 1e-6);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
movsd  0xed2(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xee3(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  0xec4(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  0xe76(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe76(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe65(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xe4b(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe17(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
divsd  -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x2c(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movaps 0xe0d(%rip),%xmm2
pand   %xmm2,%xmm1
lea    0xe12(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movaps 0xdec(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xdd0(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1133 <main+0x23>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%esi
movsd  0xedd(%rip),%xmm1
lea    0xf26(%rip),%rbx
movapd %xmm1,%xmm0
xchg   %ax,%ax
movapd %xmm1,%xmm5
addsd  %xmm1,%xmm5
mulsd  %xmm1,%xmm5
movapd %xmm1,%xmm2
mulsd  0xec0(%rip),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm5
movapd %xmm1,%xmm3
mulsd  0xeb4(%rip),%xmm3
movapd %xmm1,%xmm4
unpcklpd %xmm3,%xmm4
movapd 0xeb4(%rip),%xmm3
addsd  %xmm2,%xmm5
unpcklpd %xmm1,%xmm3
mulpd  %xmm4,%xmm3
movapd %xmm1,%xmm2
mulsd  0xe94(%rip),%xmm2
unpcklpd %xmm2,%xmm5
addpd  %xmm5,%xmm3
addpd  0xe9c(%rip),%xmm3
movapd %xmm3,%xmm2
unpckhpd %xmm3,%xmm2
divsd  %xmm2,%xmm3
subsd  %xmm3,%xmm0
movapd %xmm0,(%rsp)
lea    0x1(%rsi),%ebp
subsd  %xmm0,%xmm1
andpd  0xe88(%rip),%xmm1
mov    %rbx,%rdi
call   1030 <printf@plt>
movapd (%rsp),%xmm0
movapd %xmm0,%xmm1
mov    %ebp,%esi
cmp    $0xa,%ebp
jne    1130 <main+0x20>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"[%3d]x=%10g, |x_new-x_old|=%15g\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %6
store double 1.000000e+00, double* %2
br label %7
7: ; preds = %44, %0
%8 = load double, double* %2
store double %8, double* %3
%9 = load double, double* %2
%10 = fmul double 2.000000e+00, %9
%11 = load double, double* %2
%12 = fmul double %10, %11
%13 = load double, double* %2
%14 = load double, double* %2
%15 = fmul double 4.000000e+00, %14
%16 = load double, double* %2
%17 = fmul double %15, %16
%18 = fneg double %17
%19 = call double @llvm.fmuladd.f64(double %12, double %13, double %18)
%20 = load double, double* %2
%21 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %20, double %19)
%22 = fsub double %21, 6.000000e+00
store double %22, double* %4
%23 = load double, double* %2
%24 = fmul double 6.000000e+00, %23
%25 = load double, double* %2
%26 = load double, double* %2
%27 = fmul double 8.000000e+00, %26
%28 = fneg double %27
%29 = call double @llvm.fmuladd.f64(double %24, double %25, double %28)
%30 = fadd double %29, 3.000000e+00
store double %30, double* %5
%31 = load double, double* %2
%32 = load double, double* %4
%33 = load double, double* %5
%34 = fdiv double %32, %33
%35 = fsub double %31, %34
store double %35, double* %2
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
%38 = load double, double* %2
%39 = load double, double* %3
%40 = load double, double* %2
%41 = fsub double %39, %40
%42 = call double @llvm.fabs.f64(double %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %36, double %38, double %42)
br label %44
44: ; preds = %7
%45 = load double, double* %3
%46 = load double, double* %2
%47 = fsub double %45, %46
%48 = call double @llvm.fabs.f64(double %47)
%49 = fcmp ogt double %48, 0x3EB0C6F7A0B5ED8D
br i1 %49, label %7, label %50
50: ; preds = %44
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"[%3d]x=%10g, |x_new-x_old|=%15g\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi double [ 1.000000e+00, %0 ], [ %21, %1 ]
%3 = phi i32 [ 1, %0 ], [ %22, %1 ]
%4 = fmul double %2, 2.000000e+00
%5 = fmul double %2, %4
%6 = fmul double %2, -4.000000e+00
%7 = fmul double %2, %6
%8 = tail call double @llvm.fmuladd.f64(double %5, double %2, double %7)
%9 = fmul double %2, 6.000000e+00
%10 = fmul double %2, -8.000000e+00
%11 = insertelement <2 x double> poison, double %2, i64 0
%12 = insertelement <2 x double> %11, double %9, i64 1
%13 = insertelement <2 x double> <double 3.000000e+00, double poison>, double %2, i64 1
%14 = insertelement <2 x double> poison, double %8, i64 0
%15 = insertelement <2 x double> %14, double %10, i64 1
%16 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %12, <2 x double> %13, <2 x double> %15)
%17 = fadd <2 x double> %16, <double -6.000000e+00, double 3.000000e+00>
%18 = extractelement <2 x double> %17, i64 0
%19 = extractelement <2 x double> %17, i64 1
%20 = fdiv double %18, %19
%21 = fsub double %2, %20
%22 = add nuw nsw i32 %3, 1
%23 = fsub double %2, %21
%24 = tail call double @llvm.fabs.f64(double %23)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %3, double %21, double %24)
%26 = icmp eq i32 %22, 10
br i1 %26, label %27, label %1
27: ; preds = %1
ret i32 0
}