#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 fabs(double);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
double signx(double);
void fdjac(void (*funcgrad)(double *, int, double *), double *x, int N,
           double *jac, double *dx, double eps2, double *J) {
  int i, j;
  double stepsize, temp, stepmax;
  double *fj;
  fj = (double *)malloc(sizeof(double) * N);
  for (j = 0; j < N; ++j) {
    if (fabs(x[j]) >= (1.0 / fabs(dx[j]))) {
      stepmax = x[j];
    } else {
      stepmax = signx(x[j]) * 1.0 / fabs(dx[j]);
    }
    stepsize = eps2 * stepmax;
    temp = x[j];
    x[j] += stepsize;
    stepsize = x[j] - temp;
    funcgrad(x, N, fj);
    for (i = 0; i < N; ++i) {
      J[i * N + j] = (fj[i] - jac[i]) / stepsize;
    }
    x[j] = temp;
  }
  free(fj);
}


x86 assembly (clang, -O0):
<fdjac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12ec <fdjac+0x1bc>
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe82(%rip),%xmm1
pand   %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movaps 0xe6a(%rip),%xmm1
pand   %xmm1,%xmm2
movsd  0xe4e(%rip),%xmm1
divsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jb     11d7 <fdjac+0xa7>
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1216 <fdjac+0xe6>
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <signx@plt>
movsd  0xe0f(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movaps 0xe07(%rip),%xmm2
pand   %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x60(%rbp),%rdx
call   *%rax
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12cc <fdjac+0x19c>
mov    -0x60(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
divsd  -0x48(%rbp),%xmm0
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x40(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    127d <fdjac+0x14d>
movsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    116e <fdjac+0x3e>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdjac>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9,0x10(%rsp)
movsd  %xmm0,0x40(%rsp)
mov    %r8,0x28(%rsp)
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r13
mov    %rdi,0x38(%rsp)
lea    0x0(,%rbp,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbp,0x20(%rsp)
test   %ebp,%ebp
jle    1314 <fdjac+0x1e4>
mov    0x20(%rsp),%ebp
mov    %ebp,%r15d
and    $0xfffffffe,%r15d
mov    %rbp,%r12
shl    $0x4,%r12
xor    %edx,%edx
mov    0x10(%rsp),%rsi
mov    %r13,0x18(%rsp)
jmp    11b8 <fdjac+0x88>
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x0(%r13,%rdx,8)
add    $0x1,%rdx
add    $0x8,%rsi
cmp    %rbp,%rdx
je     1314 <fdjac+0x1e4>
movsd  0x0(%r13,%rdx,8),%xmm0
movapd %xmm0,%xmm3
movapd 0xe35(%rip),%xmm2
andpd  %xmm2,%xmm3
mov    0x28(%rsp),%rax
movsd  (%rax,%rdx,8),%xmm1
andpd  %xmm2,%xmm1
movsd  0xe2b(%rip),%xmm2
divsd  %xmm1,%xmm2
ucomisd %xmm2,%xmm3
mov    %rdx,0x8(%rsp)
mov    %rsi,0x30(%rsp)
jae    1230 <fdjac+0x100>
call   1040 <signx@plt>
mov    0x8(%rsp),%rdx
movapd %xmm0,%xmm1
mov    0x28(%rsp),%rax
movsd  (%rax,%rdx,8),%xmm0
andpd  0xde7(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0x0(%r13,%rdx,8),%xmm0
jmp    1234 <fdjac+0x104>
cs nopw 0x0(%rax,%rax,1)
movapd %xmm0,%xmm1
movapd %xmm0,0x50(%rsp)
mulsd  0x40(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x48(%rsp)
movsd  %xmm1,0x0(%r13,%rdx,8)
mov    %r13,%rdi
mov    0x20(%rsp),%r13
mov    %r13d,%esi
mov    %r14,%rdx
call   *0x38(%rsp)
movsd  0x48(%rsp),%xmm2
movapd 0x50(%rsp),%xmm1
subsd  %xmm1,%xmm2
cmp    $0x1,%r13d
jne    1290 <fdjac+0x160>
xor    %eax,%eax
mov    0x18(%rsp),%r13
mov    0x8(%rsp),%rdx
mov    0x30(%rsp),%rsi
jmp    12e5 <fdjac+0x1b5>
nopl   0x0(%rax)
mov    0x30(%rsp),%rsi
mov    %rsi,%rcx
xor    %eax,%eax
mov    0x18(%rsp),%r13
mov    0x8(%rsp),%rdx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r14,%rax,8),%xmm0
subsd  (%rbx,%rax,8),%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm0,(%rcx)
movsd  0x8(%r14,%rax,8),%xmm0
subsd  0x8(%rbx,%rax,8),%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm0,(%rcx,%rbp,8)
add    $0x2,%rax
add    %r12,%rcx
cmp    %rax,%r15
jne    12b0 <fdjac+0x180>
test   $0x1,%bpl
je     11a0 <fdjac+0x70>
movsd  (%r14,%rax,8),%xmm0
subsd  (%rbx,%rax,8),%xmm0
divsd  %xmm2,%xmm0
imul   %rbp,%rax
add    %rdx,%rax
mov    0x10(%rsp),%rcx
movsd  %xmm0,(%rcx,%rax,8)
jmp    11a0 <fdjac+0x70>
mov    %r14,%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 @fdjac(void (double*, i32, double*)* %0, double* %1, i32 %2, double* %3, double* %4, double %5, double* %6) {
%8 = alloca void (double*, i32, double*)*
%9 = alloca double*
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double*
store void (double*, i32, double*)* %0, void (double*, i32, double*)** %8
store double* %1, double** %9
store i32 %2, i32* %10
store double* %3, double** %11
store double* %4, double** %12
store double %5, double* %13
store double* %6, double** %14
%21 = load i32, i32* %10
%22 = sext i32 %21 to i64
%23 = mul i64 8, %22
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to double*
store double* %26, double** %20
store i32 0, i32* %16
br label %27
27: ; preds = %129, %7
%28 = load i32, i32* %16
%29 = load i32, i32* %10
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %132
31: ; preds = %27
%32 = load double*, double** %9
%33 = load i32, i32* %16
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = call double @llvm.fabs.f64(double %36)
%38 = load double*, double** %12
%39 = load i32, i32* %16
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = call double @llvm.fabs.f64(double %42)
%44 = fdiv double 1.000000e+00, %43
%45 = fcmp oge double %37, %44
br i1 %45, label %46, label %52
46: ; preds = %31
%47 = load double*, double** %9
%48 = load i32, i32* %16
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
store double %51, double* %19
br label %67
52: ; preds = %31
%53 = load double*, double** %9
%54 = load i32, i32* %16
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = call double @signx(double %57)
%59 = fmul double %58, 1.000000e+00
%60 = load double*, double** %12
%61 = load i32, i32* %16
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = call double @llvm.fabs.f64(double %64)
%66 = fdiv double %59, %65
store double %66, double* %19
br label %67
67: ; preds = %52, %46
%68 = load double, double* %13
%69 = load double, double* %19
%70 = fmul double %68, %69
store double %70, double* %17
%71 = load double*, double** %9
%72 = load i32, i32* %16
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
%75 = load double, double* %74
store double %75, double* %18
%76 = load double, double* %17
%77 = load double*, double** %9
%78 = load i32, i32* %16
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %77, i64 %79
%81 = load double, double* %80
%82 = fadd double %81, %76
store double %82, double* %80
%83 = load double*, double** %9
%84 = load i32, i32* %16
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %83, i64 %85
%87 = load double, double* %86
%88 = load double, double* %18
%89 = fsub double %87, %88
store double %89, double* %17
%90 = load void (double*, i32, double*)*, void (double*, i32, double*)** %8
%91 = load double*, double** %9
%92 = load i32, i32* %10
%93 = load double*, double** %20
store i32 0, i32* %15
br label %94
94: ; preds = %120, %67
%95 = load i32, i32* %15
%96 = load i32, i32* %10
%97 = icmp slt i32 %95, %96
br i1 %97, label %98, label %123
98: ; preds = %94
%99 = load double*, double** %20
%100 = load i32, i32* %15
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds double, double* %99, i64 %101
%103 = load double, double* %102
%104 = load double*, double** %11
%105 = load i32, i32* %15
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds double, double* %104, i64 %106
%108 = load double, double* %107
%109 = fsub double %103, %108
%110 = load double, double* %17
%111 = fdiv double %109, %110
%112 = load double*, double** %14
%113 = load i32, i32* %15
%114 = load i32, i32* %10
%115 = mul nsw i32 %113, %114
%116 = load i32, i32* %16
%117 = add nsw i32 %115, %116
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds double, double* %112, i64 %118
store double %111, double* %119
br label %120
120: ; preds = %98
%121 = load i32, i32* %15
%122 = add nsw i32 %121, 1
store i32 %122, i32* %15
br label %94
123: ; preds = %94
%124 = load double, double* %18
%125 = load double*, double** %9
%126 = load i32, i32* %16
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds double, double* %125, i64 %127
store double %124, double* %128
br label %129
129: ; preds = %123
%130 = load i32, i32* %16
%131 = add nsw i32 %130, 1
store i32 %131, i32* %16
br label %27
132: ; preds = %27
%133 = load double*, double** %20
%134 = call i32 @free(double* %133)
ret void
}

LLVM IR (-O2):
define void @fdjac(void (double*, i32, double*)* nocapture %0, double* %1, i32 %2, double* nocapture %3, double* nocapture %4, double %5, double* nocapture writeonly %6) {
%8 = shl i32 %2, 3
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to double*
%11 = icmp sgt i32 %2, 0
br i1 %11, label %12, label %81
12: ; preds = %7
%13 = zext i32 %2 to i64
%14 = zext i32 %2 to i64
%15 = and i64 %14, 1
%16 = icmp eq i32 %2, 1
%17 = and i64 %14, 4294967294
%18 = icmp eq i64 %15, 0
br label %19
19: ; preds = %12, %78
%20 = phi i64 [ 0, %12 ], [ %79, %78 ]
%21 = getelementptr inbounds double, double* %1, i64 %20
%22 = load double, double* %21
%23 = tail call double @llvm.fabs.f64(double %22)
%24 = getelementptr inbounds double, double* %4, i64 %20
%25 = load double, double* %24
%26 = tail call double @llvm.fabs.f64(double %25)
%27 = fdiv double 1.000000e+00, %26
%28 = fcmp ult double %23, %27
br i1 %28, label %29, label %35
29: ; preds = %19
%30 = tail call double @signx(double %22)
%31 = load double, double* %24
%32 = tail call double @llvm.fabs.f64(double %31)
%33 = fdiv double %30, %32
%34 = load double, double* %21
br label %35
35: ; preds = %29, %19
%36 = phi double [ %34, %29 ], [ %22, %19 ]
%37 = phi double [ %33, %29 ], [ %22, %19 ]
%38 = fmul double %37, %5
%39 = fadd double %36, %38
store double %39, double* %21
%40 = fsub double %39, %36
tail call void %0(double* %1, i32 %2, double* %10)
br i1 %16, label %66, label %41
41: ; preds = %35, %41
%42 = phi i64 [ %63, %41 ], [ 0, %35 ]
%43 = phi i64 [ %64, %41 ], [ 0, %35 ]
%44 = getelementptr inbounds double, double* %10, i64 %42
%45 = load double, double* %44
%46 = getelementptr inbounds double, double* %3, i64 %42
%47 = load double, double* %46
%48 = fsub double %45, %47
%49 = fdiv double %48, %40
%50 = mul nsw i64 %42, %13
%51 = add nuw nsw i64 %50, %20
%52 = getelementptr inbounds double, double* %6, i64 %51
store double %49, double* %52
%53 = or i64 %42, 1
%54 = getelementptr inbounds double, double* %10, i64 %53
%55 = load double, double* %54
%56 = getelementptr inbounds double, double* %3, i64 %53
%57 = load double, double* %56
%58 = fsub double %55, %57
%59 = fdiv double %58, %40
%60 = mul nsw i64 %53, %13
%61 = add nuw nsw i64 %60, %20
%62 = getelementptr inbounds double, double* %6, i64 %61
store double %59, double* %62
%63 = add nuw nsw i64 %42, 2
%64 = add i64 %43, 2
%65 = icmp eq i64 %64, %17
br i1 %65, label %66, label %41
66: ; preds = %41, %35
%67 = phi i64 [ 0, %35 ], [ %63, %41 ]
br i1 %18, label %78, label %68
68: ; preds = %66
%69 = getelementptr inbounds double, double* %10, i64 %67
%70 = load double, double* %69
%71 = getelementptr inbounds double, double* %3, i64 %67
%72 = load double, double* %71
%73 = fsub double %70, %72
%74 = fdiv double %73, %40
%75 = mul nsw i64 %67, %13
%76 = add nuw nsw i64 %75, %20
%77 = getelementptr inbounds double, double* %6, i64 %76
store double %74, double* %77
br label %78
78: ; preds = %66, %68
store double %36, double* %21
%79 = add nuw nsw i64 %20, 1
%80 = icmp eq i64 %79, %14
br i1 %80, label %81, label %19
81: ; preds = %78, %7
%82 = tail call i32 @free(double* %10)
ret void
}