#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  uint8_t *mallocme, *mallocme2, *mallocme3;
  fprintf(stdout, "-- malloc test by Wolfgang Richter <wolf@cs.cmu.edu> --"
                  "\n");
  mallocme = malloc(4096);
  mallocme2 = malloc(4096);
  mallocme3 = malloc(4096);
  memset(mallocme, 0, 4096);
  memset(mallocme2, 0xff, 4096);
  memset(mallocme3, 0xee, 4096);
  free(mallocme);
  free(mallocme2);
  free(mallocme3);
  mallocme = malloc(4096);
  mallocme2 = malloc(4096);
  mallocme3 = malloc(4096);
  memset(mallocme, 0, 4096);
  memset(mallocme2, 0xff, 4096);
  memset(mallocme3, 0xee, 4096);
  free(mallocme3);
  free(mallocme2);
  free(mallocme);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    $0xee,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    $0xee,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0xee,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0xee,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [57 x i8] c"-- malloc test by Wolfgang Richter <wolf@cs.cmu.edu> --\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @stdout
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%11 = call i32* @malloc(i32 4096)
store i32* %11, i32** %6
%12 = call i32* @malloc(i32 4096)
store i32* %12, i32** %7
%13 = call i32* @malloc(i32 4096)
store i32* %13, i32** %8
%14 = load i32*, i32** %6
%15 = call i32 @memset(i32* %14, i32 0, i32 4096)
%16 = load i32*, i32** %7
%17 = call i32 @memset(i32* %16, i32 255, i32 4096)
%18 = load i32*, i32** %8
%19 = call i32 @memset(i32* %18, i32 238, i32 4096)
%20 = load i32*, i32** %6
%21 = call i32 @free(i32* %20)
%22 = load i32*, i32** %7
%23 = call i32 @free(i32* %22)
%24 = load i32*, i32** %8
%25 = call i32 @free(i32* %24)
%26 = call i32* @malloc(i32 4096)
store i32* %26, i32** %6
%27 = call i32* @malloc(i32 4096)
store i32* %27, i32** %7
%28 = call i32* @malloc(i32 4096)
store i32* %28, i32** %8
%29 = load i32*, i32** %6
%30 = call i32 @memset(i32* %29, i32 0, i32 4096)
%31 = load i32*, i32** %7
%32 = call i32 @memset(i32* %31, i32 255, i32 4096)
%33 = load i32*, i32** %8
%34 = call i32 @memset(i32* %33, i32 238, i32 4096)
%35 = load i32*, i32** %8
%36 = call i32 @free(i32* %35)
%37 = load i32*, i32** %7
%38 = call i32 @free(i32* %37)
%39 = load i32*, i32** %6
%40 = call i32 @free(i32* %39)
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [57 x i8] c"-- malloc test by Wolfgang Richter <wolf@cs.cmu.edu> --\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @malloc(i32 4096)
%6 = tail call i32* @malloc(i32 4096)
%7 = tail call i32* @malloc(i32 4096)
%8 = tail call i32 @memset(i32* %5, i32 0, i32 4096)
%9 = tail call i32 @memset(i32* %6, i32 255, i32 4096)
%10 = tail call i32 @memset(i32* %7, i32 238, i32 4096)
%11 = tail call i32 @free(i32* %5)
%12 = tail call i32 @free(i32* %6)
%13 = tail call i32 @free(i32* %7)
%14 = tail call i32* @malloc(i32 4096)
%15 = tail call i32* @malloc(i32 4096)
%16 = tail call i32* @malloc(i32 4096)
%17 = tail call i32 @memset(i32* %14, i32 0, i32 4096)
%18 = tail call i32 @memset(i32* %15, i32 255, i32 4096)
%19 = tail call i32 @memset(i32* %16, i32 238, i32 4096)
%20 = tail call i32 @free(i32* %16)
%21 = tail call i32 @free(i32* %15)
%22 = tail call i32 @free(i32* %14)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}