#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 */
scalar_t__ calloc(long, int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
double **legendre_dreieck_alloc_neu(int maxdeg) {
  double *lf_kette;
  double *pd;
  double **lf_matrix;
  int grad;
  long anz_func;
  lf_kette = NULL;
  lf_matrix = NULL;
  anz_func = (maxdeg + 1) * (maxdeg + 2) / 2;
  lf_kette = (double *)calloc(anz_func, sizeof(double));
  if (lf_kette == NULL)
    return NULL;
  lf_matrix = (double **)malloc((maxdeg + 1) * sizeof(double *));
  if (lf_matrix == NULL) {
    free(lf_kette);
    return NULL;
  }
  for (grad = 0, pd = lf_kette; grad <= maxdeg; grad++, pd += grad) {
    lf_matrix[grad] = pd;
  }
  return lf_matrix;
}


x86 assembly (clang, -O0):
<legendre_dreieck_alloc_neu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1192 <legendre_dreieck_alloc_neu+0x62>
movq   $0x0,-0x8(%rbp)
jmp    1220 <legendre_dreieck_alloc_neu+0xf0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ca <legendre_dreieck_alloc_neu+0x9a>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1220 <legendre_dreieck_alloc_neu+0xf0>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1218 <legendre_dreieck_alloc_neu+0xe8>
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11d9 <legendre_dreieck_alloc_neu+0xa9>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<legendre_dreieck_alloc_neu>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
lea    0x1(%r14),%r15d
lea    0x2(%r14),%eax
imul   %r15d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     119f <legendre_dreieck_alloc_neu+0x6f>
mov    %rax,%rbx
lea    0x0(,%r15,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11a6 <legendre_dreieck_alloc_neu+0x76>
test   %r14d,%r14d
js     1273 <legendre_dreieck_alloc_neu+0x143>
mov    %r15d,%esi
lea    -0x1(%rsi),%rdx
mov    %esi,%ecx
and    $0x7,%ecx
cmp    $0x7,%rdx
jae    11b5 <legendre_dreieck_alloc_neu+0x85>
xor    %edx,%edx
test   %rcx,%rcx
jne    1250 <legendre_dreieck_alloc_neu+0x120>
jmp    1273 <legendre_dreieck_alloc_neu+0x143>
xor    %eax,%eax
jmp    1273 <legendre_dreieck_alloc_neu+0x143>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1273 <legendre_dreieck_alloc_neu+0x143>
and    $0xfffffff8,%esi
neg    %rsi
mov    $0x4,%edx
mov    %rbx,-0x20(%rax,%rdx,8)
lea    (%rbx,%rdx,8),%rdi
lea    (%rbx,%rdx,8),%rbx
add    $0xffffffffffffffe8,%rbx
mov    %rbx,-0x18(%rax,%rdx,8)
lea    -0x18(%rdi,%rdx,8),%rbx
lea    -0x28(%rdi,%rdx,8),%rdi
mov    %rdi,-0x10(%rax,%rdx,8)
lea    -0x10(%rbx,%rdx,8),%rdi
lea    -0x18(%rbx,%rdx,8),%rbx
mov    %rbx,-0x8(%rax,%rdx,8)
lea    -0x8(%rdi,%rdx,8),%rdi
mov    %rdi,(%rax,%rdx,8)
lea    (%rdi,%rdx,8),%rbx
lea    0x8(%rdi,%rdx,8),%rdi
mov    %rdi,0x8(%rax,%rdx,8)
lea    0x8(%rbx,%rdx,8),%rdi
lea    0x18(%rbx,%rdx,8),%rbx
mov    %rbx,0x10(%rax,%rdx,8)
lea    0x10(%rdi,%rdx,8),%rbx
lea    0x28(%rdi,%rdx,8),%rdi
mov    %rdi,0x18(%rax,%rdx,8)
lea    (%rbx,%rdx,8),%rbx
add    $0x38,%rbx
lea    (%rsi,%rdx,1),%rdi
add    $0x8,%rdi
add    $0x8,%rdx
cmp    $0x4,%rdi
jne    11c0 <legendre_dreieck_alloc_neu+0x90>
add    $0xfffffffffffffffc,%rdx
test   %rcx,%rcx
je     1273 <legendre_dreieck_alloc_neu+0x143>
add    $0x1,%rdx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,-0x8(%rax,%rdx,8)
lea    (%rbx,%rdx,8),%rbx
add    $0x1,%rdx
add    $0xffffffffffffffff,%rcx
jne    1260 <legendre_dreieck_alloc_neu+0x130>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define double** @legendre_dreieck_alloc_neu(i32 %0) {
%2 = add i32 %0, 1
%3 = add nsw i32 %0, 2
%4 = mul nsw i32 %2, %3
%5 = sdiv i32 %4, 2
%6 = sext i32 %5 to i64
%7 = tail call i64 @calloc(i64 %6, i32 8)
%8 = inttoptr i64 %7 to double*
%9 = icmp eq i64 %7, 0
br i1 %9, label %69, label %10
10: ; preds = %1
%11 = shl i32 %2, 3
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double**
%14 = icmp eq i64 %12, 0
br i1 %14, label %24, label %15
15: ; preds = %10
%16 = icmp slt i32 %0, 0
br i1 %16, label %69, label %17
17: ; preds = %15
%18 = zext i32 %2 to i64
%19 = add nsw i64 %18, -1
%20 = and i64 %18, 7
%21 = icmp ult i64 %19, 7
br i1 %21, label %56, label %22
22: ; preds = %17
%23 = and i64 %18, 4294967288
br label %26
24: ; preds = %10
%25 = tail call i32 @free(double* %8)
br label %69
26: ; preds = %26, %22
%27 = phi i64 [ 0, %22 ], [ %52, %26 ]
%28 = phi double* [ %8, %22 ], [ %53, %26 ]
%29 = phi i64 [ 0, %22 ], [ %54, %26 ]
%30 = getelementptr inbounds double*, double** %13, i64 %27
store double* %28, double** %30
%31 = or i64 %27, 1
%32 = getelementptr inbounds double, double* %28, i64 %31
%33 = getelementptr inbounds double*, double** %13, i64 %31
store double* %32, double** %33
%34 = or i64 %27, 2
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = getelementptr inbounds double*, double** %13, i64 %34
store double* %35, double** %36
%37 = or i64 %27, 3
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = getelementptr inbounds double*, double** %13, i64 %37
store double* %38, double** %39
%40 = or i64 %27, 4
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = getelementptr inbounds double*, double** %13, i64 %40
store double* %41, double** %42
%43 = or i64 %27, 5
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = getelementptr inbounds double*, double** %13, i64 %43
store double* %44, double** %45
%46 = or i64 %27, 6
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = getelementptr inbounds double*, double** %13, i64 %46
store double* %47, double** %48
%49 = or i64 %27, 7
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = getelementptr inbounds double*, double** %13, i64 %49
store double* %50, double** %51
%52 = add nuw nsw i64 %27, 8
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = add i64 %29, 8
%55 = icmp eq i64 %54, %23
br i1 %55, label %56, label %26
56: ; preds = %26, %17
%57 = phi i64 [ 0, %17 ], [ %52, %26 ]
%58 = phi double* [ %8, %17 ], [ %53, %26 ]
%59 = icmp eq i64 %20, 0
br i1 %59, label %69, label %60
60: ; preds = %56, %60
%61 = phi i64 [ %65, %60 ], [ %57, %56 ]
%62 = phi double* [ %66, %60 ], [ %58, %56 ]
%63 = phi i64 [ %67, %60 ], [ 0, %56 ]
%64 = getelementptr inbounds double*, double** %13, i64 %61
store double* %62, double** %64
%65 = add nuw nsw i64 %61, 1
%66 = getelementptr inbounds double, double* %62, i64 %65
%67 = add i64 %63, 1
%68 = icmp eq i64 %67, %20
br i1 %68, label %69, label %60
69: ; preds = %56, %60, %15, %1, %24
%70 = phi double** [ null, %24 ], [ null, %1 ], [ %13, %15 ], [ %13, %60 ], [ %13, %56 ]
ret double** %70
}