#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 /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  int arr_stack[10] = {0};
  int *arr_heap = (int *)malloc(sizeof(int) * 10);
  if (arr_heap == NULL) {
    printf("Out of memory\n");
    return -1;
  }
  *arr_stack = 100;
  *(arr_stack + 1) = 101;
  arr_stack[2] = 103;
  arr_stack[3] = 104;
  for (int i = 0; i < 10; i++) {
    *(arr_heap + i) = 100 + i;
  }
  free(arr_heap);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1197 <main+0x57>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <main+0xb3>
movl   $0x64,-0x40(%rbp)
movl   $0x65,-0x3c(%rbp)
movl   $0x67,-0x38(%rbp)
movl   $0x68,-0x34(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0xa,-0x4c(%rbp)
jge    11e3 <main+0xa3>
mov    -0x4c(%rbp),%edx
add    $0x64,%edx
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11ba <main+0x7a>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x28,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     116f <main+0x3f>
movaps 0xeb9(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xebf(%rip),%xmm0
movups %xmm0,0x10(%rax)
movabs $0x6d0000006c,%rcx
mov    %rcx,0x20(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xeaa(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i32]
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [10 x i32]* %6 to i8*
%10 = call i64 @malloc(i32 40)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
16: ; preds = %2
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
store i32 100, i32* %17
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%19 = getelementptr inbounds i32, i32* %18, i64 1
store i32 101, i32* %19
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 2
store i32 103, i32* %20
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 3
store i32 104, i32* %21
store i32 0, i32* %8
br label %22
22: ; preds = %32, %16
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 10
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i32, i32* %8
%27 = add nsw i32 100, %26
%28 = load i32*, i32** %7
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %25
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %22
35: ; preds = %22
%36 = load i32*, i32** %7
%37 = call i32 @free(i32* %36)
store i32 0, i32* %3
br label %38
38: ; preds = %35, %14
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@str = [14 x i8] c"Out of memory\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 40)
%4 = inttoptr i64 %3 to i32*
%5 = icmp eq i64 %3, 0
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = inttoptr i64 %3 to <4 x i32>*
store <4 x i32> <i32 100, i32 101, i32 102, i32 103>, <4 x i32>* %7
%8 = getelementptr inbounds i32, i32* %4, i64 4
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 104, i32 105, i32 106, i32 107>, <4 x i32>* %9
%10 = getelementptr inbounds i32, i32* %4, i64 8
store i32 108, i32* %10
%11 = getelementptr inbounds i32, i32* %4, i64 9
store i32 109, i32* %11
%12 = tail call i32 @free(i32* %4)
br label %15
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %6, %13
%16 = phi i32 [ -1, %13 ], [ 0, %6 ]
ret i32 %16
}