#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 */
size_t element_length(char);
scalar_t__ malloc(size_t);
void **matrix_pointer_alloc(char *, long, long, char, short);
void ***array_3_pointer_alloc(void *a, long num_rows, long num_cols,
                              long num_levs, char type, short indexing) {
  size_t el;
  long end_row;
  long num_last_dims;
  void ***p;
  char *acurr;
  long j;
  el = element_length(type);
  if (indexing < 0 || indexing > 1)
    return NULL;
  end_row = num_rows + indexing;
  num_last_dims = num_cols * num_levs;
  p = (void ***)malloc((size_t)end_row * sizeof(void **));
  if (p == NULL)
    return NULL;
  if (indexing == 1)
    p[0] = &a;
  acurr = (char *)a;
  for (j = indexing; j < end_row; j++, acurr += (num_last_dims * el)) {
    p[j] = matrix_pointer_alloc(acurr, num_cols, num_levs, type, indexing);
    if (p[j] == NULL)
      return NULL;
  }
  return p;
}


x86 assembly (clang, -O0):
<array_3_pointer_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %r8d,-0x7c(%rbp)
mov    %rcx,%rax
mov    -0x7c(%rbp),%ecx
mov    %rax,-0x78(%rbp)
mov    %rdx,%rax
mov    -0x78(%rbp),%rdx
mov    %rax,-0x70(%rbp)
mov    %rsi,%rax
mov    -0x70(%rbp),%rsi
mov    %rax,-0x68(%rbp)
mov    %rdi,%r8
mov    -0x68(%rbp),%rdi
mov    %r9w,%ax
mov    %r8,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %cl,-0x29(%rbp)
mov    %ax,-0x2c(%rbp)
movsbl -0x29(%rbp),%edi
call   1050 <element_length@plt>
mov    %rax,-0x38(%rbp)
movswl -0x2c(%rbp),%eax
cmp    $0x0,%eax
jl     11a8 <array_3_pointer_alloc+0x78>
movswl -0x2c(%rbp),%eax
cmp    $0x1,%eax
jle    11b5 <array_3_pointer_alloc+0x85>
movq   $0x0,-0x8(%rbp)
jmp    12ac <array_3_pointer_alloc+0x17c>
mov    -0x18(%rbp),%rax
movswq -0x2c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11fb <array_3_pointer_alloc+0xcb>
movq   $0x0,-0x8(%rbp)
jmp    12ac <array_3_pointer_alloc+0x17c>
movswl -0x2c(%rbp),%eax
cmp    $0x1,%eax
jne    1213 <array_3_pointer_alloc+0xe3>
mov    -0x50(%rbp),%rax
lea    -0x10(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
movswq -0x2c(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
cmp    -0x40(%rbp),%rax
jge    12a4 <array_3_pointer_alloc+0x174>
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x29(%rbp),%al
movsbl %al,%ecx
movswl -0x2c(%rbp),%r8d
call   1030 <matrix_pointer_alloc@plt>
mov    %rax,%rdx
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    127d <array_3_pointer_alloc+0x14d>
movq   $0x0,-0x8(%rbp)
jmp    12ac <array_3_pointer_alloc+0x17c>
jmp    1282 <array_3_pointer_alloc+0x152>
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rax
imul   -0x38(%rbp),%rax
add    -0x58(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    1224 <array_3_pointer_alloc+0xf4>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_3_pointer_alloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r13d
mov    %r8d,%r12d
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,0x8(%rsp)
mov    %r8d,%edi
call   1050 <element_length@plt>
cmp    $0x1,%r13w
ja     1200 <array_3_pointer_alloc+0xd0>
mov    %rax,0x10(%rsp)
mov    %rbx,(%rsp)
movzwl %r13w,%r14d
lea    (%r14,%rbp,1),%rax
mov    %rax,0x20(%rsp)
lea    0x0(,%rax,8),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1200 <array_3_pointer_alloc+0xd0>
mov    %rax,%rbx
cmp    $0x1,%r13w
jne    119f <array_3_pointer_alloc+0x6f>
lea    0x8(%rsp),%rax
mov    %rax,(%rbx)
test   %rbp,%rbp
jle    1202 <array_3_pointer_alloc+0xd2>
mov    %r15,0x18(%rsp)
imul   (%rsp),%r15
mov    0x8(%rsp),%rbp
imul   0x10(%rsp),%r15
movsbl %r12b,%r12d
movswl %r13w,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    (%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    %r12d,%ecx
mov    %r13d,%r8d
call   1030 <matrix_pointer_alloc@plt>
mov    %rax,(%rbx,%r14,8)
test   %rax,%rax
je     1200 <array_3_pointer_alloc+0xd0>
add    $0x1,%r14
add    %r15,%rbp
cmp    0x20(%rsp),%r14
jl     11d0 <array_3_pointer_alloc+0xa0>
jmp    1202 <array_3_pointer_alloc+0xd2>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8*** @array_3_pointer_alloc(i8* %0, i64 %1, i64 %2, i64 %3, i8 signext %4, i16 signext %5) {
%7 = alloca i8***
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8
%13 = alloca i16
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i8***
%18 = alloca i8*
%19 = alloca i64
store i8* %0, i8** %8
store i64 %1, i64* %9
store i64 %2, i64* %10
store i64 %3, i64* %11
store i8 %4, i8* %12
store i16 %5, i16* %13
%20 = load i8, i8* %12
%21 = call i64 @element_length(i8 signext %20)
store i64 %21, i64* %14
%22 = load i16, i16* %13
%23 = sext i16 %22 to i32
%24 = icmp slt i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %6
%26 = load i16, i16* %13
%27 = sext i16 %26 to i32
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %25, %6
store i8*** null, i8**** %7
br label %87
30: ; preds = %25
%31 = load i64, i64* %9
%32 = load i16, i16* %13
%33 = sext i16 %32 to i64
%34 = add nsw i64 %31, %33
store i64 %34, i64* %15
%35 = load i64, i64* %10
%36 = load i64, i64* %11
%37 = mul nsw i64 %35, %36
store i64 %37, i64* %16
%38 = load i64, i64* %15
%39 = mul i64 %38, 8
%40 = call i64 @malloc(i64 %39)
%41 = inttoptr i64 %40 to i8***
store i8*** %41, i8**** %17
%42 = load i8***, i8**** %17
%43 = icmp eq i8*** %42, null
br i1 %43, label %44, label %45
44: ; preds = %30
store i8*** null, i8**** %7
br label %87
45: ; preds = %30
%46 = load i16, i16* %13
%47 = sext i16 %46 to i32
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i8***, i8**** %17
%51 = getelementptr inbounds i8**, i8*** %50, i64 0
store i8** %8, i8*** %51
br label %52
52: ; preds = %49, %45
%53 = load i8*, i8** %8
store i8* %53, i8** %18
%54 = load i16, i16* %13
%55 = sext i16 %54 to i64
store i64 %55, i64* %19
br label %56
56: ; preds = %77, %52
%57 = load i64, i64* %19
%58 = load i64, i64* %15
%59 = icmp slt i64 %57, %58
br i1 %59, label %60, label %85
60: ; preds = %56
%61 = load i8*, i8** %18
%62 = load i64, i64* %10
%63 = load i64, i64* %11
%64 = load i8, i8* %12
%65 = load i16, i16* %13
%66 = call i8** @matrix_pointer_alloc(i8* %61, i64 %62, i64 %63, i8 signext %64, i16 signext %65)
%67 = load i8***, i8**** %17
%68 = load i64, i64* %19
%69 = getelementptr inbounds i8**, i8*** %67, i64 %68
store i8** %66, i8*** %69
%70 = load i8***, i8**** %17
%71 = load i64, i64* %19
%72 = getelementptr inbounds i8**, i8*** %70, i64 %71
%73 = load i8**, i8*** %72
%74 = icmp eq i8** %73, null
br i1 %74, label %75, label %76
75: ; preds = %60
store i8*** null, i8**** %7
br label %87
76: ; preds = %60
br label %77
77: ; preds = %76
%78 = load i64, i64* %19
%79 = add nsw i64 %78, 1
store i64 %79, i64* %19
%80 = load i64, i64* %16
%81 = load i64, i64* %14
%82 = mul i64 %80, %81
%83 = load i8*, i8** %18
%84 = getelementptr inbounds i8, i8* %83, i64 %82
store i8* %84, i8** %18
br label %56
85: ; preds = %56
%86 = load i8***, i8**** %17
store i8*** %86, i8**** %7
br label %87
87: ; preds = %85, %75, %44, %29
%88 = load i8***, i8**** %7
ret i8*** %88
}

LLVM IR (-O2):
define i8*** @array_3_pointer_alloc(i8* %0, i64 %1, i64 %2, i64 %3, i8 signext %4, i16 signext %5) {
%7 = alloca i8*
store i8* %0, i8** %7
%8 = tail call i64 @element_length(i8 signext %4)
%9 = icmp ugt i16 %5, 1
br i1 %9, label %36, label %10
10: ; preds = %6
%11 = zext i16 %5 to i64
%12 = add nsw i64 %11, %1
%13 = mul nsw i64 %3, %2
%14 = shl i64 %12, 3
%15 = tail call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8***
%17 = icmp eq i64 %15, 0
br i1 %17, label %36, label %18
18: ; preds = %10
%19 = icmp eq i16 %5, 1
br i1 %19, label %20, label %21
20: ; preds = %18
store i8** %7, i8*** %16
br label %21
21: ; preds = %20, %18
%22 = icmp sgt i64 %1, 0
br i1 %22, label %23, label %36
23: ; preds = %21
%24 = load i8*, i8** %7
%25 = mul i64 %13, %8
br label %26
26: ; preds = %23, %32
%27 = phi i64 [ %11, %23 ], [ %33, %32 ]
%28 = phi i8* [ %24, %23 ], [ %34, %32 ]
%29 = call i8** @matrix_pointer_alloc(i8* %28, i64 %2, i64 %3, i8 signext %4, i16 signext %5)
%30 = getelementptr inbounds i8**, i8*** %16, i64 %27
store i8** %29, i8*** %30
%31 = icmp eq i8** %29, null
br i1 %31, label %36, label %32
32: ; preds = %26
%33 = add nuw nsw i64 %27, 1
%34 = getelementptr inbounds i8, i8* %28, i64 %25
%35 = icmp slt i64 %33, %12
br i1 %35, label %26, label %36
36: ; preds = %26, %32, %21, %10, %6
%37 = phi i8*** [ null, %6 ], [ null, %10 ], [ %16, %21 ], [ null, %26 ], [ %16, %32 ]
ret i8*** %37
}