#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);
int leg_func_deriv(double t, int maxdeg, double **lf, double **lf_der) {
  short grad;
  short ord;
  double cf;
  double *wurz;
  short i;
  short ip;
  short im;
  wurz = (double *)malloc((2 * maxdeg + 4) * sizeof(double));
  for (i = 0; i < 2 * maxdeg + 4; i++)
    wurz[i] = sqrt((double)(i));
  cf = sqrt(1.0 - t * t);
  lf_der[0][0] = 0.0;
  lf_der[1][1] = -wurz[3] * t;
  for (grad = 1; grad < maxdeg; grad++) {
    lf_der[grad + 1][grad + 1] = wurz[2 * grad + 3] / wurz[2 * grad + 2] *
                                 (cf * lf_der[grad][grad] - t * lf[grad][grad]);
  }
  for (ord = 0; ord < maxdeg; ord++) {
    lf_der[ord + 1][ord] =
        wurz[2 * ord + 3] * (t * lf_der[ord][ord] + cf * lf[ord][ord]);
    for (grad = ord + 1; grad < maxdeg; grad++) {
      i = 2 * grad;
      ip = grad + ord;
      im = grad - ord;
      lf_der[grad + 1][ord] =
          wurz[i + 3] / wurz[ip + 1] / wurz[im + 1] *
          (wurz[i + 1] * (t * lf_der[grad][ord] + cf * lf[grad][ord]) -
           wurz[ip] * wurz[im] / wurz[i - 1] * lf_der[grad - 1][ord]);
    }
  }
  free(wurz);
  return 0;
}


x86 assembly (clang, -O0):
<leg_func_deriv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
add    $0x4,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
movw   $0x0,-0x3a(%rbp)
movswl -0x3a(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
add    $0x4,%ecx
cmp    %ecx,%eax
jge    11a9 <leg_func_deriv+0x79>
movswl -0x3a(%rbp),%eax
cvtsi2sd %eax,%xmm0
call   1050 <sqrt@plt>
mov    -0x38(%rbp),%rax
movswq -0x3a(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3a(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x3a(%rbp)
jmp    1168 <leg_func_deriv+0x38>
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe2a(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x38(%rbp),%rax
movsd  0x18(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x8(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
movsd  %xmm0,0x8(%rax)
movw   $0x1,-0x22(%rbp)
movswl -0x22(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12f0 <leg_func_deriv+0x1c0>
mov    -0x38(%rbp),%rax
movswl -0x22(%rbp),%ecx
shl    $0x1,%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movswl -0x22(%rbp),%ecx
shl    $0x1,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
divsd  (%rax,%rcx,8),%xmm0
movsd  -0x30(%rbp),%xmm1
mov    -0x20(%rbp),%rax
movswq -0x22(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movswq -0x22(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
movsd  -0x8(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movswq -0x22(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movswq -0x22(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movswl -0x22(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movswl -0x22(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x22(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x22(%rbp)
jmp    122a <leg_func_deriv+0xfa>
movw   $0x0,-0x24(%rbp)
movswl -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    14f5 <leg_func_deriv+0x3c5>
mov    -0x38(%rbp),%rax
movswl -0x24(%rbp),%ecx
shl    $0x1,%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x8(%rbp),%xmm1
mov    -0x20(%rbp),%rax
movswq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movswq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
movsd  -0x30(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movswq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movswq -0x24(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movswl -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movswq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movswl -0x24(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0x22(%rbp)
movswl -0x22(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    14df <leg_func_deriv+0x3af>
movswl -0x22(%rbp),%eax
shl    $0x1,%eax
mov    %ax,-0x3a(%rbp)
movswl -0x22(%rbp),%eax
movswl -0x24(%rbp),%ecx
add    %ecx,%eax
mov    %ax,-0x3c(%rbp)
movswl -0x22(%rbp),%eax
movswl -0x24(%rbp),%ecx
sub    %ecx,%eax
mov    %ax,-0x3e(%rbp)
mov    -0x38(%rbp),%rax
movswl -0x3a(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movswl -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movswl -0x3e(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movswl -0x3a(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x8(%rbp),%xmm3
mov    -0x20(%rbp),%rax
movswq -0x22(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movswq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm4
movsd  -0x30(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movswq -0x22(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movswq -0x24(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm4,%xmm3
addsd  %xmm2,%xmm3
mov    -0x38(%rbp),%rax
movswq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x38(%rbp),%rax
movswq -0x3e(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm2
mov    -0x38(%rbp),%rax
movswl -0x3a(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
divsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movswl -0x22(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movswq -0x24(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movswl -0x22(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movswq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x22(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x22(%rbp)
jmp    1384 <leg_func_deriv+0x254>
jmp    14e4 <leg_func_deriv+0x3b4>
mov    -0x24(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x24(%rbp)
jmp    12f6 <leg_func_deriv+0x1c6>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leg_func_deriv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %edi,%r15d
movsd  %xmm0,(%rsp)
lea    (%r15,%r15,1),%eax
lea    0x20(,%rax,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r13
cmp    $0xffffffff,%r15d
jl     11b4 <leg_func_deriv+0x84>
lea    (%r15,%r15,1),%ebx
add    $0x4,%ebx
xor    %ebp,%ebp
xorpd  %xmm1,%xmm1
jmp    119e <leg_func_deriv+0x6e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1050 <sqrt@plt>
xorpd  %xmm1,%xmm1
movswq %bp,%rax
movsd  %xmm0,0x0(%r13,%rax,8)
add    $0x1,%ebp
movswl %bp,%eax
cmp    %eax,%ebx
jle    11b4 <leg_func_deriv+0x84>
movswl %bp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd %xmm1,%xmm0
jb     1180 <leg_func_deriv+0x50>
sqrtsd %xmm0,%xmm0
jmp    1189 <leg_func_deriv+0x59>
movsd  (%rsp),%xmm5
movapd %xmm5,%xmm1
mulsd  %xmm5,%xmm1
movsd  0xe37(%rip),%xmm0
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11dd <leg_func_deriv+0xad>
sqrtsd %xmm0,%xmm0
jmp    11e7 <leg_func_deriv+0xb7>
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm5
mov    (%r12),%rdx
movq   $0x0,(%rdx)
movsd  0x18(%r13),%xmm1
xorpd  0xe10(%rip),%xmm1
mulsd  %xmm5,%xmm1
mov    0x8(%r12),%rax
movsd  %xmm1,0x8(%rax)
cmp    $0x2,%r15d
jl     1275 <leg_func_deriv+0x145>
mov    $0x1,%eax
nopl   0x0(%rax)
lea    (%rax,%rax,1),%ecx
movslq %ecx,%rcx
movsd  0x18(%r13,%rcx,8),%xmm2
divsd  0x10(%r13,%rcx,8),%xmm2
movslq %eax,%rcx
mov    (%r14,%rcx,8),%rax
movsd  (%rax,%rcx,8),%xmm3
mulsd  %xmm5,%xmm3
mulsd  %xmm0,%xmm1
subsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm1
mov    0x8(%r12,%rcx,8),%rax
movsd  %xmm1,0x8(%rax,%rcx,8)
add    $0x1,%ecx
movswl %cx,%eax
cmp    %r15d,%eax
jge    1275 <leg_func_deriv+0x145>
movswq %cx,%rcx
mov    (%r12,%rcx,8),%rsi
movsd  (%rsi,%rcx,8),%xmm1
jmp    1220 <leg_func_deriv+0xf0>
test   %r15d,%r15d
jle    1399 <leg_func_deriv+0x269>
xor    %r8d,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r8,%r8,1),%ecx
movslq %ecx,%rsi
movslq %r8d,%r9
mov    (%r14,%r9,8),%rdi
movsd  (%rdi,%r9,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rdx,%r9,8),%xmm2
mulsd  %xmm5,%xmm2
addsd  %xmm1,%xmm2
mulsd  0x18(%r13,%rsi,8),%xmm2
lea    0x1(%r9),%edx
mov    0x8(%r12,%r9,8),%rsi
movsd  %xmm2,(%rsi,%r9,8)
movswl %dx,%edx
cmp    %r15d,%edx
jge    1380 <leg_func_deriv+0x250>
nopl   0x0(%rax,%rax,1)
lea    (%rdx,%rdx,1),%edi
lea    (%rdx,%r8,1),%ebp
movslq %edx,%rsi
sub    %r8d,%edx
movswq %di,%rax
movsd  0x18(%r13,%rax,8),%xmm1
movswq %bp,%rbp
movswl %di,%edi
divsd  0x8(%r13,%rbp,8),%xmm1
movswq %dx,%rdx
or     $0x1,%edi
mov    -0x8(%r12,%rsi,8),%r10
mov    (%r12,%rsi,8),%rcx
mov    (%r14,%rsi,8),%rbx
movslq %edi,%rdi
movsd  (%rbx,%r9,8),%xmm2
movsd  (%rcx,%r9,8),%xmm3
movsd  0x0(%r13,%rdx,8),%xmm4
mulsd  %xmm0,%xmm2
mulsd  0x0(%r13,%rbp,8),%xmm4
divsd  0x8(%r13,%rdx,8),%xmm1
mulsd  %xmm5,%xmm3
divsd  -0x8(%r13,%rax,8),%xmm4
addsd  %xmm2,%xmm3
mulsd  0x0(%r13,%rdi,8),%xmm3
mulsd  (%r10,%r9,8),%xmm4
subsd  %xmm4,%xmm3
mov    0x8(%r12,%rsi,8),%rax
mulsd  %xmm1,%xmm3
movsd  %xmm3,(%rax,%r9,8)
add    $0x1,%esi
movswl %si,%edx
cmp    %r15d,%edx
jl     12e0 <leg_func_deriv+0x1b0>
lea    0x1(%r8),%eax
movswl %ax,%r8d
cmp    %r15d,%r8d
jge    1399 <leg_func_deriv+0x269>
movslq %r8d,%rax
mov    (%r12,%rax,8),%rdx
jmp    1290 <leg_func_deriv+0x160>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @leg_func_deriv(double %0, i32 %1, double** %2, double** %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca double**
%8 = alloca double**
%9 = alloca i16
%10 = alloca i16
%11 = alloca double
%12 = alloca double*
%13 = alloca i16
%14 = alloca i16
%15 = alloca i16
store double %0, double* %5
store i32 %1, i32* %6
store double** %2, double*** %7
store double** %3, double*** %8
%16 = load i32, i32* %6
%17 = mul nsw i32 2, %16
%18 = add nsw i32 %17, 4
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to double*
store double* %23, double** %12
store i16 0, i16* %13
br label %24
24: ; preds = %39, %4
%25 = load i16, i16* %13
%26 = sext i16 %25 to i32
%27 = load i32, i32* %6
%28 = mul nsw i32 2, %27
%29 = add nsw i32 %28, 4
%30 = icmp slt i32 %26, %29
br i1 %30, label %31, label %42
31: ; preds = %24
%32 = load i16, i16* %13
%33 = sitofp i16 %32 to double
%34 = call double @sqrt(double %33)
%35 = load double*, double** %12
%36 = load i16, i16* %13
%37 = sext i16 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
store double %34, double* %38
br label %39
39: ; preds = %31
%40 = load i16, i16* %13
%41 = add i16 %40, 1
store i16 %41, i16* %13
br label %24
42: ; preds = %24
%43 = load double, double* %5
%44 = load double, double* %5
%45 = fneg double %43
%46 = call double @llvm.fmuladd.f64(double %45, double %44, double 1.000000e+00)
%47 = call double @sqrt(double %46)
store double %47, double* %11
%48 = load double**, double*** %8
%49 = getelementptr inbounds double*, double** %48, i64 0
%50 = load double*, double** %49
%51 = getelementptr inbounds double, double* %50, i64 0
store double 0.000000e+00, double* %51
%52 = load double*, double** %12
%53 = getelementptr inbounds double, double* %52, i64 3
%54 = load double, double* %53
%55 = fneg double %54
%56 = load double, double* %5
%57 = fmul double %55, %56
%58 = load double**, double*** %8
%59 = getelementptr inbounds double*, double** %58, i64 1
%60 = load double*, double** %59
%61 = getelementptr inbounds double, double* %60, i64 1
store double %57, double* %61
store i16 1, i16* %9
br label %62
62: ; preds = %121, %42
%63 = load i16, i16* %9
%64 = sext i16 %63 to i32
%65 = load i32, i32* %6
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %124
67: ; preds = %62
%68 = load double*, double** %12
%69 = load i16, i16* %9
%70 = sext i16 %69 to i32
%71 = mul nsw i32 2, %70
%72 = add nsw i32 %71, 3
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %68, i64 %73
%75 = load double, double* %74
%76 = load double*, double** %12
%77 = load i16, i16* %9
%78 = sext i16 %77 to i32
%79 = mul nsw i32 2, %78
%80 = add nsw i32 %79, 2
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double, double* %76, i64 %81
%83 = load double, double* %82
%84 = fdiv double %75, %83
%85 = load double, double* %11
%86 = load double**, double*** %8
%87 = load i16, i16* %9
%88 = sext i16 %87 to i64
%89 = getelementptr inbounds double*, double** %86, i64 %88
%90 = load double*, double** %89
%91 = load i16, i16* %9
%92 = sext i16 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
%94 = load double, double* %93
%95 = load double, double* %5
%96 = load double**, double*** %7
%97 = load i16, i16* %9
%98 = sext i16 %97 to i64
%99 = getelementptr inbounds double*, double** %96, i64 %98
%100 = load double*, double** %99
%101 = load i16, i16* %9
%102 = sext i16 %101 to i64
%103 = getelementptr inbounds double, double* %100, i64 %102
%104 = load double, double* %103
%105 = fmul double %95, %104
%106 = fneg double %105
%107 = call double @llvm.fmuladd.f64(double %85, double %94, double %106)
%108 = fmul double %84, %107
%109 = load double**, double*** %8
%110 = load i16, i16* %9
%111 = sext i16 %110 to i32
%112 = add nsw i32 %111, 1
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds double*, double** %109, i64 %113
%115 = load double*, double** %114
%116 = load i16, i16* %9
%117 = sext i16 %116 to i32
%118 = add nsw i32 %117, 1
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds double, double* %115, i64 %119
store double %108, double* %120
br label %121
121: ; preds = %67
%122 = load i16, i16* %9
%123 = add i16 %122, 1
store i16 %123, i16* %9
br label %62
124: ; preds = %62
store i16 0, i16* %10
br label %125
125: ; preds = %298, %124
%126 = load i16, i16* %10
%127 = sext i16 %126 to i32
%128 = load i32, i32* %6
%129 = icmp slt i32 %127, %128
br i1 %129, label %130, label %301
130: ; preds = %125
%131 = load double*, double** %12
%132 = load i16, i16* %10
%133 = sext i16 %132 to i32
%134 = mul nsw i32 2, %133
%135 = add nsw i32 %134, 3
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds double, double* %131, i64 %136
%138 = load double, double* %137
%139 = load double, double* %5
%140 = load double**, double*** %8
%141 = load i16, i16* %10
%142 = sext i16 %141 to i64
%143 = getelementptr inbounds double*, double** %140, i64 %142
%144 = load double*, double** %143
%145 = load i16, i16* %10
%146 = sext i16 %145 to i64
%147 = getelementptr inbounds double, double* %144, i64 %146
%148 = load double, double* %147
%149 = load double, double* %11
%150 = load double**, double*** %7
%151 = load i16, i16* %10
%152 = sext i16 %151 to i64
%153 = getelementptr inbounds double*, double** %150, i64 %152
%154 = load double*, double** %153
%155 = load i16, i16* %10
%156 = sext i16 %155 to i64
%157 = getelementptr inbounds double, double* %154, i64 %156
%158 = load double, double* %157
%159 = fmul double %149, %158
%160 = call double @llvm.fmuladd.f64(double %139, double %148, double %159)
%161 = fmul double %138, %160
%162 = load double**, double*** %8
%163 = load i16, i16* %10
%164 = sext i16 %163 to i32
%165 = add nsw i32 %164, 1
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds double*, double** %162, i64 %166
%168 = load double*, double** %167
%169 = load i16, i16* %10
%170 = sext i16 %169 to i64
%171 = getelementptr inbounds double, double* %168, i64 %170
store double %161, double* %171
%172 = load i16, i16* %10
%173 = sext i16 %172 to i32
%174 = add nsw i32 %173, 1
%175 = trunc i32 %174 to i16
store i16 %175, i16* %9
br label %176
176: ; preds = %294, %130
%177 = load i16, i16* %9
%178 = sext i16 %177 to i32
%179 = load i32, i32* %6
%180 = icmp slt i32 %178, %179
br i1 %180, label %181, label %297
181: ; preds = %176
%182 = load i16, i16* %9
%183 = sext i16 %182 to i32
%184 = mul nsw i32 2, %183
%185 = trunc i32 %184 to i16
store i16 %185, i16* %13
%186 = load i16, i16* %9
%187 = sext i16 %186 to i32
%188 = load i16, i16* %10
%189 = sext i16 %188 to i32
%190 = add nsw i32 %187, %189
%191 = trunc i32 %190 to i16
store i16 %191, i16* %14
%192 = load i16, i16* %9
%193 = sext i16 %192 to i32
%194 = load i16, i16* %10
%195 = sext i16 %194 to i32
%196 = sub nsw i32 %193, %195
%197 = trunc i32 %196 to i16
store i16 %197, i16* %15
%198 = load double*, double** %12
%199 = load i16, i16* %13
%200 = sext i16 %199 to i32
%201 = add nsw i32 %200, 3
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds double, double* %198, i64 %202
%204 = load double, double* %203
%205 = load double*, double** %12
%206 = load i16, i16* %14
%207 = sext i16 %206 to i32
%208 = add nsw i32 %207, 1
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds double, double* %205, i64 %209
%211 = load double, double* %210
%212 = fdiv double %204, %211
%213 = load double*, double** %12
%214 = load i16, i16* %15
%215 = sext i16 %214 to i32
%216 = add nsw i32 %215, 1
%217 = sext i32 %216 to i64
%218 = getelementptr inbounds double, double* %213, i64 %217
%219 = load double, double* %218
%220 = fdiv double %212, %219
%221 = load double*, double** %12
%222 = load i16, i16* %13
%223 = sext i16 %222 to i32
%224 = add nsw i32 %223, 1
%225 = sext i32 %224 to i64
%226 = getelementptr inbounds double, double* %221, i64 %225
%227 = load double, double* %226
%228 = load double, double* %5
%229 = load double**, double*** %8
%230 = load i16, i16* %9
%231 = sext i16 %230 to i64
%232 = getelementptr inbounds double*, double** %229, i64 %231
%233 = load double*, double** %232
%234 = load i16, i16* %10
%235 = sext i16 %234 to i64
%236 = getelementptr inbounds double, double* %233, i64 %235
%237 = load double, double* %236
%238 = load double, double* %11
%239 = load double**, double*** %7
%240 = load i16, i16* %9
%241 = sext i16 %240 to i64
%242 = getelementptr inbounds double*, double** %239, i64 %241
%243 = load double*, double** %242
%244 = load i16, i16* %10
%245 = sext i16 %244 to i64
%246 = getelementptr inbounds double, double* %243, i64 %245
%247 = load double, double* %246
%248 = fmul double %238, %247
%249 = call double @llvm.fmuladd.f64(double %228, double %237, double %248)
%250 = load double*, double** %12
%251 = load i16, i16* %14
%252 = sext i16 %251 to i64
%253 = getelementptr inbounds double, double* %250, i64 %252
%254 = load double, double* %253
%255 = load double*, double** %12
%256 = load i16, i16* %15
%257 = sext i16 %256 to i64
%258 = getelementptr inbounds double, double* %255, i64 %257
%259 = load double, double* %258
%260 = fmul double %254, %259
%261 = load double*, double** %12
%262 = load i16, i16* %13
%263 = sext i16 %262 to i32
%264 = sub nsw i32 %263, 1
%265 = sext i32 %264 to i64
%266 = getelementptr inbounds double, double* %261, i64 %265
%267 = load double, double* %266
%268 = fdiv double %260, %267
%269 = load double**, double*** %8
%270 = load i16, i16* %9
%271 = sext i16 %270 to i32
%272 = sub nsw i32 %271, 1
%273 = sext i32 %272 to i64
%274 = getelementptr inbounds double*, double** %269, i64 %273
%275 = load double*, double** %274
%276 = load i16, i16* %10
%277 = sext i16 %276 to i64
%278 = getelementptr inbounds double, double* %275, i64 %277
%279 = load double, double* %278
%280 = fmul double %268, %279
%281 = fneg double %280
%282 = call double @llvm.fmuladd.f64(double %227, double %249, double %281)
%283 = fmul double %220, %282
%284 = load double**, double*** %8
%285 = load i16, i16* %9
%286 = sext i16 %285 to i32
%287 = add nsw i32 %286, 1
%288 = sext i32 %287 to i64
%289 = getelementptr inbounds double*, double** %284, i64 %288
%290 = load double*, double** %289
%291 = load i16, i16* %10
%292 = sext i16 %291 to i64
%293 = getelementptr inbounds double, double* %290, i64 %292
store double %283, double* %293
br label %294
294: ; preds = %181
%295 = load i16, i16* %9
%296 = add i16 %295, 1
store i16 %296, i16* %9
br label %176
297: ; preds = %176
br label %298
298: ; preds = %297
%299 = load i16, i16* %10
%300 = add i16 %299, 1
store i16 %300, i16* %10
br label %125
301: ; preds = %125
%302 = load double*, double** %12
%303 = call i32 @free(double* %302)
ret i32 0
}

LLVM IR (-O2):
define i32 @leg_func_deriv(double %0, i32 %1, double** nocapture %2, double** nocapture %3) {
%5 = shl nsw i32 %1, 1
%6 = add nsw i32 %5, 4
%7 = shl i32 %6, 3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = icmp sgt i32 %1, -2
br i1 %10, label %11, label %20
11: ; preds = %4, %11
%12 = phi i16 [ %17, %11 ], [ 0, %4 ]
%13 = sitofp i16 %12 to double
%14 = tail call double @sqrt(double %13)
%15 = sext i16 %12 to i64
%16 = getelementptr inbounds double, double* %9, i64 %15
store double %14, double* %16
%17 = add i16 %12, 1
%18 = sext i16 %17 to i32
%19 = icmp sgt i32 %6, %18
br i1 %19, label %11, label %20
20: ; preds = %11, %4
%21 = fneg double %0
%22 = tail call double @llvm.fmuladd.f64(double %21, double %0, double 1.000000e+00)
%23 = tail call double @sqrt(double %22)
%24 = load double*, double** %3
store double 0.000000e+00, double* %24
%25 = getelementptr inbounds double, double* %9, i64 3
%26 = load double, double* %25
%27 = fneg double %26
%28 = fmul double %27, %0
%29 = getelementptr inbounds double*, double** %3, i64 1
%30 = load double*, double** %29
%31 = getelementptr inbounds double, double* %30, i64 1
store double %28, double* %31
%32 = icmp sgt i32 %1, 1
br i1 %32, label %35, label %33
33: ; preds = %35, %20
%34 = icmp sgt i32 %1, 0
br i1 %34, label %72, label %172
35: ; preds = %20, %66
%36 = phi double [ %71, %66 ], [ %28, %20 ]
%37 = phi i32 [ %64, %66 ], [ 1, %20 ]
%38 = trunc i32 %37 to i16
%39 = shl nsw i32 %37, 1
%40 = add nsw i32 %39, 3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %9, i64 %41
%43 = load double, double* %42
%44 = add nsw i32 %39, 2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %9, i64 %45
%47 = load double, double* %46
%48 = fdiv double %43, %47
%49 = sext i32 %37 to i64
%50 = getelementptr inbounds double*, double** %2, i64 %49
%51 = load double*, double** %50
%52 = getelementptr inbounds double, double* %51, i64 %49
%53 = load double, double* %52
%54 = fneg double %53
%55 = fmul double %54, %0
%56 = tail call double @llvm.fmuladd.f64(double %23, double %36, double %55)
%57 = fmul double %48, %56
%58 = add nsw i32 %37, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double*, double** %3, i64 %59
%61 = load double*, double** %60
%62 = getelementptr inbounds double, double* %61, i64 %59
store double %57, double* %62
%63 = add i16 %38, 1
%64 = sext i16 %63 to i32
%65 = icmp slt i32 %64, %1
br i1 %65, label %66, label %33
66: ; preds = %35
%67 = sext i16 %63 to i64
%68 = getelementptr inbounds double*, double** %3, i64 %67
%69 = load double*, double** %68
%70 = getelementptr inbounds double, double* %69, i64 %67
%71 = load double, double* %70
br label %35
72: ; preds = %33, %168
%73 = phi double* [ %171, %168 ], [ %24, %33 ]
%74 = phi i32 [ %166, %168 ], [ 0, %33 ]
%75 = trunc i32 %74 to i16
%76 = shl nsw i32 %74, 1
%77 = add nsw i32 %76, 3
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %9, i64 %78
%80 = load double, double* %79
%81 = sext i32 %74 to i64
%82 = getelementptr inbounds double, double* %73, i64 %81
%83 = load double, double* %82
%84 = getelementptr inbounds double*, double** %2, i64 %81
%85 = load double*, double** %84
%86 = getelementptr inbounds double, double* %85, i64 %81
%87 = load double, double* %86
%88 = fmul double %23, %87
%89 = tail call double @llvm.fmuladd.f64(double %0, double %83, double %88)
%90 = fmul double %80, %89
%91 = add nsw i32 %74, 1
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double*, double** %3, i64 %92
%94 = load double*, double** %93
%95 = getelementptr inbounds double, double* %94, i64 %81
store double %90, double* %95
%96 = shl i32 %91, 16
%97 = ashr exact i32 %96, 16
%98 = icmp slt i32 %97, %1
br i1 %98, label %99, label %164
99: ; preds = %72, %99
%100 = phi i32 [ %162, %99 ], [ %97, %72 ]
%101 = trunc i32 %100 to i16
%102 = shl i16 %101, 1
%103 = add i16 %101, %75
%104 = sub i16 %101, %75
%105 = sext i16 %102 to i32
%106 = add nsw i32 %105, 3
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double, double* %9, i64 %107
%109 = load double, double* %108
%110 = sext i16 %103 to i64
%111 = add nsw i64 %110, 1
%112 = getelementptr inbounds double, double* %9, i64 %111
%113 = load double, double* %112
%114 = fdiv double %109, %113
%115 = sext i16 %104 to i64
%116 = add nsw i64 %115, 1
%117 = getelementptr inbounds double, double* %9, i64 %116
%118 = load double, double* %117
%119 = fdiv double %114, %118
%120 = or i32 %105, 1
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds double, double* %9, i64 %121
%123 = load double, double* %122
%124 = sext i32 %100 to i64
%125 = getelementptr inbounds double*, double** %3, i64 %124
%126 = load double*, double** %125
%127 = getelementptr inbounds double, double* %126, i64 %81
%128 = load double, double* %127
%129 = getelementptr inbounds double*, double** %2, i64 %124
%130 = load double*, double** %129
%131 = getelementptr inbounds double, double* %130, i64 %81
%132 = load double, double* %131
%133 = fmul double %23, %132
%134 = tail call double @llvm.fmuladd.f64(double %0, double %128, double %133)
%135 = getelementptr inbounds double, double* %9, i64 %110
%136 = load double, double* %135
%137 = getelementptr inbounds double, double* %9, i64 %115
%138 = load double, double* %137
%139 = add nsw i32 %105, -1
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds double, double* %9, i64 %140
%142 = load double, double* %141
%143 = add nsw i32 %100, -1
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds double*, double** %3, i64 %144
%146 = load double*, double** %145
%147 = getelementptr inbounds double, double* %146, i64 %81
%148 = load double, double* %147
%149 = fneg double %136
%150 = fmul double %138, %149
%151 = fdiv double %150, %142
%152 = fmul double %151, %148
%153 = tail call double @llvm.fmuladd.f64(double %123, double %134, double %152)
%154 = fmul double %119, %153
%155 = add nsw i32 %100, 1
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds double*, double** %3, i64 %156
%158 = load double*, double** %157
%159 = getelementptr inbounds double, double* %158, i64 %81
store double %154, double* %159
%160 = shl nsw i32 %100, 16
%161 = add i32 %160, 65536
%162 = ashr exact i32 %161, 16
%163 = icmp slt i32 %162, %1
br i1 %163, label %99, label %164
164: ; preds = %99, %72
%165 = add i16 %75, 1
%166 = sext i16 %165 to i32
%167 = icmp slt i32 %166, %1
br i1 %167, label %168, label %172
168: ; preds = %164
%169 = sext i16 %165 to i64
%170 = getelementptr inbounds double*, double** %3, i64 %169
%171 = load double*, double** %170
br label %72
172: ; preds = %164, %33
%173 = tail call i32 @free(double* %9)
ret i32 0
}