#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 derivativeFunc(double, double, double);
double fabs(double);
double func(double, double, double, double);
double newtonMethod(double x, double v2, double Psi, double phi0) {
  double ratio = func(x, v2, Psi, phi0) / derivativeFunc(x, v2, Psi);
  while (fabs(ratio) > 0.0000001) {
    ratio = func(x, v2, Psi, phi0) / derivativeFunc(x, v2, Psi);
    x = x - ratio;
  }
  return x;
}


x86 assembly (clang, -O0):
<newtonMethod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
call   1040 <func@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1030 <derivativeFunc@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movaps 0xe85(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe69(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f8 <newtonMethod+0xd8>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
call   1040 <func@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1030 <derivativeFunc@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    117f <newtonMethod+0x5f>
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newtonMethod>:
sub    $0x38,%rsp
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  %xmm3,0x30(%rsp)
call   1040 <func@plt>
movaps %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
call   1030 <derivativeFunc@plt>
movapd 0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
andpd  0xe91(%rip),%xmm1
ucomisd 0xe99(%rip),%xmm1
jbe    11ea <newtonMethod+0xca>
movsd  0x8(%rsp),%xmm0
nop
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
movsd  0x30(%rsp),%xmm3
call   1040 <func@plt>
movaps %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
call   1030 <derivativeFunc@plt>
movapd 0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
andpd  0xe25(%rip),%xmm1
ucomisd 0xe2d(%rip),%xmm1
ja     1180 <newtonMethod+0x60>
add    $0x38,%rsp
ret
movsd  0x8(%rsp),%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @newtonMethod(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%10 = load double, double* %5
%11 = load double, double* %6
%12 = load double, double* %7
%13 = load double, double* %8
%14 = call double @func(double %10, double %11, double %12, double %13)
%15 = load double, double* %5
%16 = load double, double* %6
%17 = load double, double* %7
%18 = call double @derivativeFunc(double %15, double %16, double %17)
%19 = fdiv double %14, %18
store double %19, double* %9
br label %20
20: ; preds = %24, %4
%21 = load double, double* %9
%22 = call double @llvm.fabs.f64(double %21)
%23 = fcmp ogt double %22, 0x3E7AD7F29ABCAF48
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load double, double* %5
%26 = load double, double* %6
%27 = load double, double* %7
%28 = load double, double* %8
%29 = call double @func(double %25, double %26, double %27, double %28)
%30 = load double, double* %5
%31 = load double, double* %6
%32 = load double, double* %7
%33 = call double @derivativeFunc(double %30, double %31, double %32)
%34 = fdiv double %29, %33
store double %34, double* %9
%35 = load double, double* %5
%36 = load double, double* %9
%37 = fsub double %35, %36
store double %37, double* %5
br label %20
38: ; preds = %20
%39 = load double, double* %5
ret double %39
}

LLVM IR (-O2):
define double @newtonMethod(double %0, double %1, double %2, double %3) {
%5 = tail call double @func(double %0, double %1, double %2, double %3)
%6 = tail call double @derivativeFunc(double %0, double %1, double %2)
%7 = fdiv double %5, %6
%8 = tail call double @llvm.fabs.f64(double %7)
%9 = fcmp ogt double %8, 0x3E7AD7F29ABCAF48
br i1 %9, label %10, label %18
10: ; preds = %4, %10
%11 = phi double [ %15, %10 ], [ %0, %4 ]
%12 = tail call double @func(double %11, double %1, double %2, double %3)
%13 = tail call double @derivativeFunc(double %11, double %1, double %2)
%14 = fdiv double %12, %13
%15 = fsub double %11, %14
%16 = tail call double @llvm.fabs.f64(double %14)
%17 = fcmp ogt double %16, 0x3E7AD7F29ABCAF48
br i1 %17, label %10, label %18
18: ; preds = %10, %4
%19 = phi double [ %0, %4 ], [ %15, %10 ]
ret double %19
}