#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*/ f();
int /*<<< orphan*/ g();
scalar_t__ myalloc(int);
int /*<<< orphan*/ myallocinit(int);
int /*<<< orphan*/ mygc();
int /*<<< orphan*/ printallocation();
int /*<<< orphan*/ printf(char *);
int main() {
  int i;
  int *ip;
  char *cp;
  myallocinit(100);
  f();
  mygc();
  printf("In main after gc\n");
  printallocation();
  g();
  printf("In main after g() and gc\n");
  mygc();
  printallocation();
  ip = (int *)myalloc(4 * sizeof(int));
  printf("In main after allocating ip\n");
  printallocation();
  cp = (char *)myalloc(4 * sizeof(char));
  printf("In main after allocating cp\n");
  printallocation();
  for (i = 0; i < 4; i++) {
    ip[i] = i;
    cp[i] = 'A' + i;
  }
  mygc();
  printf("In main after gc\n");
  printallocation();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
call   1080 <myallocinit@plt>
mov    $0x0,%al
call   1040 <f@plt>
mov    $0x0,%al
call   1070 <mygc@plt>
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <printallocation@plt>
mov    $0x0,%al
call   1090 <g@plt>
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <mygc@plt>
mov    $0x0,%al
call   1060 <printallocation@plt>
mov    $0x10,%edi
call   1030 <myalloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <printallocation@plt>
mov    $0x4,%edi
call   1030 <myalloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <printallocation@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    124d <main+0xdd>
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x41,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1214 <main+0xa4>
mov    $0x0,%al
call   1070 <mygc@plt>
lea    0xda5(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <printallocation@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x64,%edi
call   1080 <myallocinit@plt>
xor    %eax,%eax
call   1050 <f@plt>
xor    %eax,%eax
call   1070 <mygc@plt>
lea    0xebd(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <printallocation@plt>
xor    %eax,%eax
call   1090 <g@plt>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <mygc@plt>
xor    %eax,%eax
call   1060 <printallocation@plt>
mov    $0x10,%edi
call   1040 <myalloc@plt>
mov    %rax,%r15
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <printallocation@plt>
mov    $0x4,%edi
call   1040 <myalloc@plt>
mov    %rax,%rbx
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <printallocation@plt>
movl   $0x0,(%r15)
movb   $0x41,(%rbx)
movl   $0x1,0x4(%r15)
movb   $0x42,0x1(%rbx)
movl   $0x2,0x8(%r15)
movb   $0x43,0x2(%rbx)
movl   $0x3,0xc(%r15)
movb   $0x44,0x3(%rbx)
xor    %eax,%eax
call   1070 <mygc@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <printallocation@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@str.4 = [25 x i8] c"In main after g() and gc\00"
@str.5 = [28 x i8] c"In main after allocating ip\00"
@str.6 = [28 x i8] c"In main after allocating cp\00"
@str.7 = [17 x i8] c"In main after gc\00"
define i32 @main() {
%1 = tail call i32 @myallocinit(i32 100)
%2 = tail call i32 (...) @f()
%3 = tail call i32 (...) @mygc()
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%5 = tail call i32 (...) @printallocation()
%6 = tail call i32 (...) @g()
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
%8 = tail call i32 (...) @mygc()
%9 = tail call i32 (...) @printallocation()
%10 = tail call i64 @myalloc(i32 16)
%11 = inttoptr i64 %10 to i32*
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.5, i64 0, i64 0))
%13 = tail call i32 (...) @printallocation()
%14 = tail call i64 @myalloc(i32 4)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.6, i64 0, i64 0))
%17 = tail call i32 (...) @printallocation()
store i32 0, i32* %11
store i8 65, i8* %15
%18 = getelementptr inbounds i32, i32* %11, i64 1
store i32 1, i32* %18
%19 = getelementptr inbounds i8, i8* %15, i64 1
store i8 66, i8* %19
%20 = getelementptr inbounds i32, i32* %11, i64 2
store i32 2, i32* %20
%21 = getelementptr inbounds i8, i8* %15, i64 2
store i8 67, i8* %21
%22 = getelementptr inbounds i32, i32* %11, i64 3
store i32 3, i32* %22
%23 = getelementptr inbounds i8, i8* %15, i64 3
store i8 68, i8* %23
%24 = tail call i32 (...) @mygc()
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%26 = tail call i32 (...) @printallocation()
ret i32 0
}