#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__ malloc(int);
int rand();
int create_array(int **arr, int size) {
  int i = 0;
  *arr = (int *)malloc(sizeof(int) * size);
  for (i = 0; i < size; i++) {
    *((*arr) + i) = rand() % 127;
  }
}


x86 assembly (clang, -O0):
<create_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118d <create_array+0x6d>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x7f,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1156 <create_array+0x36>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_array>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x0(,%r14,4),%edi
call   1030 <malloc@plt>
mov    %rax,(%r15)
test   %r14d,%r14d
jle    1188 <create_array+0x68>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffff81020409,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x6,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x7,%edx
sub    %edx,%ecx
add    %eax,%ecx
mov    (%r15),%rax
mov    %ecx,(%rax,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <create_array+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @create_array(i32** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32
store i32** %0, i32*** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = load i32**, i32*** %4
store i32* %12, i32** %13
store i32 0, i32* %6
br label %14
14: ; preds = %26, %2
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 127
%21 = load i32**, i32*** %4
%22 = load i32*, i32** %21
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %20, i32* %25
br label %26
26: ; preds = %18
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %14
29: ; preds = %14
%30 = load i32, i32* %3
ret i32 %30
}

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