#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 root(double (*f)(double x), double (*g)(double x), double *x, int *n,
         double delta) {
  int satisfied, i;
  i = 0;
  satisfied = 0;
  while (!satisfied && i + 1 < *n) {
    x[i + 1] = x[i] - (f(x[i]) / g(x[i]));
    if (fabs(x[i + 1] - x[i]) < delta)
      satisfied = 1;
    i++;
  }
  if (i == 0)
    *n = 1;
  else
    *n = i + 1;
  if (satisfied)
    return 0;
  else
    return -1;
}


x86 assembly (clang, -O0):
<root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x34(%rbp)
mov    %al,-0x39(%rbp)
jne    114c <root+0x4c>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    115c <root+0x5c>
jmp    120e <root+0x10e>
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x38(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x38(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
call   *%rax
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
movaps 0xe1a(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1200 <root+0x100>
movl   $0x1,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    112b <root+0x2b>
cmpl   $0x0,-0x38(%rbp)
jne    1227 <root+0x127>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
jmp    1233 <root+0x133>
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x34(%rbp)
je     1249 <root+0x149>
movl   $0x0,-0x4(%rbp)
jmp    1250 <root+0x150>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<root>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm0,0x10(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%rbx),%rbp
mov    0x8(%rsp),%rax
movslq (%rax),%r14
cmp    %r14,%rbp
jge    119b <root+0x9b>
movsd  0x0(%r13,%rbx,8),%xmm0
movaps %xmm0,0x20(%rsp)
call   *%r12
movsd  %xmm0,0x18(%rsp)
movsd  0x0(%r13,%rbx,8),%xmm0
call   *%r15
movsd  0x18(%rsp),%xmm2
divsd  %xmm0,%xmm2
movapd 0x20(%rsp),%xmm1
subsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%r13,%rbx,8)
subsd  0x0(%r13,%rbx,8),%xmm1
andpd  0xe76(%rip),%xmm1
movsd  0x10(%rsp),%xmm0
ucomisd %xmm1,%xmm0
mov    %rbp,%rbx
jbe    1130 <root+0x30>
mov    %ebp,%ebx
xor    %eax,%eax
cmp    %r14,%rbp
setge  %al
add    $0x1,%ebx
mov    0x8(%rsp),%rcx
mov    %ebx,(%rcx)
neg    %eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @root(double (double)* %0, double (double)* %1, double* %2, i32* %3, double %4) {
%6 = alloca i32
%7 = alloca double (double)*
%8 = alloca double (double)*
%9 = alloca double*
%10 = alloca i32*
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
store double (double)* %0, double (double)** %7
store double (double)* %1, double (double)** %8
store double* %2, double** %9
store i32* %3, i32** %10
store double %4, double* %11
store i32 0, i32* %13
store i32 0, i32* %12
br label %14
14: ; preds = %68, %5
%15 = load i32, i32* %12
%16 = icmp ne i32 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = load i32, i32* %13
%19 = add nsw i32 %18, 1
%20 = load i32*, i32** %10
%21 = load i32, i32* %20
%22 = icmp slt i32 %19, %21
br label %23
23: ; preds = %17, %14
%24 = phi i1 [ false, %14 ], [ %22, %17 ]
br i1 %24, label %25, label %71
25: ; preds = %23
%26 = load double*, double** %9
%27 = load i32, i32* %13
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double (double)*, double (double)** %7
%32 = load double*, double** %9
%33 = load i32, i32* %13
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = call double %31(double %36)
%38 = load double (double)*, double (double)** %8
%39 = load double*, double** %9
%40 = load i32, i32* %13
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = call double %38(double %43)
%45 = fdiv double %37, %44
%46 = fsub double %30, %45
%47 = load double*, double** %9
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %47, i64 %50
store double %46, double* %51
%52 = load double*, double** %9
%53 = load i32, i32* %13
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %52, i64 %55
%57 = load double, double* %56
%58 = load double*, double** %9
%59 = load i32, i32* %13
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = fsub double %57, %62
%64 = call double @llvm.fabs.f64(double %63)
%65 = load double, double* %11
%66 = fcmp olt double %64, %65
br i1 %66, label %67, label %68
67: ; preds = %25
store i32 1, i32* %12
br label %68
68: ; preds = %67, %25
%69 = load i32, i32* %13
%70 = add nsw i32 %69, 1
store i32 %70, i32* %13
br label %14
71: ; preds = %23
%72 = load i32, i32* %13
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %71
%75 = load i32*, i32** %10
store i32 1, i32* %75
br label %80
76: ; preds = %71
%77 = load i32, i32* %13
%78 = add nsw i32 %77, 1
%79 = load i32*, i32** %10
store i32 %78, i32* %79
br label %80
80: ; preds = %76, %74
%81 = load i32, i32* %12
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %80
store i32 0, i32* %6
br label %85
84: ; preds = %80
store i32 -1, i32* %6
br label %85
85: ; preds = %84, %83
%86 = load i32, i32* %6
ret i32 %86
}

LLVM IR (-O2):
define i32 @root(double (double)* nocapture %0, double (double)* nocapture %1, double* nocapture %2, i32* nocapture %3, double %4) {
br label %6
6: ; preds = %5, %14
%7 = phi i64 [ 0, %5 ], [ %9, %14 ]
%8 = phi i32 [ 0, %5 ], [ %10, %14 ]
%9 = add nuw nsw i64 %7, 1
%10 = add nuw nsw i32 %8, 1
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %9, %12
br i1 %13, label %14, label %27
14: ; preds = %6
%15 = getelementptr inbounds double, double* %2, i64 %7
%16 = load double, double* %15
%17 = tail call double %0(double %16)
%18 = load double, double* %15
%19 = tail call double %1(double %18)
%20 = fdiv double %17, %19
%21 = fsub double %16, %20
%22 = getelementptr inbounds double, double* %2, i64 %9
store double %21, double* %22
%23 = load double, double* %15
%24 = fsub double %21, %23
%25 = tail call double @llvm.fabs.f64(double %24)
%26 = fcmp uge double %25, %4
br i1 %26, label %6, label %29
27: ; preds = %6
%28 = trunc i64 %7 to i32
br label %29
29: ; preds = %14, %27
%30 = phi i32 [ %28, %27 ], [ %10, %14 ]
%31 = xor i1 %13, true
%32 = add nuw nsw i32 %30, 1
store i32 %32, i32* %3
%33 = sext i1 %31 to i32
ret i32 %33
}