#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*/ cgfree();
void *cgmalloc(int);
int /*<<< orphan*/ mtrace();
int /*<<< orphan*/ setenv(char *, char *, int);
int main() {
  void *p[4];
  void *dd[2];
  int i = 0;
  setenv("MALLOC_TRACE", "output.out", 1);
  mtrace();
  for (; i < 4; i++) {
    p[i] = cgmalloc(i + 10);
  }
  cgfree();
  dd[0] = cgmalloc(100);
  dd[1] = cgmalloc(30);
  cgfree();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x44(%rbp)
lea    0xea3(%rip),%rdi
lea    0xea9(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    $0x0,%al
call   1060 <mtrace@plt>
cmpl   $0x4,-0x44(%rbp)
jge    11a4 <main+0x64>
mov    -0x44(%rbp),%edi
add    $0xa,%edi
call   1030 <cgmalloc@plt>
mov    %rax,%rcx
movslq -0x44(%rbp),%rax
mov    %rcx,-0x30(%rbp,%rax,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1175 <main+0x35>
mov    $0x0,%al
call   1050 <cgfree@plt>
mov    $0x64,%edi
call   1030 <cgmalloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x1e,%edi
call   1030 <cgmalloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <cgfree@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
lea    0xebe(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
xor    %eax,%eax
call   1060 <mtrace@plt>
mov    $0xa,%edi
call   1030 <cgmalloc@plt>
mov    $0xb,%edi
call   1030 <cgmalloc@plt>
mov    $0xc,%edi
call   1030 <cgmalloc@plt>
mov    $0xd,%edi
call   1030 <cgmalloc@plt>
xor    %eax,%eax
call   1050 <cgfree@plt>
mov    $0x64,%edi
call   1030 <cgmalloc@plt>
mov    $0x1e,%edi
call   1030 <cgmalloc@plt>
xor    %eax,%eax
call   1050 <cgfree@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"MALLOC_TRACE\00"
@.str.1 = [11 x i8] c"output.out\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8*]
%3 = alloca [2 x i8*]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 @setenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 1)
%6 = call i32 (...) @mtrace()
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 10
%13 = call i8* @cgmalloc(i32 %12)
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 %15
store i8* %13, i8** %16
br label %17
17: ; preds = %10
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %7
20: ; preds = %7
%21 = call i32 (...) @cgfree()
%22 = call i8* @cgmalloc(i32 100)
%23 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* %22, i8** %23
%24 = call i8* @cgmalloc(i32 30)
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* %24, i8** %25
%26 = call i32 (...) @cgfree()
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"MALLOC_TRACE\00"
@.str.1 = [11 x i8] c"output.out\00"
define i32 @main() {
%1 = tail call i32 @setenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 1)
%2 = tail call i32 (...) @mtrace()
%3 = tail call i8* @cgmalloc(i32 10)
%4 = tail call i8* @cgmalloc(i32 11)
%5 = tail call i8* @cgmalloc(i32 12)
%6 = tail call i8* @cgmalloc(i32 13)
%7 = tail call i32 (...) @cgfree()
%8 = tail call i8* @cgmalloc(i32 100)
%9 = tail call i8* @cgmalloc(i32 30)
%10 = tail call i32 (...) @cgfree()
ret i32 0
}