#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int *p, i;
  p = (int *)malloc(sizeof(int) * 20);
  if (p == NULL) {
    fprintf(stderr, "mem allocation failed!\n");
    exit(1);
  }
  for (i = 1; i <= 20; i++) {
    *(p + i - 1) = i;
    printf("i: %d\n", *(p + i - 1));
  }
  free(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119e <main+0x4e>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jg     11e4 <main+0x94>
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,-0x4(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    -0x4(%rax,%rcx,4),%esi
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a5 <main+0x55>
mov    -0x18(%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    $0x50,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1312 <main+0x1c2>
mov    %rax,%rbx
movl   $0x1,(%rax)
lea    0xea1(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
movl   $0x2,0x4(%rbx)
mov    %r14,%rdi
mov    $0x2,%esi
call   1040 <printf@plt>
movl   $0x3,0x8(%rbx)
mov    %r14,%rdi
mov    $0x3,%esi
call   1040 <printf@plt>
movl   $0x4,0xc(%rbx)
mov    %r14,%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
movl   $0x5,0x10(%rbx)
mov    %r14,%rdi
mov    $0x5,%esi
call   1040 <printf@plt>
movl   $0x6,0x14(%rbx)
mov    %r14,%rdi
mov    $0x6,%esi
call   1040 <printf@plt>
movl   $0x7,0x18(%rbx)
mov    %r14,%rdi
mov    $0x7,%esi
call   1040 <printf@plt>
movl   $0x8,0x1c(%rbx)
mov    %r14,%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
movl   $0x9,0x20(%rbx)
mov    %r14,%rdi
mov    $0x9,%esi
call   1040 <printf@plt>
movl   $0xa,0x24(%rbx)
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
movl   $0xb,0x28(%rbx)
mov    %r14,%rdi
mov    $0xb,%esi
call   1040 <printf@plt>
movl   $0xc,0x2c(%rbx)
mov    %r14,%rdi
mov    $0xc,%esi
call   1040 <printf@plt>
movl   $0xd,0x30(%rbx)
mov    %r14,%rdi
mov    $0xd,%esi
call   1040 <printf@plt>
movl   $0xe,0x34(%rbx)
mov    %r14,%rdi
mov    $0xe,%esi
call   1040 <printf@plt>
movl   $0xf,0x38(%rbx)
mov    %r14,%rdi
mov    $0xf,%esi
call   1040 <printf@plt>
movl   $0x10,0x3c(%rbx)
mov    %r14,%rdi
mov    $0x10,%esi
call   1040 <printf@plt>
movl   $0x11,0x40(%rbx)
mov    %r14,%rdi
mov    $0x11,%esi
call   1040 <printf@plt>
movl   $0x12,0x44(%rbx)
mov    %r14,%rdi
mov    $0x12,%esi
call   1040 <printf@plt>
movl   $0x13,0x48(%rbx)
mov    %r14,%rdi
mov    $0x13,%esi
call   1040 <printf@plt>
movl   $0x14,0x4c(%rbx)
mov    %r14,%rdi
mov    $0x14,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
lea    0xcde(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"mem allocation failed!\0A\00"
@.str.1 = [7 x i8] c"i: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 80)
%4 = inttoptr i64 %3 to i32*
%5 = icmp eq i64 %3, 0
br i1 %5, label %47, label %6
6: ; preds = %2
store i32 1, i32* %4
%7 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%8 = getelementptr inbounds i32, i32* %4, i64 1
store i32 2, i32* %8
%9 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2)
%10 = getelementptr inbounds i32, i32* %4, i64 2
store i32 3, i32* %10
%11 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 3)
%12 = getelementptr inbounds i32, i32* %4, i64 3
store i32 4, i32* %12
%13 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 4)
%14 = getelementptr inbounds i32, i32* %4, i64 4
store i32 5, i32* %14
%15 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 5)
%16 = getelementptr inbounds i32, i32* %4, i64 5
store i32 6, i32* %16
%17 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%18 = getelementptr inbounds i32, i32* %4, i64 6
store i32 7, i32* %18
%19 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 7)
%20 = getelementptr inbounds i32, i32* %4, i64 7
store i32 8, i32* %20
%21 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 8)
%22 = getelementptr inbounds i32, i32* %4, i64 8
store i32 9, i32* %22
%23 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 9)
%24 = getelementptr inbounds i32, i32* %4, i64 9
store i32 10, i32* %24
%25 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 10)
%26 = getelementptr inbounds i32, i32* %4, i64 10
store i32 11, i32* %26
%27 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 11)
%28 = getelementptr inbounds i32, i32* %4, i64 11
store i32 12, i32* %28
%29 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 12)
%30 = getelementptr inbounds i32, i32* %4, i64 12
store i32 13, i32* %30
%31 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 13)
%32 = getelementptr inbounds i32, i32* %4, i64 13
store i32 14, i32* %32
%33 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 14)
%34 = getelementptr inbounds i32, i32* %4, i64 14
store i32 15, i32* %34
%35 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 15)
%36 = getelementptr inbounds i32, i32* %4, i64 15
store i32 16, i32* %36
%37 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 16)
%38 = getelementptr inbounds i32, i32* %4, i64 16
store i32 17, i32* %38
%39 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 17)
%40 = getelementptr inbounds i32, i32* %4, i64 17
store i32 18, i32* %40
%41 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 18)
%42 = getelementptr inbounds i32, i32* %4, i64 18
store i32 19, i32* %42
%43 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 19)
%44 = getelementptr inbounds i32, i32* %4, i64 19
store i32 20, i32* %44
%45 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 20)
%46 = tail call i32 @free(i32* %4)
ret i32 0
47: ; preds = %2
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%50 = tail call i32 @exit(i32 1)
unreachable
}