#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 rand();
int *make_array(int exponent) {
  int *arr = malloc((1 << exponent) * sizeof(int));
  int i;
  for (i = 0; i < (1 << exponent); i++) {
    arr[i] = rand() % (1 << exponent);
  }
  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    $0x2,%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    1193 <make_array+0x73>
mov    $0x0,%al
call   1040 <rand@plt>
mov    -0x4(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <make_array+0x2d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    $0x1,%r15d
mov    $0x1,%ebp
mov    %r14d,%ecx
shl    %cl,%ebp
lea    0x0(,%rbp,4),%edi
call   1030 <malloc@plt>
mov    %rax,%r12
cmp    $0x1f,%r14d
je     1177 <make_array+0x57>
cmp    $0x2,%ebp
cmovge %ebp,%r15d
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %ebp
mov    %edx,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <make_array+0x40>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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, 4
%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 = %25, %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 %28
16: ; preds = %11
%17 = call i32 (...) @rand()
%18 = load i32, i32* %2
%19 = shl i32 1, %18
%20 = srem i32 %17, %19
%21 = load i32*, i32** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
store i32 %20, i32* %24
br label %25
25: ; preds = %16
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %11
28: ; preds = %11
%29 = load i32*, i32** %3
ret i32* %29
}

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