#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);
int legendre_dreieck_alloc(int maxdeg, double ***lf_anker) {
  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 8;
  lf_matrix = (double **)malloc((maxdeg + 1) * sizeof(double *));
  if (lf_matrix == NULL) {
    free(lf_kette);
    return 12;
  }
  for (grad = 0, pd = lf_kette; grad <= maxdeg; grad++, pd += grad) {
    lf_matrix[grad] = pd;
  }
  *lf_anker = lf_matrix;
  return 0;
}


x86 assembly (clang, -O0):
<legendre_dreieck_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    -0x8(%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    1195 <legendre_dreieck_alloc+0x65>
movl   $0x8,-0x4(%rbp)
jmp    122c <legendre_dreieck_alloc+0xfc>
mov    -0x8(%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    11cc <legendre_dreieck_alloc+0x9c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xc,-0x4(%rbp)
jmp    122c <legendre_dreieck_alloc+0xfc>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     121a <legendre_dreieck_alloc+0xea>
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    11db <legendre_dreieck_alloc+0xab>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<legendre_dreieck_alloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x1(%r15),%r12d
lea    0x2(%r15),%eax
imul   %r12d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rdi
mov    $0x8,%ebp
mov    $0x8,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1288 <legendre_dreieck_alloc+0x158>
mov    %rax,%rbx
lea    0x0(,%r12,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ae <legendre_dreieck_alloc+0x7e>
test   %r15d,%r15d
js     1283 <legendre_dreieck_alloc+0x153>
mov    %r12d,%esi
lea    -0x1(%rsi),%rdx
mov    %esi,%ecx
and    $0x7,%ecx
cmp    $0x7,%rdx
jae    11c0 <legendre_dreieck_alloc+0x90>
xor    %edx,%edx
test   %rcx,%rcx
jne    1263 <legendre_dreieck_alloc+0x133>
jmp    1283 <legendre_dreieck_alloc+0x153>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xc,%ebp
jmp    1288 <legendre_dreieck_alloc+0x158>
and    $0xfffffff8,%esi
neg    %rsi
mov    $0x4,%edx
nopl   0x0(%rax,%rax,1)
mov    %rbx,-0x20(%rax,%rdx,8)
lea    (%rbx,%rdx,8),%rdi
lea    (%rbx,%rdx,8),%rbp
add    $0xffffffffffffffe8,%rbp
mov    %rbp,-0x18(%rax,%rdx,8)
lea    -0x18(%rdi,%rdx,8),%rbp
lea    -0x28(%rdi,%rdx,8),%rdi
mov    %rdi,-0x10(%rax,%rdx,8)
lea    -0x10(%rbp,%rdx,8),%rdi
lea    -0x18(%rbp,%rdx,8),%rbp
mov    %rbp,-0x8(%rax,%rdx,8)
lea    -0x8(%rdi,%rdx,8),%rdi
mov    %rdi,(%rax,%rdx,8)
lea    (%rdi,%rdx,8),%rbp
lea    0x8(%rdi,%rdx,8),%rdi
mov    %rdi,0x8(%rax,%rdx,8)
lea    0x8(%rbp,%rdx,8),%rdi
lea    0x18(%rbp,%rdx,8),%rbp
mov    %rbp,0x10(%rax,%rdx,8)
lea    0x10(%rdi,%rdx,8),%rbp
lea    0x28(%rdi,%rdx,8),%rdi
mov    %rdi,0x18(%rax,%rdx,8)
lea    0x38(,%rdx,8),%rbx
add    %rbp,%rbx
lea    (%rsi,%rdx,1),%rdi
add    $0x8,%rdi
add    $0x8,%rdx
cmp    $0x4,%rdi
jne    11d0 <legendre_dreieck_alloc+0xa0>
add    $0xfffffffffffffffc,%rdx
test   %rcx,%rcx
je     1283 <legendre_dreieck_alloc+0x153>
add    $0x1,%rdx
nopw   0x0(%rax,%rax,1)
mov    %rbx,-0x8(%rax,%rdx,8)
lea    (%rbx,%rdx,8),%rbx
add    $0x1,%rdx
add    $0xffffffffffffffff,%rcx
jne    1270 <legendre_dreieck_alloc+0x140>
mov    %rax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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