#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*/ get_memory(char *, int);
int /*<<< orphan*/ mtrace();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int main(void) {
  char *str = NULL;
  setenv("MALLOC_TRACE", "mtrace.out", 1);
  mtrace();
  printf("Memory leak test!\n");
  for (int i = 0; i < 10; i++) {
    get_memory(str, 100);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xea2(%rip),%rdi
lea    0xea8(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    $0x0,%al
call   1060 <mtrace@plt>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11af <main+0x6f>
mov    -0x10(%rbp),%rdi
mov    $0x64,%esi
call   1050 <get_memory@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1189 <main+0x49>
xor    %eax,%eax
add    $0x20,%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>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <get_memory@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"MALLOC_TRACE\00"
@.str.1 = [11 x i8] c"mtrace.out\00"
@.str.2 = [19 x i8] c"Memory leak test!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
%4 = 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)
%5 = call i32 (...) @mtrace()
%6 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %7
7: ; preds = %13, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = call i32 @get_memory(i8* %11, i32 100)
br label %13
13: ; preds = %10
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %7
16: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"MALLOC_TRACE\00"
@.str.1 = [11 x i8] c"mtrace.out\00"
@str = [18 x i8] c"Memory leak test!\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 i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @get_memory(i8* null, i32 100)
%5 = tail call i32 @get_memory(i8* null, i32 100)
%6 = tail call i32 @get_memory(i8* null, i32 100)
%7 = tail call i32 @get_memory(i8* null, i32 100)
%8 = tail call i32 @get_memory(i8* null, i32 100)
%9 = tail call i32 @get_memory(i8* null, i32 100)
%10 = tail call i32 @get_memory(i8* null, i32 100)
%11 = tail call i32 @get_memory(i8* null, i32 100)
%12 = tail call i32 @get_memory(i8* null, i32 100)
%13 = tail call i32 @get_memory(i8* null, i32 100)
ret i32 0
}