#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 */
int /*<<< orphan*/ exit(int);
double macheps();
int newton_min_func(double (*)(double *, int),
                    void (*)(double *, int, double *), double *, int, double *,
                    double, int, int *, double, double, double, double *);
int newton_min_trust(double (*)(double *, int),
                     void (*)(double *, int, double *), double *, int, double *,
                     double, double, int, int, int *, double, double, double,
                     double *);
double pow(double, double);
int /*<<< orphan*/ printf(char *);
int fminqn(double (*funcpt)(double *, int),
           void (*funcgrad)(double *, int, double *), int N, double *xi,
           double delta, int method, double *dx, double fsval, double *xf) {
  int retval;
  int MAXITER, niter;
  double eps, gtol, stol;
  MAXITER = 200 * N;
  niter = 0;
  eps = macheps();
  if (method == 1) {
    gtol = pow(eps, 1.0 / 3.0);
    stol = gtol * gtol;
    if (MAXITER < 1000) {
      MAXITER = 1000;
    }
    retval = newton_min_func(funcpt, funcgrad, xi, N, dx, fsval, MAXITER,
                             &niter, eps, gtol, stol, xf);
  } else if (method == 2) {
    gtol = pow(eps, 1.0 / 3.0);
    stol = gtol * gtol;
    if (MAXITER < 1000) {
      MAXITER = 1000;
    }
    retval = newton_min_trust(funcpt, funcgrad, xi, N, dx, fsval, delta, 0,
                              MAXITER, &niter, eps, gtol, stol, xf);
  } else if (method == 3) {
    gtol = pow(eps, 1.0 / 3.0);
    stol = gtol * gtol;
    if (MAXITER < 1000) {
      MAXITER = 1000;
    }
    retval = newton_min_trust(funcpt, funcgrad, xi, N, dx, fsval, delta, 1,
                              MAXITER, &niter, eps, gtol, stol, xf);
  } else {
    printf("Method Value should be one of 1,2 or 3. See Documentation. \n");
    exit(1);
  }
  return retval;
}


x86 assembly (clang, -O0):
<fminqn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9,-0x38(%rbp)
movsd  %xmm1,-0x40(%rbp)
imul   $0xc8,-0x14(%rbp),%eax
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    $0x0,%al
call   1060 <macheps@plt>
movsd  %xmm0,-0x58(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    123a <fminqn+0xda>
movsd  -0x58(%rbp),%xmm0
movsd  0xe3c(%rip),%xmm1
call   1070 <pow@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
cmpl   $0x3e8,-0x48(%rbp)
jge    11f1 <fminqn+0x91>
movl   $0x3e8,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x38(%rbp),%r8
movsd  -0x40(%rbp),%xmm0
mov    -0x48(%rbp),%r9d
movsd  -0x58(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm3
mov    0x10(%rbp),%rax
lea    -0x4c(%rbp),%r10
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <newton_min_func@plt>
mov    %eax,-0x44(%rbp)
jmp    1391 <fminqn+0x231>
cmpl   $0x2,-0x2c(%rbp)
jne    12d4 <fminqn+0x174>
movsd  -0x58(%rbp),%xmm0
movsd  0xdaf(%rip),%xmm1
call   1070 <pow@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
cmpl   $0x3e8,-0x48(%rbp)
jge    127e <fminqn+0x11e>
movl   $0x3e8,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x38(%rbp),%r8
movsd  -0x40(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x48(%rbp),%r11d
movsd  -0x58(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm3
movsd  -0x68(%rbp),%xmm4
mov    0x10(%rbp),%rax
xor    %r9d,%r9d
lea    -0x4c(%rbp),%r10
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <newton_min_trust@plt>
mov    %eax,-0x44(%rbp)
jmp    138c <fminqn+0x22c>
cmpl   $0x3,-0x2c(%rbp)
jne    1371 <fminqn+0x211>
movsd  -0x58(%rbp),%xmm0
movsd  0xd15(%rip),%xmm1
call   1070 <pow@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
cmpl   $0x3e8,-0x48(%rbp)
jge    1318 <fminqn+0x1b8>
movl   $0x3e8,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x38(%rbp),%r8
movsd  -0x40(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x48(%rbp),%r11d
movsd  -0x58(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm3
movsd  -0x68(%rbp),%xmm4
mov    0x10(%rbp),%rax
mov    $0x1,%r9d
lea    -0x4c(%rbp),%r10
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <newton_min_trust@plt>
mov    %eax,-0x44(%rbp)
jmp    1387 <fminqn+0x227>
lea    0xc90(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    138c <fminqn+0x22c>
jmp    1391 <fminqn+0x231>
mov    -0x44(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fminqn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm1,0x18(%rsp)
mov    %r9,0x10(%rsp)
mov    %r8d,%ebx
movsd  %xmm0,0x20(%rsp)
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%r13
imul   $0xc8,%edx,%r14d
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
call   1060 <macheps@plt>
cmp    $0x3,%ebx
movsd  %xmm0,0x8(%rsp)
je     121e <fminqn+0xbe>
cmp    $0x2,%ebx
je     1274 <fminqn+0x114>
cmp    $0x1,%ebx
jne    12e9 <fminqn+0x189>
movsd  0xe38(%rip),%xmm1
call   1070 <pow@plt>
movapd %xmm0,%xmm2
movapd %xmm0,%xmm3
mulsd  %xmm0,%xmm3
cmp    $0x3e9,%r14d
mov    $0x3e8,%r9d
cmovge %r14d,%r9d
lea    0x4(%rsp),%rax
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
mov    0x10(%rsp),%r8
movsd  0x18(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
push   0x60(%rsp)
push   %rax
call   1050 <newton_min_func@plt>
add    $0x10,%rsp
jmp    12da <fminqn+0x17a>
movsd  0xdda(%rip),%xmm1
call   1070 <pow@plt>
movapd %xmm0,%xmm3
movapd %xmm0,%xmm4
mulsd  %xmm0,%xmm4
cmp    $0x3e9,%r14d
mov    $0x3e8,%eax
cmovge %r14d,%eax
sub    $0x8,%rsp
lea    0xc(%rsp),%rbx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
mov    0x18(%rsp),%r8
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
mov    $0x1,%r9d
jmp    12c5 <fminqn+0x165>
movsd  0xd84(%rip),%xmm1
call   1070 <pow@plt>
movapd %xmm0,%xmm3
movapd %xmm0,%xmm4
mulsd  %xmm0,%xmm4
cmp    $0x3e9,%r14d
mov    $0x3e8,%eax
cmovge %r14d,%eax
sub    $0x8,%rsp
lea    0xc(%rsp),%rbx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
mov    0x18(%rsp),%r8
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
xor    %r9d,%r9d
movsd  0x10(%rsp),%xmm2
push   0x68(%rsp)
push   %rbx
push   %rax
call   1040 <newton_min_trust@plt>
add    $0x20,%rsp
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd18(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [61 x i8] c"Method Value should be one of 1,2 or 3. See Documentation. \0A\00"
define i32 @fminqn(double (double*, i32)* %0, void (double*, i32, double*)* %1, i32 %2, double* %3, double %4, i32 %5, double* %6, double %7, double* %8) {
%10 = alloca double (double*, i32)*
%11 = alloca void (double*, i32, double*)*
%12 = alloca i32
%13 = alloca double*
%14 = alloca double
%15 = alloca i32
%16 = alloca double*
%17 = alloca double
%18 = alloca double*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca double
%23 = alloca double
%24 = alloca double
store double (double*, i32)* %0, double (double*, i32)** %10
store void (double*, i32, double*)* %1, void (double*, i32, double*)** %11
store i32 %2, i32* %12
store double* %3, double** %13
store double %4, double* %14
store i32 %5, i32* %15
store double* %6, double** %16
store double %7, double* %17
store double* %8, double** %18
%25 = load i32, i32* %12
%26 = mul nsw i32 200, %25
store i32 %26, i32* %20
store i32 0, i32* %21
%27 = call double (...) @macheps()
store double %27, double* %22
%28 = load i32, i32* %15
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %52
30: ; preds = %9
%31 = load double, double* %22
%32 = call double @pow(double %31, double 0x3FD5555555555555)
store double %32, double* %23
%33 = load double, double* %23
%34 = load double, double* %23
%35 = fmul double %33, %34
store double %35, double* %24
%36 = load i32, i32* %20
%37 = icmp slt i32 %36, 1000
br i1 %37, label %38, label %39
38: ; preds = %30
store i32 1000, i32* %20
br label %39
39: ; preds = %38, %30
%40 = load double (double*, i32)*, double (double*, i32)** %10
%41 = load void (double*, i32, double*)*, void (double*, i32, double*)** %11
%42 = load double*, double** %13
%43 = load i32, i32* %12
%44 = load double*, double** %16
%45 = load double, double* %17
%46 = load i32, i32* %20
%47 = load double, double* %22
%48 = load double, double* %23
%49 = load double, double* %24
%50 = load double*, double** %18
%51 = call i32 @newton_min_func(double (double*, i32)* %40, void (double*, i32, double*)* %41, double* %42, i32 %43, double* %44, double %45, i32 %46, i32* %21, double %47, double %48, double %49, double* %50)
store i32 %51, i32* %19
br label %109
52: ; preds = %9
%53 = load i32, i32* %15
%54 = icmp eq i32 %53, 2
br i1 %54, label %55, label %78
55: ; preds = %52
%56 = load double, double* %22
%57 = call double @pow(double %56, double 0x3FD5555555555555)
store double %57, double* %23
%58 = load double, double* %23
%59 = load double, double* %23
%60 = fmul double %58, %59
store double %60, double* %24
%61 = load i32, i32* %20
%62 = icmp slt i32 %61, 1000
br i1 %62, label %63, label %64
63: ; preds = %55
store i32 1000, i32* %20
br label %64
64: ; preds = %63, %55
%65 = load double (double*, i32)*, double (double*, i32)** %10
%66 = load void (double*, i32, double*)*, void (double*, i32, double*)** %11
%67 = load double*, double** %13
%68 = load i32, i32* %12
%69 = load double*, double** %16
%70 = load double, double* %17
%71 = load double, double* %14
%72 = load i32, i32* %20
%73 = load double, double* %22
%74 = load double, double* %23
%75 = load double, double* %24
%76 = load double*, double** %18
%77 = call i32 @newton_min_trust(double (double*, i32)* %65, void (double*, i32, double*)* %66, double* %67, i32 %68, double* %69, double %70, double %71, i32 0, i32 %72, i32* %21, double %73, double %74, double %75, double* %76)
store i32 %77, i32* %19
br label %108
78: ; preds = %52
%79 = load i32, i32* %15
%80 = icmp eq i32 %79, 3
br i1 %80, label %81, label %104
81: ; preds = %78
%82 = load double, double* %22
%83 = call double @pow(double %82, double 0x3FD5555555555555)
store double %83, double* %23
%84 = load double, double* %23
%85 = load double, double* %23
%86 = fmul double %84, %85
store double %86, double* %24
%87 = load i32, i32* %20
%88 = icmp slt i32 %87, 1000
br i1 %88, label %89, label %90
89: ; preds = %81
store i32 1000, i32* %20
br label %90
90: ; preds = %89, %81
%91 = load double (double*, i32)*, double (double*, i32)** %10
%92 = load void (double*, i32, double*)*, void (double*, i32, double*)** %11
%93 = load double*, double** %13
%94 = load i32, i32* %12
%95 = load double*, double** %16
%96 = load double, double* %17
%97 = load double, double* %14
%98 = load i32, i32* %20
%99 = load double, double* %22
%100 = load double, double* %23
%101 = load double, double* %24
%102 = load double*, double** %18
%103 = call i32 @newton_min_trust(double (double*, i32)* %91, void (double*, i32, double*)* %92, double* %93, i32 %94, double* %95, double %96, double %97, i32 1, i32 %98, i32* %21, double %99, double %100, double %101, double* %102)
store i32 %103, i32* %19
br label %107
104: ; preds = %78
%105 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %90
br label %108
108: ; preds = %107, %64
br label %109
109: ; preds = %108, %39
%110 = load i32, i32* %19
ret i32 %110
}

LLVM IR (-O2):
@str = [60 x i8] c"Method Value should be one of 1,2 or 3. See Documentation. \00"
define i32 @fminqn(double (double*, i32)* %0, void (double*, i32, double*)* %1, i32 %2, double* %3, double %4, i32 %5, double* %6, double %7, double* %8) {
%10 = alloca i32
%11 = bitcast i32* %10 to i8*
%12 = mul nsw i32 %2, 200
store i32 0, i32* %10
%13 = tail call double (...) @macheps()
switch i32 %5, label %32 [
i32 1, label %14
i32 2, label %20
i32 3, label %26
]
14: ; preds = %9
%15 = tail call double @pow(double %13, double 0x3FD5555555555555)
%16 = fmul double %15, %15
%17 = icmp sgt i32 %12, 1000
%18 = select i1 %17, i32 %12, i32 1000
%19 = call i32 @newton_min_func(double (double*, i32)* %0, void (double*, i32, double*)* %1, double* %3, i32 %2, double* %6, double %7, i32 %18, i32* %10, double %13, double %15, double %16, double* %8)
br label %35
20: ; preds = %9
%21 = tail call double @pow(double %13, double 0x3FD5555555555555)
%22 = fmul double %21, %21
%23 = icmp sgt i32 %12, 1000
%24 = select i1 %23, i32 %12, i32 1000
%25 = call i32 @newton_min_trust(double (double*, i32)* %0, void (double*, i32, double*)* %1, double* %3, i32 %2, double* %6, double %7, double %4, i32 0, i32 %24, i32* %10, double %13, double %21, double %22, double* %8)
br label %35
26: ; preds = %9
%27 = tail call double @pow(double %13, double 0x3FD5555555555555)
%28 = fmul double %27, %27
%29 = icmp sgt i32 %12, 1000
%30 = select i1 %29, i32 %12, i32 1000
%31 = call i32 @newton_min_trust(double (double*, i32)* %0, void (double*, i32, double*)* %1, double* %3, i32 %2, double* %6, double %7, double %4, i32 1, i32 %30, i32* %10, double %13, double %27, double %28, double* %8)
br label %35
32: ; preds = %9
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %20, %26, %14
%36 = phi i32 [ %19, %14 ], [ %25, %20 ], [ %31, %26 ]
ret i32 %36
}