#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 */
scalar_t__ mycalloc(int, int);
int /*<<< orphan*/ myfree(int *);
int *mymalloc(int);
int *myrealloc(int *, int);
int /*<<< orphan*/ printf(char *, unsigned int);
int main() {
  int *p1[3];
  int i;
  for (i = 0; i < 3; i++) {
    p1[i] = mymalloc(16);
    printf("%x\n", (unsigned int)p1[i]);
  }
  myfree(p1[1]);
  int *p = (int *)mymalloc(10);
  printf("%x\n", (unsigned int)p);
  myfree(p1[0]);
  myfree(p1[2]);
  int *p2 = (int *)mycalloc(2, 7);
  printf("%x\n", (unsigned int)p2);
  p = myrealloc(p, 5);
  myfree(p);
  myfree(p2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    11ab <main+0x5b>
mov    $0x10,%edi
call   1060 <mymalloc@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
mov    %rcx,-0x20(%rbp,%rax,8)
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rax
mov    %eax,%esi
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1166 <main+0x16>
mov    -0x18(%rbp),%rdi
call   1070 <myfree@plt>
mov    $0xa,%edi
call   1060 <mymalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,%esi
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <myfree@plt>
mov    -0x10(%rbp),%rdi
call   1070 <myfree@plt>
mov    $0x2,%edi
mov    $0x7,%esi
call   1030 <mycalloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,%esi
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    $0x5,%esi
call   1050 <myrealloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <myfree@plt>
mov    -0x38(%rbp),%rdi
call   1070 <myfree@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x10,%edi
call   1060 <mymalloc@plt>
mov    %rax,%r15
lea    0xe93(%rip),%r14
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
mov    $0x10,%edi
call   1060 <mymalloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    $0x10,%edi
call   1060 <mymalloc@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <myfree@plt>
mov    $0xa,%edi
call   1060 <mymalloc@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %r13d,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1070 <myfree@plt>
mov    %r12,%rdi
call   1070 <myfree@plt>
mov    $0x2,%edi
mov    $0x7,%esi
call   1030 <mycalloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    $0x5,%esi
call   1050 <myrealloc@plt>
mov    %rax,%rdi
call   1070 <myfree@plt>
mov    %rbx,%rdi
call   1070 <myfree@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i32*]
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %3
br label %6
6: ; preds = %20, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = call i32* @mymalloc(i32 16)
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [3 x i32*], [3 x i32*]* %2, i64 0, i64 %12
store i32* %10, i32** %13
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [3 x i32*], [3 x i32*]* %2, i64 0, i64 %15
%17 = load i32*, i32** %16
%18 = ptrtoint i32* %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %9
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %6
23: ; preds = %6
%24 = getelementptr inbounds [3 x i32*], [3 x i32*]* %2, i64 0, i64 1
%25 = load i32*, i32** %24
%26 = call i32 @myfree(i32* %25)
%27 = call i32* @mymalloc(i32 10)
store i32* %27, i32** %4
%28 = load i32*, i32** %4
%29 = ptrtoint i32* %28 to i32
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [3 x i32*], [3 x i32*]* %2, i64 0, i64 0
%32 = load i32*, i32** %31
%33 = call i32 @myfree(i32* %32)
%34 = getelementptr inbounds [3 x i32*], [3 x i32*]* %2, i64 0, i64 2
%35 = load i32*, i32** %34
%36 = call i32 @myfree(i32* %35)
%37 = call i64 @mycalloc(i32 2, i32 7)
%38 = inttoptr i64 %37 to i32*
store i32* %38, i32** %5
%39 = load i32*, i32** %5
%40 = ptrtoint i32* %39 to i32
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i32*, i32** %4
%43 = call i32* @myrealloc(i32* %42, i32 5)
store i32* %43, i32** %4
%44 = load i32*, i32** %4
%45 = call i32 @myfree(i32* %44)
%46 = load i32*, i32** %5
%47 = call i32 @myfree(i32* %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%x\0A\00"
define i32 @main() {
%1 = tail call i32* @mymalloc(i32 16)
%2 = ptrtoint i32* %1 to i64
%3 = trunc i64 %2 to i32
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32* @mymalloc(i32 16)
%6 = ptrtoint i32* %5 to i64
%7 = trunc i64 %6 to i32
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32* @mymalloc(i32 16)
%10 = ptrtoint i32* %9 to i64
%11 = trunc i64 %10 to i32
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @myfree(i32* %5)
%14 = tail call i32* @mymalloc(i32 10)
%15 = ptrtoint i32* %14 to i64
%16 = trunc i64 %15 to i32
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = tail call i32 @myfree(i32* %1)
%19 = tail call i32 @myfree(i32* %9)
%20 = tail call i64 @mycalloc(i32 2, i32 7)
%21 = inttoptr i64 %20 to i32*
%22 = trunc i64 %20 to i32
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = tail call i32* @myrealloc(i32* %14, i32 5)
%25 = tail call i32 @myfree(i32* %24)
%26 = tail call i32 @myfree(i32* %21)
ret i32 0
}