#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);
double stub1(double, double);
double stub2(double, double);
double stub3(double, double);
double rootbysecand(double (*f)(double, double), double angle, double x0,
                    double x1, double precision) {
  double fx0, fx1, x2;
  fx0 = (*f)(x0, angle);
  fx1 = (*f)(x1, angle);
  int i = 0;
  for (i = 0; i < 20; i++) {
    if (fabs(fx1) < precision || fabs(x0 - x1) < precision)
      return x1;
    x2 = x1 - fx1 * (x1 - x0) / (fx1 - fx0);
    fx0 = fx1;
    fx1 = (*f)(x2, angle);
    x0 = x1;
    x1 = x2;
  }
  printf("debug in rootbysecand: not found after %d iterations \n", i);
  return -1;
}


x86 assembly (clang, -O0):
<rootbysecand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   *%rax
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x28(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   *%rax
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x14,-0x4c(%rbp)
jge    1234 <rootbysecand+0x124>
movsd  -0x40(%rbp),%xmm1
movaps 0xe92(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     11b5 <rootbysecand+0xa5>
movsd  -0x20(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movaps 0xe6e(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c4 <rootbysecand+0xb4>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1250 <rootbysecand+0x140>
movsd  -0x28(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
subsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  -0x40(%rbp),%xmm2
subsd  -0x38(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   *%rax
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1168 <rootbysecand+0x58>
mov    -0x4c(%rbp),%esi
lea    0xde2(%rip),%rdi
call   1030 <printf@plt>
movsd  0xdb5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rootbysecand>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movsd  %xmm3,0x30(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movaps %xmm0,%xmm2
movsd  %xmm0,0x18(%rsp)
mov    %rdi,%rbx
movaps %xmm1,%xmm0
movaps %xmm2,%xmm1
call   *%rdi
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
call   *%rbx
movsd  0x20(%rsp),%xmm5
movsd  0x10(%rsp),%xmm4
movsd  0x8(%rsp),%xmm2
mov    $0x14,%ebp
movapd 0xe91(%rip),%xmm3
nop
movapd %xmm0,%xmm6
andpd  %xmm3,%xmm0
movsd  0x30(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1210 <rootbysecand+0x100>
movapd %xmm4,%xmm0
subsd  %xmm2,%xmm0
andpd  %xmm3,%xmm0
ucomisd %xmm0,%xmm1
ja     1210 <rootbysecand+0x100>
movapd %xmm2,%xmm3
subsd  %xmm4,%xmm3
mulsd  %xmm6,%xmm3
movapd %xmm6,%xmm1
subsd  %xmm5,%xmm1
divsd  %xmm1,%xmm3
movapd %xmm2,%xmm0
subsd  %xmm3,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm1
movsd  %xmm2,0x8(%rsp)
movapd %xmm6,0x20(%rsp)
call   *%rbx
movapd 0xe24(%rip),%xmm3
movapd 0x20(%rsp),%xmm5
movsd  0x8(%rsp),%xmm4
movsd  0x10(%rsp),%xmm2
add    $0xffffffff,%ebp
jne    1170 <rootbysecand+0x60>
lea    0xe1a(%rip),%rdi
mov    $0x14,%esi
call   1030 <printf@plt>
movsd  0xe00(%rip),%xmm2
movapd %xmm2,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"debug in rootbysecand: not found after %d iterations \0A\00"
define double @rootbysecand(double (double, double)* %0, double %1, double %2, double %3, double %4) {
%6 = alloca double
%7 = alloca double (double, double)*
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
store double (double, double)* %0, double (double, double)** %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
%16 = load double (double, double)*, double (double, double)** %7
%17 = load double, double* %9
%18 = load double, double* %8
%19 = call double %16(double %17, double %18)
store double %19, double* %12
%20 = load double (double, double)*, double (double, double)** %7
%21 = load double, double* %10
%22 = load double, double* %8
%23 = call double %20(double %21, double %22)
store double %23, double* %13
store i32 0, i32* %15
store i32 0, i32* %15
br label %24
24: ; preds = %60, %5
%25 = load i32, i32* %15
%26 = icmp slt i32 %25, 20
br i1 %26, label %27, label %63
27: ; preds = %24
%28 = load double, double* %13
%29 = call double @llvm.fabs.f64(double %28)
%30 = load double, double* %11
%31 = fcmp olt double %29, %30
br i1 %31, label %39, label %32
32: ; preds = %27
%33 = load double, double* %9
%34 = load double, double* %10
%35 = fsub double %33, %34
%36 = call double @llvm.fabs.f64(double %35)
%37 = load double, double* %11
%38 = fcmp olt double %36, %37
br i1 %38, label %39, label %41
39: ; preds = %32, %27
%40 = load double, double* %10
store double %40, double* %6
br label %66
41: ; preds = %32
%42 = load double, double* %10
%43 = load double, double* %13
%44 = load double, double* %10
%45 = load double, double* %9
%46 = fsub double %44, %45
%47 = fmul double %43, %46
%48 = load double, double* %13
%49 = load double, double* %12
%50 = fsub double %48, %49
%51 = fdiv double %47, %50
%52 = fsub double %42, %51
store double %52, double* %14
%53 = load double, double* %13
store double %53, double* %12
%54 = load double (double, double)*, double (double, double)** %7
%55 = load double, double* %14
%56 = load double, double* %8
%57 = call double %54(double %55, double %56)
store double %57, double* %13
%58 = load double, double* %10
store double %58, double* %9
%59 = load double, double* %14
store double %59, double* %10
br label %60
60: ; preds = %41
%61 = load i32, i32* %15
%62 = add nsw i32 %61, 1
store i32 %62, i32* %15
br label %24
63: ; preds = %24
%64 = load i32, i32* %15
%65 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %64)
store double -1.000000e+00, double* %6
br label %66
66: ; preds = %63, %39
%67 = load double, double* %6
ret double %67
}

LLVM IR (-O2):
@.str = [55 x i8] c"debug in rootbysecand: not found after %d iterations \0A\00"
define double @rootbysecand(double (double, double)* nocapture %0, double %1, double %2, double %3, double %4) {
%6 = tail call double %0(double %2, double %1)
%7 = tail call double %0(double %3, double %1)
br label %8
8: ; preds = %5, %20
%9 = phi i32 [ 0, %5 ], [ %27, %20 ]
%10 = phi double [ %7, %5 ], [ %26, %20 ]
%11 = phi double [ %6, %5 ], [ %10, %20 ]
%12 = phi double [ %2, %5 ], [ %13, %20 ]
%13 = phi double [ %3, %5 ], [ %25, %20 ]
%14 = tail call double @llvm.fabs.f64(double %10)
%15 = fcmp olt double %14, %4
br i1 %15, label %31, label %16
16: ; preds = %8
%17 = fsub double %12, %13
%18 = tail call double @llvm.fabs.f64(double %17)
%19 = fcmp olt double %18, %4
br i1 %19, label %31, label %20
20: ; preds = %16
%21 = fsub double %13, %12
%22 = fmul double %21, %10
%23 = fsub double %10, %11
%24 = fdiv double %22, %23
%25 = fsub double %13, %24
%26 = tail call double %0(double %25, double %1)
%27 = add nuw nsw i32 %9, 1
%28 = icmp eq i32 %27, 20
br i1 %28, label %29, label %8
29: ; preds = %20
%30 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 20)
br label %31
31: ; preds = %8, %16, %29
%32 = phi double [ -1.000000e+00, %29 ], [ %13, %16 ], [ %13, %8 ]
ret double %32
}