#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 INFINITY;
double fabs(double);
double iter_secant(int, double, double, double, double);
double legendre(int, double);
int secant(int i, double *px0, double *px1, double prec, double nmax) {
  int count;
  double dif;
  double f1, f0, temp, x1, x0;
  dif = INFINITY;
  x0 = *px0;
  x1 = *px1;
  f0 = legendre(i, x0);
  f1 = legendre(i, x1);
  count = 0;
  while (fabs(f1) > prec && dif > prec) {
    temp = x1;
    x1 = iter_secant(i, x1, x0, f1, f0);
    x0 = temp;
    f0 = f1;
    f1 = legendre(i, x1);
    dif = fabs(x1 - x0);
    count++;
    if (count >= nmax)
      return 1;
  }
  (*px0) = x0;
  (*px1) = x1;
  return 0;
}


x86 assembly (clang, -O0):
<secant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    0x2ea4(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%edi
movsd  -0x60(%rbp),%xmm0
call   1040 <legendre@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%edi
movsd  -0x58(%rbp),%xmm0
call   1040 <legendre@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
movsd  -0x40(%rbp),%xmm0
movaps 0xe62(%rip),%xmm1
pand   %xmm1,%xmm0
xor    %eax,%eax
ucomisd -0x20(%rbp),%xmm0
mov    %al,-0x61(%rbp)
jbe    11c2 <secant+0xa2>
movsd  -0x38(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
seta   %al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    11d2 <secant+0xb2>
jmp    1267 <secant+0x147>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%edi
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm3
call   1030 <iter_secant@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%edi
movsd  -0x58(%rbp),%xmm0
call   1040 <legendre@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
movaps 0xdcc(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     1262 <secant+0x142>
movl   $0x1,-0x4(%rbp)
jmp    1288 <secant+0x168>
jmp    1192 <secant+0x72>
movsd  -0x60(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x58(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<secant>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x30(%rsp)
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2ea3(%rip),%rax
movsd  (%rax),%xmm0
movaps %xmm0,0x10(%rsp)
movsd  (%rsi),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rdx),%xmm1
movsd  %xmm1,(%rsp)
call   1040 <legendre@plt>
movsd  %xmm0,0x20(%rsp)
mov    %ebp,%edi
movsd  (%rsp),%xmm0
call   1040 <legendre@plt>
movsd  0x20(%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm4
movapd 0x10(%rsp),%xmm6
mov    $0x1,%ebx
movapd 0xe64(%rip),%xmm5
nopl   0x0(%rax)
movapd %xmm0,%xmm2
andpd  %xmm5,%xmm0
movsd  0x30(%rsp),%xmm5
ucomisd %xmm5,%xmm0
jbe    1222 <secant+0x102>
movapd %xmm5,%xmm0
ucomisd %xmm5,%xmm6
jbe    1222 <secant+0x102>
mov    %ebp,%edi
movapd %xmm4,%xmm0
movsd  %xmm4,0x8(%rsp)
movapd %xmm2,0x10(%rsp)
call   1030 <iter_secant@plt>
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
call   1040 <legendre@plt>
movsd  (%rsp),%xmm4
movapd 0xe12(%rip),%xmm5
movapd %xmm4,%xmm6
movsd  0x8(%rsp),%xmm2
subsd  %xmm2,%xmm6
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
andpd  %xmm5,%xmm6
add    $0x1,%ebx
ucomisd 0x28(%rsp),%xmm1
movaps 0x10(%rsp),%xmm3
movapd %xmm2,%xmm1
jb     11a0 <secant+0x80>
mov    $0x1,%eax
jmp    122e <secant+0x10e>
movsd  %xmm1,(%r15)
movsd  %xmm4,(%r14)
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INFINITY = global double 0.000000e+00
define i32 @secant(i32 %0, double* %1, double* %2, double %3, double %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
store i32 %0, i32* %7
store double* %1, double** %8
store double* %2, double** %9
store double %3, double* %10
store double %4, double* %11
%19 = load double, double* @INFINITY
store double %19, double* %13
%20 = load double*, double** %8
%21 = load double, double* %20
store double %21, double* %18
%22 = load double*, double** %9
%23 = load double, double* %22
store double %23, double* %17
%24 = load i32, i32* %7
%25 = load double, double* %18
%26 = call double @legendre(i32 %24, double %25)
store double %26, double* %15
%27 = load i32, i32* %7
%28 = load double, double* %17
%29 = call double @legendre(i32 %27, double %28)
store double %29, double* %14
store i32 0, i32* %12
br label %30
30: ; preds = %65, %5
%31 = load double, double* %14
%32 = call double @llvm.fabs.f64(double %31)
%33 = load double, double* %10
%34 = fcmp ogt double %32, %33
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load double, double* %13
%37 = load double, double* %10
%38 = fcmp ogt double %36, %37
br label %39
39: ; preds = %35, %30
%40 = phi i1 [ false, %30 ], [ %38, %35 ]
br i1 %40, label %41, label %66
41: ; preds = %39
%42 = load double, double* %17
store double %42, double* %16
%43 = load i32, i32* %7
%44 = load double, double* %17
%45 = load double, double* %18
%46 = load double, double* %14
%47 = load double, double* %15
%48 = call double @iter_secant(i32 %43, double %44, double %45, double %46, double %47)
store double %48, double* %17
%49 = load double, double* %16
store double %49, double* %18
%50 = load double, double* %14
store double %50, double* %15
%51 = load i32, i32* %7
%52 = load double, double* %17
%53 = call double @legendre(i32 %51, double %52)
store double %53, double* %14
%54 = load double, double* %17
%55 = load double, double* %18
%56 = fsub double %54, %55
%57 = call double @llvm.fabs.f64(double %56)
store double %57, double* %13
%58 = load i32, i32* %12
%59 = add nsw i32 %58, 1
store i32 %59, i32* %12
%60 = load i32, i32* %12
%61 = sitofp i32 %60 to double
%62 = load double, double* %11
%63 = fcmp oge double %61, %62
br i1 %63, label %64, label %65
64: ; preds = %41
store i32 1, i32* %6
br label %71
65: ; preds = %41
br label %30
66: ; preds = %39
%67 = load double, double* %18
%68 = load double*, double** %8
store double %67, double* %68
%69 = load double, double* %17
%70 = load double*, double** %9
store double %69, double* %70
store i32 0, i32* %6
br label %71
71: ; preds = %66, %64
%72 = load i32, i32* %6
ret i32 %72
}

LLVM IR (-O2):
@INFINITY = global double 0.000000e+00
define i32 @secant(i32 %0, double* nocapture %1, double* nocapture %2, double %3, double %4) {
%6 = load double, double* @INFINITY
%7 = load double, double* %1
%8 = load double, double* %2
%9 = tail call double @legendre(i32 %0, double %7)
%10 = tail call double @legendre(i32 %0, double %8)
br label %11
11: ; preds = %22, %5
%12 = phi i32 [ 0, %5 ], [ %27, %22 ]
%13 = phi double [ %6, %5 ], [ %26, %22 ]
%14 = phi double [ %10, %5 ], [ %24, %22 ]
%15 = phi double [ %9, %5 ], [ %14, %22 ]
%16 = phi double [ %8, %5 ], [ %23, %22 ]
%17 = phi double [ %7, %5 ], [ %16, %22 ]
%18 = tail call double @llvm.fabs.f64(double %14)
%19 = fcmp ogt double %18, %3
%20 = fcmp ogt double %13, %3
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %22, label %30
22: ; preds = %11
%23 = tail call double @iter_secant(i32 %0, double %16, double %17, double %14, double %15)
%24 = tail call double @legendre(i32 %0, double %23)
%25 = fsub double %23, %16
%26 = tail call double @llvm.fabs.f64(double %25)
%27 = add nuw nsw i32 %12, 1
%28 = sitofp i32 %27 to double
%29 = fcmp ult double %28, %4
br i1 %29, label %11, label %31
30: ; preds = %11
store double %17, double* %1
store double %16, double* %2
br label %31
31: ; preds = %22, %30
%32 = phi i32 [ 0, %30 ], [ 1, %22 ]
ret i32 %32
}