#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*/ approximatelyEqual(double, double);
int /*<<< orphan*/ printf(char *, double);
double cubeRoot(double x) {
  double g;
  if (x == 0)
    return (0);
  if (x < 0)
    printf("cubeRoot called with negative arguments %g", x);
  g = x;
  while (!approximatelyEqual(x, g * g * g)) {
    g = (g + x / (g * g)) / 2;
  }
  return g;
}


x86 assembly (clang, -O0):
<cubeRoot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1152 <cubeRoot+0x32>
jp     1152 <cubeRoot+0x32>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e5 <cubeRoot+0xc5>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1171 <cubeRoot+0x51>
movsd  -0x10(%rbp),%xmm0
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
call   1030 <approximatelyEqual@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a9 <cubeRoot+0x89>
jmp    11db <cubeRoot+0xbb>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
mulsd  -0x18(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  0xe33(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    117b <cubeRoot+0x5b>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cubeRoot>:
sub    $0x18,%rsp
xorpd  %xmm2,%xmm2
movsd  %xmm0,(%rsp)
ucomisd %xmm2,%xmm0
jne    1139 <cubeRoot+0x19>
jnp    11da <cubeRoot+0xba>
xorpd  %xmm0,%xmm0
ucomisd (%rsp),%xmm0
jbe    1155 <cubeRoot+0x35>
lea    0xebd(%rip),%rdi
movsd  (%rsp),%xmm0
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mulsd  %xmm0,%xmm1
call   1030 <approximatelyEqual@plt>
test   %eax,%eax
je     117c <cubeRoot+0x5c>
movsd  (%rsp),%xmm2
jmp    11da <cubeRoot+0xba>
movsd  (%rsp),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rsp),%xmm0
movapd %xmm0,%xmm3
divsd  0x8(%rsp),%xmm3
addsd  %xmm1,%xmm3
mulsd  0xe55(%rip),%xmm3
movsd  %xmm3,0x10(%rsp)
movapd %xmm3,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm3,%xmm1
movsd  %xmm2,0x8(%rsp)
mulsd  %xmm2,%xmm1
call   1030 <approximatelyEqual@plt>
movsd  0x10(%rsp),%xmm2
movapd %xmm2,%xmm1
test   %eax,%eax
je     1190 <cubeRoot+0x70>
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"cubeRoot called with negative arguments %g\00"
define double @cubeRoot(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %3
%5 = load double, double* %3
%6 = fcmp oeq double %5, 0.000000e+00
br i1 %6, label %7, label %8
7: ; preds = %1
store double 0.000000e+00, double* %2
br label %37
8: ; preds = %1
%9 = load double, double* %3
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load double, double* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %12)
br label %14
14: ; preds = %11, %8
%15 = load double, double* %3
store double %15, double* %4
br label %16
16: ; preds = %26, %14
%17 = load double, double* %3
%18 = load double, double* %4
%19 = load double, double* %4
%20 = fmul double %18, %19
%21 = load double, double* %4
%22 = fmul double %20, %21
%23 = call i32 @approximatelyEqual(double %17, double %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %35
26: ; preds = %16
%27 = load double, double* %4
%28 = load double, double* %3
%29 = load double, double* %4
%30 = load double, double* %4
%31 = fmul double %29, %30
%32 = fdiv double %28, %31
%33 = fadd double %27, %32
%34 = fdiv double %33, 2.000000e+00
store double %34, double* %4
br label %16
35: ; preds = %16
%36 = load double, double* %4
store double %36, double* %2
br label %37
37: ; preds = %35, %7
%38 = load double, double* %2
ret double %38
}

LLVM IR (-O2):
@.str = [43 x i8] c"cubeRoot called with negative arguments %g\00"
define double @cubeRoot(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = fcmp olt double %0, 0.000000e+00
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %0)
br label %7
7: ; preds = %5, %3
%8 = fmul double %0, %0
%9 = fmul double %8, %0
%10 = tail call i32 @approximatelyEqual(double %0, double %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %7, %12
%13 = phi double [ %18, %12 ], [ %8, %7 ]
%14 = phi double [ %17, %12 ], [ %0, %7 ]
%15 = fdiv double %0, %13
%16 = fadd double %14, %15
%17 = fmul double %16, 5.000000e-01
%18 = fmul double %17, %17
%19 = fmul double %17, %18
%20 = tail call i32 @approximatelyEqual(double %0, double %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %12, label %22
22: ; preds = %12, %7, %1
%23 = phi double [ 0.000000e+00, %1 ], [ %0, %7 ], [ %17, %12 ]
ret double %23
}