#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 ***malloc(int);
int ***make_array(int exponent) {
  int ***arr = malloc((1 << exponent) * sizeof(int *));
  int i;
  for (i = 0; i < (1 << exponent); i++) {
    if (i == ((1 << exponent) - 1)) {
      arr[i] = (int **)&arr[0];
    } else {
      arr[i] = (int **)&arr[i + 1];
    }
  }
  return arr;
}


x86 assembly (clang, -O0):
<make_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x4(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jge    11b5 <make_array+0xa5>
mov    -0x14(%rbp),%eax
mov    -0x4(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1183 <make_array+0x73>
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11a2 <make_array+0x92>
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11a7 <make_array+0x97>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <make_array+0x2d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_array>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x1,%ebx
mov    $0x1,%ebp
mov    %r14d,%ecx
shl    %cl,%ebp
lea    0x0(,%rbp,8),%edi
call   1030 <malloc@plt>
cmp    $0x1f,%r14d
je     1177 <make_array+0x67>
lea    -0x1(%rbp),%ecx
cmp    $0x2,%ebp
cmovge %ebp,%ebx
xor    %edx,%edx
jmp    1165 <make_array+0x55>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rax,%rdx,8),%rsi
add    $0x8,%rsi
mov    %rsi,(%rax,%rdx,8)
add    $0x1,%rdx
cmp    %rbx,%rdx
je     1177 <make_array+0x67>
cmp    %rcx,%rdx
jne    1150 <make_array+0x40>
mov    %rax,(%rax,%rcx,8)
add    $0x1,%rdx
cmp    %rbx,%rdx
jne    1165 <make_array+0x55>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32*** @make_array(i32 %0) {
%2 = alloca i32
%3 = alloca i32***
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = shl i32 1, %5
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 8
%9 = trunc i64 %8 to i32
%10 = call i32*** @malloc(i32 %9)
store i32*** %10, i32**** %3
store i32 0, i32* %4
br label %11
11: ; preds = %42, %1
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = shl i32 1, %13
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %45
16: ; preds = %11
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = shl i32 1, %18
%20 = sub nsw i32 %19, 1
%21 = icmp eq i32 %17, %20
br i1 %21, label %22, label %30
22: ; preds = %16
%23 = load i32***, i32**** %3
%24 = getelementptr inbounds i32**, i32*** %23, i64 0
%25 = bitcast i32*** %24 to i32**
%26 = load i32***, i32**** %3
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32**, i32*** %26, i64 %28
store i32** %25, i32*** %29
br label %41
30: ; preds = %16
%31 = load i32***, i32**** %3
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32**, i32*** %31, i64 %34
%36 = bitcast i32*** %35 to i32**
%37 = load i32***, i32**** %3
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32**, i32*** %37, i64 %39
store i32** %36, i32*** %40
br label %41
41: ; preds = %30, %22
br label %42
42: ; preds = %41
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %11
45: ; preds = %11
%46 = load i32***, i32**** %3
ret i32*** %46
}

LLVM IR (-O2):
define i32*** @make_array(i32 %0) {
%2 = shl nuw i32 1, %0
%3 = shl i32 %2, 3
%4 = tail call i32*** @malloc(i32 %3)
%5 = icmp eq i32 %0, 31
br i1 %5, label %26, label %6
6: ; preds = %1
%7 = add nsw i32 %2, -1
%8 = zext i32 %7 to i64
%9 = call i32 @llvm.smax.i32(i32 %2, i32 1)
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i32**, i32*** %4, i64 %8
%12 = bitcast i32*** %11 to i32****
br label %13
13: ; preds = %6, %23
%14 = phi i64 [ 0, %6 ], [ %24, %23 ]
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %18
16: ; preds = %13
store i32*** %4, i32**** %12
%17 = add nuw nsw i64 %14, 1
br label %23
18: ; preds = %13
%19 = add nuw nsw i64 %14, 1
%20 = getelementptr inbounds i32**, i32*** %4, i64 %19
%21 = getelementptr inbounds i32**, i32*** %4, i64 %14
%22 = bitcast i32*** %21 to i32****
store i32*** %20, i32**** %22
br label %23
23: ; preds = %16, %18
%24 = phi i64 [ %17, %16 ], [ %19, %18 ]
%25 = icmp eq i64 %24, %10
br i1 %25, label %26, label %13
26: ; preds = %23, %1
ret i32*** %4
}