#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stderr;
int main() {
  int a_size = 10;
  int *a = NULL;
  a = malloc(a_size * sizeof(int));
  if (a == NULL) {
    fprintf(stderr, "Error allocating memory!\n");
    exit(1);
  }
  for (int i = 0; i < a_size; i++) {
    a[i] = i * 10;
  }
  for (int i = 0; i < a_size; i++) {
    printf("a[%d]: %d\n", i, a[i]);
  }
  free(a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ab <main+0x5b>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11db <main+0x8b>
imul   $0xa,-0x14(%rbp),%edx
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    11b2 <main+0x62>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1216 <main+0xc6>
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e2 <main+0x92>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x28,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1254 <main+0x104>
mov    %rax,%r14
movaps 0xe8f(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe95(%rip),%xmm0
movups %xmm0,0x10(%rax)
movabs $0x5a00000050,%rax
mov    %rax,0x20(%r14)
lea    0xea6(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x14,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x1e,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x28,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x32,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0x3c,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
mov    $0x46,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0x50,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    $0x5a,%edx
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Error allocating memory!\0A\00"
@.str.1 = [11 x i8] c"a[%d]: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %2
store i32* null, i32** %3
%6 = load i32, i32* %2
%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
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
store i32 0, i32* %4
br label %18
18: ; preds = %29, %17
%19 = load i32, i32* %4
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %4
%24 = mul nsw i32 %23, 10
%25 = load i32*, i32** %3
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %22
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %18
32: ; preds = %18
store i32 0, i32* %5
br label %33
33: ; preds = %45, %32
%34 = load i32, i32* %5
%35 = load i32, i32* %2
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %33
%38 = load i32, i32* %5
%39 = load i32*, i32** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %43)
br label %45
45: ; preds = %37
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %33
48: ; preds = %33
%49 = load i32*, i32** %3
%50 = call i32 @free(i32* %49)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Error allocating memory!\0A\00"
@.str.1 = [11 x i8] c"a[%d]: %d\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 40)
%2 = icmp eq i32* %1, null
br i1 %2, label %20, label %3
3: ; preds = %0
%4 = bitcast i32* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 10, i32 20, i32 30>, <4 x i32>* %4
%5 = getelementptr inbounds i32, i32* %1, i64 4
%6 = bitcast i32* %5 to <4 x i32>*
store <4 x i32> <i32 40, i32 50, i32 60, i32 70>, <4 x i32>* %6
%7 = getelementptr inbounds i32, i32* %1, i64 8
store i32 80, i32* %7
%8 = getelementptr inbounds i32, i32* %1, i64 9
store i32 90, i32* %8
%9 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 10)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 20)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 30)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 40)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 50)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 6, i32 60)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 7, i32 70)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 8, i32 80)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 9, i32 90)
%19 = tail call i32 @free(i32* %1)
ret i32 0
20: ; preds = %0
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
}