#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 bspline_quad(double *, int, int, int, int, int, int);
void bspline_gram(double *output, double *knots, int nknots, int m, int dl,
                  int dr) {
  double *result;
  int l, r, i, j;
  int nbasis;
  nbasis = nknots - m;
  result = output;
  for (i = 0; i < nbasis; i++) {
    for (j = 0; j < m; j++) {
      l = i;
      r = l + j;
      *result = bspline_quad(knots, nknots, m, l, r, dl, dr);
      result++;
    }
  }
}


x86 assembly (clang, -O0):
<bspline_gram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    11c9 <bspline_gram+0xb9>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b6 <bspline_gram+0xa6>
mov    -0x34(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x20(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <bspline_quad@plt>
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1159 <bspline_gram+0x49>
jmp    11bb <bspline_gram+0xab>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1146 <bspline_gram+0x36>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bspline_gram>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbp
mov    %edx,%edi
sub    %ecx,%edi
mov    %edi,0x8(%rsp)
test   %edi,%edi
jle    11a7 <bspline_gram+0x97>
mov    %r9d,%r12d
mov    %r8d,%r13d
mov    %ecx,%r14d
xor    %ebx,%ebx
mov    %rsi,0x10(%rsp)
mov    %edx,0xc(%rsp)
jmp    1159 <bspline_gram+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
cmp    0x8(%rsp),%ebx
je     11a7 <bspline_gram+0x97>
test   %r14d,%r14d
jle    1150 <bspline_gram+0x40>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%rbx,%r15,1),%r8d
mov    %r12d,(%rsp)
mov    %rsi,%rdi
mov    %edx,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    %r13d,%r9d
call   1030 <bspline_quad@plt>
mov    0x10(%rsp),%rsi
mov    0xc(%rsp),%edx
movsd  %xmm0,0x0(%rbp)
add    $0x8,%rbp
add    $0x1,%r15d
cmp    %r15d,%r14d
jne    1170 <bspline_gram+0x60>
jmp    1150 <bspline_gram+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @bspline_gram(double* %0, double* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store double* %0, double** %7
store double* %1, double** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%19 = load i32, i32* %9
%20 = load i32, i32* %10
%21 = sub nsw i32 %19, %20
store i32 %21, i32* %18
%22 = load double*, double** %7
store double* %22, double** %13
store i32 0, i32* %16
br label %23
23: ; preds = %52, %6
%24 = load i32, i32* %16
%25 = load i32, i32* %18
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %55
27: ; preds = %23
store i32 0, i32* %17
br label %28
28: ; preds = %48, %27
%29 = load i32, i32* %17
%30 = load i32, i32* %10
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %51
32: ; preds = %28
%33 = load i32, i32* %16
store i32 %33, i32* %14
%34 = load i32, i32* %14
%35 = load i32, i32* %17
%36 = add nsw i32 %34, %35
store i32 %36, i32* %15
%37 = load double*, double** %8
%38 = load i32, i32* %9
%39 = load i32, i32* %10
%40 = load i32, i32* %14
%41 = load i32, i32* %15
%42 = load i32, i32* %11
%43 = load i32, i32* %12
%44 = call double @bspline_quad(double* %37, i32 %38, i32 %39, i32 %40, i32 %41, i32 %42, i32 %43)
%45 = load double*, double** %13
store double %44, double* %45
%46 = load double*, double** %13
%47 = getelementptr inbounds double, double* %46, i32 1
store double* %47, double** %13
br label %48
48: ; preds = %32
%49 = load i32, i32* %17
%50 = add nsw i32 %49, 1
store i32 %50, i32* %17
br label %28
51: ; preds = %28
br label %52
52: ; preds = %51
%53 = load i32, i32* %16
%54 = add nsw i32 %53, 1
store i32 %54, i32* %16
br label %23
55: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @bspline_gram(double* nocapture writeonly %0, double* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = sub i32 %2, %3
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = icmp sgt i32 %3, 0
br label %11
11: ; preds = %9, %22
%12 = phi double* [ %0, %9 ], [ %23, %22 ]
%13 = phi i32 [ 0, %9 ], [ %24, %22 ]
br i1 %10, label %14, label %22
14: ; preds = %11, %14
%15 = phi double* [ %19, %14 ], [ %12, %11 ]
%16 = phi i32 [ %20, %14 ], [ 0, %11 ]
%17 = add nuw nsw i32 %16, %13
%18 = tail call double @bspline_quad(double* %1, i32 %2, i32 %3, i32 %13, i32 %17, i32 %4, i32 %5)
store double %18, double* %15
%19 = getelementptr inbounds double, double* %15, i64 1
%20 = add nuw nsw i32 %16, 1
%21 = icmp eq i32 %20, %3
br i1 %21, label %22, label %14
22: ; preds = %14, %11
%23 = phi double* [ %12, %11 ], [ %19, %14 ]
%24 = add nuw nsw i32 %13, 1
%25 = icmp eq i32 %24, %7
br i1 %25, label %26, label %11
26: ; preds = %22, %6
ret void
}