#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 */
scalar_t__ gradroot(double *, int, double (*)(double *, double *), double, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void main() {
  double eps = 0.000001;
  int n = 3, max = 600, i;
  double *x0;
  double f(double *, double *);
  x0 = (double *)malloc(n * sizeof(double));
  x0[0] = 1;
  x0[1] = -3;
  x0[2] = 5;
  if (gradroot(x0, n, f, eps, max)) {
    for (i = 0; i < n; i++)
      printf("x[%d]=%1.7f\n", i, x0[i]);
  } else
    printf("failed!\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  0xed8(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
movl   $0x258,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsd  0xe9e(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x20(%rbp),%rax
movsd  0xe6d(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%ecx
mov    0x2e32(%rip),%rdx
call   1030 <gradroot@plt>
cmp    $0x0,%rax
je     1201 <main+0xd1>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fc <main+0xcc>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe39(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c4 <main+0x94>
jmp    120f <main+0xdf>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movaps 0xea8(%rip),%xmm0
movups %xmm0,(%rax)
movabs $0x4014000000000000,%rax
mov    %rax,0x10(%rbx)
mov    0x2e70(%rip),%rdx
movsd  0xe98(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x258,%ecx
call   1040 <gradroot@plt>
test   %rax,%rax
je     11d5 <main+0x95>
movsd  (%rbx),%xmm0
lea    0xe7e(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x10(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>
lea    0xe49(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"x[%d]=%1.7f\0A\00"
@.str.1 = [9 x i8] c"failed!\0A\00"
define void @main() {
%1 = alloca double
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double*
store double 0x3EB0C6F7A0B5ED8D, double* %1
store i32 3, i32* %2
store i32 600, i32* %3
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 8
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to double*
store double* %11, double** %5
%12 = load double*, double** %5
%13 = getelementptr inbounds double, double* %12, i64 0
store double 1.000000e+00, double* %13
%14 = load double*, double** %5
%15 = getelementptr inbounds double, double* %14, i64 1
store double -3.000000e+00, double* %15
%16 = load double*, double** %5
%17 = getelementptr inbounds double, double* %16, i64 2
store double 5.000000e+00, double* %17
%18 = load double*, double** %5
%19 = load i32, i32* %2
%20 = load double, double* %1
%21 = load i32, i32* %3
%22 = call i64 @gradroot(double* %18, i32 %19, double (double*, double*)* @f, double %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %0
store i32 0, i32* %4
br label %25
25: ; preds = %37, %24
%26 = load i32, i32* %4
%27 = load i32, i32* %2
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %40
29: ; preds = %25
%30 = load i32, i32* %4
%31 = load double*, double** %5
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %30, double %35)
br label %37
37: ; preds = %29
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %25
40: ; preds = %25
br label %43
41: ; preds = %0
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %40
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"x[%d]=%1.7f\0A\00"
@str = [8 x i8] c"failed!\00"
define void @main() {
%1 = tail call i64 @malloc(i32 24)
%2 = inttoptr i64 %1 to double*
%3 = inttoptr i64 %1 to <2 x double>*
store <2 x double> <double 1.000000e+00, double -3.000000e+00>, <2 x double>* %3
%4 = getelementptr inbounds double, double* %2, i64 2
store double 5.000000e+00, double* %4
%5 = tail call i64 @gradroot(double* %2, i32 3, double (double*, double*)* @f, double 0x3EB0C6F7A0B5ED8D, i32 600)
%6 = icmp eq i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = getelementptr inbounds double, double* %2, i64 1
%9 = load double, double* %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 0, double %9)
%11 = load double, double* %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1, double %11)
%13 = load double, double* %4
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 2, double %13)
br label %17
15: ; preds = %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %7, %15
ret void
}