#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*/ mm_init(int *);
int /*<<< orphan*/ my_free(int *);
scalar_t__ my_malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int *p, i;
  mm_init(p);
  p = (int *)my_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));
  }
  my_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    -0x18(%rbp),%rdi
call   1050 <mm_init@plt>
mov    $0x50,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b7 <main+0x57>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jg     11fd <main+0x9d>
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    0xe2e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11be <main+0x5e>
mov    -0x18(%rbp),%rdi
call   1070 <my_free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
call   1050 <mm_init@plt>
mov    $0x50,%edi
call   1030 <my_malloc@plt>
test   %rax,%rax
je     1327 <main+0x1c7>
mov    %rax,%rbx
movl   $0x1,(%rax)
lea    0xe8c(%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   1070 <my_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
lea    0xcc9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <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 = load i32*, i32** %6
%9 = call i32 @mm_init(i32* %8)
%10 = call i64 @my_malloc(i32 80)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
store i32 1, i32* %7
br label %19
19: ; preds = %36, %18
%20 = load i32, i32* %7
%21 = icmp sle i32 %20, 20
br i1 %21, label %22, label %39
22: ; preds = %19
%23 = load i32, i32* %7
%24 = load i32*, i32** %6
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = getelementptr inbounds i32, i32* %27, i64 -1
store i32 %23, i32* %28
%29 = load i32*, i32** %6
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = getelementptr inbounds i32, i32* %32, i64 -1
%34 = load i32, i32* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %22
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %19
39: ; preds = %19
%40 = load i32*, i32** %6
%41 = call i32 @my_free(i32* %40)
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 i32 @mm_init(i32* undef)
%4 = tail call i64 @my_malloc(i32 80)
%5 = inttoptr i64 %4 to i32*
%6 = icmp eq i64 %4, 0
br i1 %6, label %48, label %7
7: ; preds = %2
store i32 1, i32* %5
%8 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%9 = getelementptr inbounds i32, i32* %5, i64 1
store i32 2, i32* %9
%10 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2)
%11 = getelementptr inbounds i32, i32* %5, i64 2
store i32 3, i32* %11
%12 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 3)
%13 = getelementptr inbounds i32, i32* %5, i64 3
store i32 4, i32* %13
%14 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 4)
%15 = getelementptr inbounds i32, i32* %5, i64 4
store i32 5, i32* %15
%16 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 5)
%17 = getelementptr inbounds i32, i32* %5, i64 5
store i32 6, i32* %17
%18 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%19 = getelementptr inbounds i32, i32* %5, i64 6
store i32 7, i32* %19
%20 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 7)
%21 = getelementptr inbounds i32, i32* %5, i64 7
store i32 8, i32* %21
%22 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 8)
%23 = getelementptr inbounds i32, i32* %5, i64 8
store i32 9, i32* %23
%24 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 9)
%25 = getelementptr inbounds i32, i32* %5, i64 9
store i32 10, i32* %25
%26 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 10)
%27 = getelementptr inbounds i32, i32* %5, i64 10
store i32 11, i32* %27
%28 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 11)
%29 = getelementptr inbounds i32, i32* %5, i64 11
store i32 12, i32* %29
%30 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 12)
%31 = getelementptr inbounds i32, i32* %5, i64 12
store i32 13, i32* %31
%32 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 13)
%33 = getelementptr inbounds i32, i32* %5, i64 13
store i32 14, i32* %33
%34 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 14)
%35 = getelementptr inbounds i32, i32* %5, i64 14
store i32 15, i32* %35
%36 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 15)
%37 = getelementptr inbounds i32, i32* %5, i64 15
store i32 16, i32* %37
%38 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 16)
%39 = getelementptr inbounds i32, i32* %5, i64 16
store i32 17, i32* %39
%40 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 17)
%41 = getelementptr inbounds i32, i32* %5, i64 17
store i32 18, i32* %41
%42 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 18)
%43 = getelementptr inbounds i32, i32* %5, i64 18
store i32 19, i32* %43
%44 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 19)
%45 = getelementptr inbounds i32, i32* %5, i64 19
store i32 20, i32* %45
%46 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 20)
%47 = tail call i32 @my_free(i32* %5)
ret i32 0
48: ; preds = %2
%49 = load i32, i32* @stderr
%50 = tail call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%51 = tail call i32 @exit(i32 1)
unreachable
}