#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 cgpr_mt(double (*)(double *, int), void (*)(double *, int, double *),
            double *, int, double *, int, int *, double, double, double, double,
            double *);
int conjgrad_min_lin(double (*funcpt)(double *, int),
                     void (*funcgrad)(double *, int, double *), double *xi,
                     int N, double *dx, int MAXITER, int *niter, double eps,
                     double gtol, double ftol, double xtol, double *xf) {
  int rcode, i;
  for (i = 0; i < N; ++i) {
    xi[i] *= dx[i];
    dx[i] = 1.0 / dx[i];
  }
  rcode = cgpr_mt(funcpt, funcgrad, xi, N, dx, MAXITER, niter, eps, gtol, ftol,
                  xtol, xf);
  return rcode;
}


x86 assembly (clang, -O0):
<conjgrad_min_lin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movsd  %xmm0,-0x38(%rbp)
movsd  %xmm1,-0x40(%rbp)
movsd  %xmm2,-0x48(%rbp)
movsd  %xmm3,-0x50(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ad <conjgrad_min_lin+0x9d>
mov    -0x28(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x58(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  0xe73(%rip),%xmm0
divsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1152 <conjgrad_min_lin+0x42>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    0x10(%rbp),%r10
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm3
mov    0x18(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <cgpr_mt@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conjgrad_min_lin>:
push   %r14
push   %rbx
test   %ecx,%ecx
jle    12c0 <conjgrad_min_lin+0x1b0>
mov    %ecx,%r10d
cmp    $0x1,%ecx
je     113d <conjgrad_min_lin+0x2d>
lea    (%r8,%r10,8),%rax
cmp    %rdx,%rax
jbe    11e3 <conjgrad_min_lin+0xd3>
lea    (%rdx,%r10,8),%rax
cmp    %r8,%rax
jbe    11e3 <conjgrad_min_lin+0xd3>
xor    %eax,%eax
mov    %rax,%rbx
not    %rbx
test   $0x1,%r10b
je     1173 <conjgrad_min_lin+0x63>
movsd  (%r8,%rax,8),%xmm4
mulsd  (%rdx,%rax,8),%xmm4
movsd  %xmm4,(%rdx,%rax,8)
movsd  0xead(%rip),%xmm4
divsd  (%r8,%rax,8),%xmm4
movsd  %xmm4,(%r8,%rax,8)
or     $0x1,%rax
add    %r10,%rbx
je     12c0 <conjgrad_min_lin+0x1b0>
movsd  0xe8c(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r8,%rax,8),%xmm5
mulsd  (%rdx,%rax,8),%xmm5
movsd  %xmm5,(%rdx,%rax,8)
movapd %xmm4,%xmm5
divsd  (%r8,%rax,8),%xmm5
movsd  %xmm5,(%r8,%rax,8)
movsd  0x8(%r8,%rax,8),%xmm5
mulsd  0x8(%rdx,%rax,8),%xmm5
movsd  %xmm5,0x8(%rdx,%rax,8)
movapd %xmm4,%xmm5
divsd  0x8(%r8,%rax,8),%xmm5
movsd  %xmm5,0x8(%r8,%rax,8)
add    $0x2,%rax
cmp    %rax,%r10
jne    1190 <conjgrad_min_lin+0x80>
jmp    12c0 <conjgrad_min_lin+0x1b0>
mov    %r10d,%eax
and    $0xfffffffe,%eax
lea    -0x2(%rax),%rbx
mov    %rbx,%r14
shr    %r14
add    $0x1,%r14
test   %rbx,%rbx
je     12c8 <conjgrad_min_lin+0x1b8>
mov    %r14,%rbx
and    $0xfffffffffffffffe,%rbx
xor    %r11d,%r11d
movapd 0xdee(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movupd (%r8,%r11,8),%xmm5
movupd (%rdx,%r11,8),%xmm6
mulpd  %xmm5,%xmm6
movupd %xmm6,(%rdx,%r11,8)
movupd (%r8,%r11,8),%xmm5
movupd 0x10(%r8,%r11,8),%xmm6
movapd %xmm4,%xmm7
divpd  %xmm5,%xmm7
movupd %xmm7,(%r8,%r11,8)
movupd 0x10(%rdx,%r11,8),%xmm5
mulpd  %xmm6,%xmm5
movupd %xmm5,0x10(%rdx,%r11,8)
movupd 0x10(%r8,%r11,8),%xmm5
movapd %xmm4,%xmm6
divpd  %xmm5,%xmm6
movupd %xmm6,0x10(%r8,%r11,8)
add    $0x4,%r11
add    $0xfffffffffffffffe,%rbx
jne    1220 <conjgrad_min_lin+0x110>
test   $0x1,%r14b
je     12b7 <conjgrad_min_lin+0x1a7>
movupd (%r8,%r11,8),%xmm4
movupd (%rdx,%r11,8),%xmm5
mulpd  %xmm4,%xmm5
movupd %xmm5,(%rdx,%r11,8)
movupd (%r8,%r11,8),%xmm4
movapd 0xd53(%rip),%xmm5
divpd  %xmm4,%xmm5
movupd %xmm5,(%r8,%r11,8)
cmp    %r10,%rax
jne    113f <conjgrad_min_lin+0x2f>
pop    %rbx
pop    %r14
jmp    1030 <cgpr_mt@plt>
xor    %r11d,%r11d
test   $0x1,%r14b
jne    1289 <conjgrad_min_lin+0x179>
jmp    12b7 <conjgrad_min_lin+0x1a7>

LLVM IR (-O0):
define i32 @conjgrad_min_lin(double (double*, i32)* %0, void (double*, i32, double*)* %1, double* %2, i32 %3, double* %4, i32 %5, i32* %6, double %7, double %8, double %9, double %10, double* %11) {
%13 = alloca double (double*, i32)*
%14 = alloca void (double*, i32, double*)*
%15 = alloca double*
%16 = alloca i32
%17 = alloca double*
%18 = alloca i32
%19 = alloca i32*
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double*
%25 = alloca i32
%26 = alloca i32
store double (double*, i32)* %0, double (double*, i32)** %13
store void (double*, i32, double*)* %1, void (double*, i32, double*)** %14
store double* %2, double** %15
store i32 %3, i32* %16
store double* %4, double** %17
store i32 %5, i32* %18
store i32* %6, i32** %19
store double %7, double* %20
store double %8, double* %21
store double %9, double* %22
store double %10, double* %23
store double* %11, double** %24
store i32 0, i32* %26
br label %27
27: ; preds = %53, %12
%28 = load i32, i32* %26
%29 = load i32, i32* %16
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %56
31: ; preds = %27
%32 = load double*, double** %17
%33 = load i32, i32* %26
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = load double*, double** %15
%38 = load i32, i32* %26
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = fmul double %41, %36
store double %42, double* %40
%43 = load double*, double** %17
%44 = load i32, i32* %26
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = fdiv double 1.000000e+00, %47
%49 = load double*, double** %17
%50 = load i32, i32* %26
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
store double %48, double* %52
br label %53
53: ; preds = %31
%54 = load i32, i32* %26
%55 = add nsw i32 %54, 1
store i32 %55, i32* %26
br label %27
56: ; preds = %27
%57 = load double (double*, i32)*, double (double*, i32)** %13
%58 = load void (double*, i32, double*)*, void (double*, i32, double*)** %14
%59 = load double*, double** %15
%60 = load i32, i32* %16
%61 = load double*, double** %17
%62 = load i32, i32* %18
%63 = load i32*, i32** %19
%64 = load double, double* %20
%65 = load double, double* %21
%66 = load double, double* %22
%67 = load double, double* %23
%68 = load double*, double** %24
%69 = call i32 @cgpr_mt(double (double*, i32)* %57, void (double*, i32, double*)* %58, double* %59, i32 %60, double* %61, i32 %62, i32* %63, double %64, double %65, double %66, double %67, double* %68)
store i32 %69, i32* %25
%70 = load i32, i32* %25
ret i32 %70
}

LLVM IR (-O2):
define i32 @conjgrad_min_lin(double (double*, i32)* %0, void (double*, i32, double*)* %1, double* %2, i32 %3, double* %4, i32 %5, i32* %6, double %7, double %8, double %9, double %10, double* %11) {
%13 = icmp sgt i32 %3, 0
br i1 %13, label %14, label %118
14: ; preds = %12
%15 = zext i32 %3 to i64
%16 = icmp eq i32 %3, 1
br i1 %16, label %81, label %17
17: ; preds = %14
%18 = getelementptr double, double* %2, i64 %15
%19 = getelementptr double, double* %4, i64 %15
%20 = icmp ugt double* %19, %2
%21 = icmp ugt double* %18, %4
%22 = and i1 %20, %21
br i1 %22, label %81, label %23
23: ; preds = %17
%24 = and i64 %15, 4294967294
%25 = add nsw i64 %24, -2
%26 = lshr exact i64 %25, 1
%27 = add nuw i64 %26, 1
%28 = and i64 %27, 1
%29 = icmp eq i64 %25, 0
br i1 %29, label %63, label %30
30: ; preds = %23
%31 = and i64 %27, -2
br label %32
32: ; preds = %32, %30
%33 = phi i64 [ 0, %30 ], [ %60, %32 ]
%34 = phi i64 [ 0, %30 ], [ %61, %32 ]
%35 = getelementptr inbounds double, double* %4, i64 %33
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = getelementptr inbounds double, double* %2, i64 %33
%39 = bitcast double* %38 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = fmul <2 x double> %37, %40
%42 = bitcast double* %38 to <2 x double>*
store <2 x double> %41, <2 x double>* %42
%43 = bitcast double* %35 to <2 x double>*
%44 = load <2 x double>, <2 x double>* %43
%45 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %44
%46 = bitcast double* %35 to <2 x double>*
store <2 x double> %45, <2 x double>* %46
%47 = or i64 %33, 2
%48 = getelementptr inbounds double, double* %4, i64 %47
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = getelementptr inbounds double, double* %2, i64 %47
%52 = bitcast double* %51 to <2 x double>*
%53 = load <2 x double>, <2 x double>* %52
%54 = fmul <2 x double> %50, %53
%55 = bitcast double* %51 to <2 x double>*
store <2 x double> %54, <2 x double>* %55
%56 = bitcast double* %48 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %57
%59 = bitcast double* %48 to <2 x double>*
store <2 x double> %58, <2 x double>* %59
%60 = add nuw i64 %33, 4
%61 = add nuw i64 %34, 2
%62 = icmp eq i64 %61, %31
br i1 %62, label %63, label %32
63: ; preds = %32, %23
%64 = phi i64 [ 0, %23 ], [ %60, %32 ]
%65 = icmp eq i64 %28, 0
br i1 %65, label %79, label %66
66: ; preds = %63
%67 = getelementptr inbounds double, double* %4, i64 %64
%68 = bitcast double* %67 to <2 x double>*
%69 = load <2 x double>, <2 x double>* %68
%70 = getelementptr inbounds double, double* %2, i64 %64
%71 = bitcast double* %70 to <2 x double>*
%72 = load <2 x double>, <2 x double>* %71
%73 = fmul <2 x double> %69, %72
%74 = bitcast double* %70 to <2 x double>*
store <2 x double> %73, <2 x double>* %74
%75 = bitcast double* %67 to <2 x double>*
%76 = load <2 x double>, <2 x double>* %75
%77 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %76
%78 = bitcast double* %67 to <2 x double>*
store <2 x double> %77, <2 x double>* %78
br label %79
79: ; preds = %63, %66
%80 = icmp eq i64 %24, %15
br i1 %80, label %118, label %81
81: ; preds = %17, %14, %79
%82 = phi i64 [ 0, %17 ], [ 0, %14 ], [ %24, %79 ]
%83 = xor i64 %82, -1
%84 = and i64 %15, 1
%85 = icmp eq i64 %84, 0
br i1 %85, label %95, label %86
86: ; preds = %81
%87 = getelementptr inbounds double, double* %4, i64 %82
%88 = load double, double* %87
%89 = getelementptr inbounds double, double* %2, i64 %82
%90 = load double, double* %89
%91 = fmul double %88, %90
store double %91, double* %89
%92 = load double, double* %87
%93 = fdiv double 1.000000e+00, %92
store double %93, double* %87
%94 = or i64 %82, 1
br label %95
95: ; preds = %86, %81
%96 = phi i64 [ %82, %81 ], [ %94, %86 ]
%97 = sub nsw i64 0, %15
%98 = icmp eq i64 %83, %97
br i1 %98, label %118, label %99
99: ; preds = %95, %99
%100 = phi i64 [ %116, %99 ], [ %96, %95 ]
%101 = getelementptr inbounds double, double* %4, i64 %100
%102 = load double, double* %101
%103 = getelementptr inbounds double, double* %2, i64 %100
%104 = load double, double* %103
%105 = fmul double %102, %104
store double %105, double* %103
%106 = load double, double* %101
%107 = fdiv double 1.000000e+00, %106
store double %107, double* %101
%108 = add nuw nsw i64 %100, 1
%109 = getelementptr inbounds double, double* %4, i64 %108
%110 = load double, double* %109
%111 = getelementptr inbounds double, double* %2, i64 %108
%112 = load double, double* %111
%113 = fmul double %110, %112
store double %113, double* %111
%114 = load double, double* %109
%115 = fdiv double 1.000000e+00, %114
store double %115, double* %109
%116 = add nuw nsw i64 %100, 2
%117 = icmp eq i64 %116, %15
br i1 %117, label %118, label %99
118: ; preds = %95, %99, %79, %12
%119 = tail call i32 @cgpr_mt(double (double*, i32)* %0, void (double*, i32, double*)* %1, double* %2, i32 %3, double* %4, i32 %5, i32* %6, double %7, double %8, double %9, double %10, double* %11)
ret i32 %119
}