#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*/ free(double *);
scalar_t__ malloc(int);
double sqrt(double);
void jacobian_fd(double (*funcpt)(double *, int), double *x, int N, double *f) {
  int i, j;
  double step, fd;
  double *xi;
  fd = sqrt((double)1e-15);
  xi = (double *)malloc(sizeof(double) * N);
  for (i = 0; i < N; ++i) {
    step = fd * x[i];
    for (j = 0; j < N; ++j) {
      xi[j] = x[j];
    }
    xi[i] += step;
    f[i] = (funcpt(xi, N) - funcpt(x, N)) / step;
  }
  free(xi);
}


x86 assembly (clang, -O0):
<jacobian_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movsd  0xeb1(%rip),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1233 <jacobian_fd+0x103>
movsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d1 <jacobian_fd+0xa1>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    119d <jacobian_fd+0x6d>
movsd  -0x30(%rbp),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   *%rax
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1173 <jacobian_fd+0x43>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jacobian_fd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rcx,0x50(%rsp)
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,0x48(%rsp)
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    13c1 <jacobian_fd+0x2a1>
mov    %r14d,%r12d
lea    (%rbx,%r12,8),%rax
lea    0x0(,%r12,8),%rcx
add    %r13,%rcx
mov    %r12d,%edx
and    $0xfffffffc,%edx
mov    %rdx,0x30(%rsp)
add    $0xfffffffffffffffc,%rdx
mov    %rdx,0x28(%rsp)
shr    $0x2,%rdx
add    $0x1,%rdx
cmp    %rcx,%rbx
setb   %cl
cmp    %r13,%rax
seta   %al
and    %cl,%al
mov    %al,0x7(%rsp)
mov    %edx,%eax
and    $0x3,%eax
and    $0xfffffffffffffffc,%rdx
mov    %rdx,0x8(%rsp)
mov    %r12d,%esi
and    $0x3,%esi
mov    %rbx,%rcx
add    $0x10,%rcx
mov    %rcx,0x18(%rsp)
lea    0x10(%r13),%rcx
mov    %rcx,0x10(%rsp)
mov    %rax,0x20(%rsp)
mov    %rax,%rdi
shl    $0x5,%rdi
xor    %ebp,%ebp
mov    %rdi,0x40(%rsp)
mov    %rsi,0x38(%rsp)
mov    0x48(%rsp),%r15
jmp    123d <jacobian_fd+0x11d>
nop
movsd  (%rbx,%rbp,8),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
mov    %rbx,%rdi
mov    %r14d,%esi
movsd  %xmm2,0x60(%rsp)
call   *%r15
movsd  %xmm0,0x58(%rsp)
mov    %r13,%rdi
mov    %r14d,%esi
call   *%r15
mov    0x38(%rsp),%rsi
movsd  0x58(%rsp),%xmm1
subsd  %xmm0,%xmm1
divsd  0x60(%rsp),%xmm1
mov    0x50(%rsp),%rax
movsd  %xmm1,(%rax,%rbp,8)
add    $0x1,%rbp
cmp    %r12,%rbp
mov    0x40(%rsp),%rdi
je     13c1 <jacobian_fd+0x2a1>
cmp    $0x4,%r14d
setb   %al
movsd  0x0(%r13,%rbp,8),%xmm2
mulsd  0xdad(%rip),%xmm2
or     0x7(%rsp),%al
je     1260 <jacobian_fd+0x140>
xor    %eax,%eax
jmp    1340 <jacobian_fd+0x220>
cmpq   $0xc,0x28(%rsp)
jae    1270 <jacobian_fd+0x150>
xor    %eax,%eax
jmp    12e5 <jacobian_fd+0x1c5>
nopl   0x0(%rax)
mov    0x8(%rsp),%rcx
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movups 0x0(%r13,%rax,8),%xmm0
movups 0x10(%r13,%rax,8),%xmm1
movups %xmm0,(%rbx,%rax,8)
movups %xmm1,0x10(%rbx,%rax,8)
movups 0x20(%r13,%rax,8),%xmm0
movups 0x30(%r13,%rax,8),%xmm1
movups %xmm0,0x20(%rbx,%rax,8)
movups %xmm1,0x30(%rbx,%rax,8)
movups 0x40(%r13,%rax,8),%xmm0
movups 0x50(%r13,%rax,8),%xmm1
movups %xmm0,0x40(%rbx,%rax,8)
movups %xmm1,0x50(%rbx,%rax,8)
movupd 0x60(%r13,%rax,8),%xmm0
movupd 0x70(%r13,%rax,8),%xmm1
movupd %xmm0,0x60(%rbx,%rax,8)
movupd %xmm1,0x70(%rbx,%rax,8)
add    $0x10,%rax
add    $0xfffffffffffffffc,%rcx
jne    1280 <jacobian_fd+0x160>
cmpq   $0x0,0x20(%rsp)
je     132f <jacobian_fd+0x20f>
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%rcx
mov    0x10(%rsp),%rdx
lea    (%rdx,%rax,8),%rax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movupd -0x10(%rax,%rdx,1),%xmm0
movupd (%rax,%rdx,1),%xmm1
movupd %xmm0,-0x10(%rcx,%rdx,1)
movupd %xmm1,(%rcx,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%rdi
jne    1310 <jacobian_fd+0x1f0>
mov    0x30(%rsp),%rcx
mov    %rcx,%rax
cmp    %r12,%rcx
je     11e0 <jacobian_fd+0xc0>
mov    %rax,%rcx
not    %rcx
add    %r12,%rcx
test   %rsi,%rsi
je     1376 <jacobian_fd+0x256>
mov    %rsi,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  0x0(%r13,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%rax
add    $0xffffffffffffffff,%rdx
jne    1360 <jacobian_fd+0x240>
cmp    $0x3,%rcx
jb     11e0 <jacobian_fd+0xc0>
movsd  0x0(%r13,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
movsd  0x8(%r13,%rax,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rax,8)
movsd  0x10(%r13,%rax,8),%xmm0
movsd  %xmm0,0x10(%rbx,%rax,8)
movsd  0x18(%r13,%rax,8),%xmm0
movsd  %xmm0,0x18(%rbx,%rax,8)
add    $0x4,%rax
cmp    %rax,%r12
jne    1380 <jacobian_fd+0x260>
jmp    11e0 <jacobian_fd+0xc0>
mov    %rbx,%rdi
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @jacobian_fd(double (double*, i32)* nocapture %0, double* %1, i32 %2, double* nocapture writeonly %3) {
%5 = shl i32 %2, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double*
%8 = inttoptr i64 %6 to i8*
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %152
10: ; preds = %4
%11 = zext i32 %2 to i64
%12 = getelementptr double, double* %7, i64 %11
%13 = getelementptr double, double* %1, i64 %11
%14 = bitcast double* %13 to i8*
%15 = and i64 %11, 4294967292
%16 = add nsw i64 %15, -4
%17 = lshr exact i64 %16, 2
%18 = add nuw nsw i64 %17, 1
%19 = icmp ult i32 %2, 4
%20 = icmp ult i8* %8, %14
%21 = icmp ugt double* %12, %1
%22 = and i1 %20, %21
%23 = and i64 %11, 4294967292
%24 = and i64 %18, 3
%25 = icmp ult i64 %16, 12
%26 = and i64 %18, 9223372036854775804
%27 = icmp eq i64 %24, 0
%28 = icmp eq i64 %23, %11
%29 = and i64 %11, 3
%30 = icmp eq i64 %29, 0
br label %31
31: ; preds = %141, %10
%32 = phi i64 [ 0, %10 ], [ %150, %141 ]
%33 = getelementptr inbounds double, double* %1, i64 %32
%34 = load double, double* %33
%35 = fmul double %34, 0x3E60FA3389D6EB40
%36 = select i1 %19, i1 true, i1 %22
br i1 %36, label %106, label %37
37: ; preds = %31
br i1 %25, label %87, label %38
38: ; preds = %37, %38
%39 = phi i64 [ %84, %38 ], [ 0, %37 ]
%40 = phi i64 [ %85, %38 ], [ 0, %37 ]
%41 = getelementptr inbounds double, double* %1, i64 %39
%42 = bitcast double* %41 to <2 x double>*
%43 = load <2 x double>, <2 x double>* %42
%44 = getelementptr inbounds double, double* %41, i64 2
%45 = bitcast double* %44 to <2 x double>*
%46 = load <2 x double>, <2 x double>* %45
%47 = getelementptr inbounds double, double* %7, i64 %39
%48 = bitcast double* %47 to <2 x double>*
store <2 x double> %43, <2 x double>* %48
%49 = getelementptr inbounds double, double* %47, i64 2
%50 = bitcast double* %49 to <2 x double>*
store <2 x double> %46, <2 x double>* %50
%51 = or i64 %39, 4
%52 = getelementptr inbounds double, double* %1, i64 %51
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = getelementptr inbounds double, double* %52, i64 2
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = getelementptr inbounds double, double* %7, i64 %51
%59 = bitcast double* %58 to <2 x double>*
store <2 x double> %54, <2 x double>* %59
%60 = getelementptr inbounds double, double* %58, i64 2
%61 = bitcast double* %60 to <2 x double>*
store <2 x double> %57, <2 x double>* %61
%62 = or i64 %39, 8
%63 = getelementptr inbounds double, double* %1, i64 %62
%64 = bitcast double* %63 to <2 x double>*
%65 = load <2 x double>, <2 x double>* %64
%66 = getelementptr inbounds double, double* %63, i64 2
%67 = bitcast double* %66 to <2 x double>*
%68 = load <2 x double>, <2 x double>* %67
%69 = getelementptr inbounds double, double* %7, i64 %62
%70 = bitcast double* %69 to <2 x double>*
store <2 x double> %65, <2 x double>* %70
%71 = getelementptr inbounds double, double* %69, i64 2
%72 = bitcast double* %71 to <2 x double>*
store <2 x double> %68, <2 x double>* %72
%73 = or i64 %39, 12
%74 = getelementptr inbounds double, double* %1, i64 %73
%75 = bitcast double* %74 to <2 x double>*
%76 = load <2 x double>, <2 x double>* %75
%77 = getelementptr inbounds double, double* %74, i64 2
%78 = bitcast double* %77 to <2 x double>*
%79 = load <2 x double>, <2 x double>* %78
%80 = getelementptr inbounds double, double* %7, i64 %73
%81 = bitcast double* %80 to <2 x double>*
store <2 x double> %76, <2 x double>* %81
%82 = getelementptr inbounds double, double* %80, i64 2
%83 = bitcast double* %82 to <2 x double>*
store <2 x double> %79, <2 x double>* %83
%84 = add nuw i64 %39, 16
%85 = add nuw i64 %40, 4
%86 = icmp eq i64 %85, %26
br i1 %86, label %87, label %38
87: ; preds = %38, %37
%88 = phi i64 [ 0, %37 ], [ %84, %38 ]
br i1 %27, label %105, label %89
89: ; preds = %87, %89
%90 = phi i64 [ %102, %89 ], [ %88, %87 ]
%91 = phi i64 [ %103, %89 ], [ 0, %87 ]
%92 = getelementptr inbounds double, double* %1, i64 %90
%93 = bitcast double* %92 to <2 x double>*
%94 = load <2 x double>, <2 x double>* %93
%95 = getelementptr inbounds double, double* %92, i64 2
%96 = bitcast double* %95 to <2 x double>*
%97 = load <2 x double>, <2 x double>* %96
%98 = getelementptr inbounds double, double* %7, i64 %90
%99 = bitcast double* %98 to <2 x double>*
store <2 x double> %94, <2 x double>* %99
%100 = getelementptr inbounds double, double* %98, i64 2
%101 = bitcast double* %100 to <2 x double>*
store <2 x double> %97, <2 x double>* %101
%102 = add nuw i64 %90, 4
%103 = add i64 %91, 1
%104 = icmp eq i64 %103, %24
br i1 %104, label %105, label %89
105: ; preds = %89, %87
br i1 %28, label %141, label %106
106: ; preds = %31, %105
%107 = phi i64 [ 0, %31 ], [ %23, %105 ]
%108 = xor i64 %107, -1
%109 = add nsw i64 %108, %11
br i1 %30, label %119, label %110
110: ; preds = %106, %110
%111 = phi i64 [ %116, %110 ], [ %107, %106 ]
%112 = phi i64 [ %117, %110 ], [ 0, %106 ]
%113 = getelementptr inbounds double, double* %1, i64 %111
%114 = load double, double* %113
%115 = getelementptr inbounds double, double* %7, i64 %111
store double %114, double* %115
%116 = add nuw nsw i64 %111, 1
%117 = add i64 %112, 1
%118 = icmp eq i64 %117, %29
br i1 %118, label %119, label %110
119: ; preds = %110, %106
%120 = phi i64 [ %107, %106 ], [ %116, %110 ]
%121 = icmp ult i64 %109, 3
br i1 %121, label %141, label %122
122: ; preds = %119, %122
%123 = phi i64 [ %139, %122 ], [ %120, %119 ]
%124 = getelementptr inbounds double, double* %1, i64 %123
%125 = load double, double* %124
%126 = getelementptr inbounds double, double* %7, i64 %123
store double %125, double* %126
%127 = add nuw nsw i64 %123, 1
%128 = getelementptr inbounds double, double* %1, i64 %127
%129 = load double, double* %128
%130 = getelementptr inbounds double, double* %7, i64 %127
store double %129, double* %130
%131 = add nuw nsw i64 %123, 2
%132 = getelementptr inbounds double, double* %1, i64 %131
%133 = load double, double* %132
%134 = getelementptr inbounds double, double* %7, i64 %131
store double %133, double* %134
%135 = add nuw nsw i64 %123, 3
%136 = getelementptr inbounds double, double* %1, i64 %135
%137 = load double, double* %136
%138 = getelementptr inbounds double, double* %7, i64 %135
store double %137, double* %138
%139 = add nuw nsw i64 %123, 4
%140 = icmp eq i64 %139, %11
br i1 %140, label %141, label %122
141: ; preds = %119, %122, %105
%142 = getelementptr inbounds double, double* %7, i64 %32
%143 = load double, double* %142
%144 = fadd double %35, %143
store double %144, double* %142
%145 = tail call double %0(double* %7, i32 %2)
%146 = tail call double %0(double* %1, i32 %2)
%147 = fsub double %145, %146
%148 = fdiv double %147, %35
%149 = getelementptr inbounds double, double* %3, i64 %32
store double %148, double* %149
%150 = add nuw nsw i64 %32, 1
%151 = icmp eq i64 %150, %11
br i1 %151, label %152, label %31
152: ; preds = %141, %4
%153 = tail call i32 @free(double* %7)
ret void
}