#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main() {
  int *p, a;
  p = (int *)malloc(sizeof(int) * 10);
  if (p == NULL) {
    fprintf(stderr, "Unable to initialize memory\n");
    exit(1);
  }
  printf("10 pointers allocated at location %p\n", p);
  for (a = 0; a < 10; a++) {
    *(p + a) = a * 20;
    printf("%d\n", *(p + a));
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1187 <main+0x47>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11e0 <main+0xa0>
imul   $0x14,-0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a0 <main+0x60>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x28,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1254 <main+0x114>
mov    %rax,%rbx
lea    0xebc(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x0,(%rbx)
lea    0xecb(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x14,0x4(%rbx)
mov    %r14,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x28,0x8(%rbx)
mov    %r14,%rdi
mov    $0x28,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x3c,0xc(%rbx)
mov    %r14,%rdi
mov    $0x3c,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x50,0x10(%rbx)
mov    %r14,%rdi
mov    $0x50,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x64,0x14(%rbx)
mov    %r14,%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x78,0x18(%rbx)
mov    %r14,%rdi
mov    $0x78,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x8c,0x1c(%rbx)
mov    %r14,%rdi
mov    $0x8c,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0xa0,0x20(%rbx)
mov    %r14,%rdi
mov    $0xa0,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0xb4,0x24(%rbx)
mov    %r14,%rdi
mov    $0xb4,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Unable to initialize memory\0A\00"
@.str.1 = [38 x i8] c"10 pointers allocated at location %p\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 @malloc(i32 40)
%5 = inttoptr i64 %4 to i32*
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32*, i32** %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32* %13)
store i32 0, i32* %3
br label %15
15: ; preds = %31, %12
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 10
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = load i32, i32* %3
%20 = mul nsw i32 %19, 20
%21 = load i32*, i32** %2
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
store i32 %20, i32* %24
%25 = load i32*, i32** %2
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %18
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %15
34: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Unable to initialize memory\0A\00"
@.str.1 = [38 x i8] c"10 pointers allocated at location %p\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 40)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 0, i32* %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%11 = getelementptr inbounds i32, i32* %2, i64 1
store i32 20, i32* %11
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 20)
%13 = getelementptr inbounds i32, i32* %2, i64 2
store i32 40, i32* %13
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 40)
%15 = getelementptr inbounds i32, i32* %2, i64 3
store i32 60, i32* %15
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 60)
%17 = getelementptr inbounds i32, i32* %2, i64 4
store i32 80, i32* %17
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 80)
%19 = getelementptr inbounds i32, i32* %2, i64 5
store i32 100, i32* %19
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 100)
%21 = getelementptr inbounds i32, i32* %2, i64 6
store i32 120, i32* %21
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 120)
%23 = getelementptr inbounds i32, i32* %2, i64 7
store i32 140, i32* %23
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 140)
%25 = getelementptr inbounds i32, i32* %2, i64 8
store i32 160, i32* %25
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 160)
%27 = getelementptr inbounds i32, i32* %2, i64 9
store i32 180, i32* %27
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 180)
ret i32 0
}