#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;
typedef int uint32_t;
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int getpid();
int getppid();
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ print_status_vm_values(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  pid_t pid = getpid();
  pid_t ppid = getppid();
  printf("Current PID is %d.  PPID is %d.\n", pid, ppid);
  uint32_t malloc_size = (1024 * 1024);
  uint8_t *buf1 = malloc(malloc_size);
  printf("1st malloc() returned %p\n", buf1);
  print_status_vm_values(pid);
  memset(buf1, 0x55, malloc_size);
  printf("Wrote to every byte of the 1st allocated block.\n");
  print_status_vm_values(pid);
  uint8_t *buf2 = malloc(malloc_size);
  printf("2nd malloc() returned %p\n", buf2);
  print_status_vm_values(pid);
  memset(buf2, 0x55, malloc_size);
  printf("Wrote to every byte of the 2nd allocated block.\n");
  print_status_vm_values(pid);
  free(buf1);
  printf("Freed the 1st block of memory.\n");
  print_status_vm_values(pid);
  free(buf2);
  printf("Freed the 2nd block of memory.\n");
  print_status_vm_values(pid);
  printf("End of test program.\n");
  return 0;
}


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    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x100000,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <print_status_vm_values@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x55,%esi
call   1060 <memset@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <print_status_vm_values@plt>
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <print_status_vm_values@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x55,%esi
call   1060 <memset@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <print_status_vm_values@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <print_status_vm_values@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <print_status_vm_values@plt>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10a0 <getppid@plt>
lea    0xe64(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x100000,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xe66(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1090 <print_status_vm_values@plt>
mov    %r14,%rdi
mov    $0x55,%esi
mov    $0x100000,%edx
call   1070 <memset@plt>
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1090 <print_status_vm_values@plt>
mov    $0x100000,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xe36(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1090 <print_status_vm_values@plt>
mov    %r15,%rdi
mov    $0x55,%esi
mov    $0x100000,%edx
call   1070 <memset@plt>
lea    0xe56(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1090 <print_status_vm_values@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1090 <print_status_vm_values@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1090 <print_status_vm_values@plt>
lea    0xe7b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Current PID is %d. PPID is %d.\0A\00"
@.str.1 = [26 x i8] c"1st malloc() returned %p\0A\00"
@.str.2 = [49 x i8] c"Wrote to every byte of the 1st allocated block.\0A\00"
@.str.3 = [26 x i8] c"2nd malloc() returned %p\0A\00"
@.str.4 = [49 x i8] c"Wrote to every byte of the 2nd allocated block.\0A\00"
@.str.5 = [32 x i8] c"Freed the 1st block of memory.\0A\00"
@.str.6 = [32 x i8] c"Freed the 2nd block of memory.\0A\00"
@.str.7 = [22 x i8] c"End of test program.\0A\00"
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
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @getpid()
store i32 %11, i32* %6
%12 = call i32 (...) @getppid()
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
store i32 1048576, i32* %8
%16 = load i32, i32* %8
%17 = call i32* @malloc(i32 %16)
store i32* %17, i32** %9
%18 = load i32*, i32** %9
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = load i32, i32* %6
%21 = call i32 @print_status_vm_values(i32 %20)
%22 = load i32*, i32** %9
%23 = load i32, i32* %8
%24 = call i32 @memset(i32* %22, i32 85, i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %6
%27 = call i32 @print_status_vm_values(i32 %26)
%28 = load i32, i32* %8
%29 = call i32* @malloc(i32 %28)
store i32* %29, i32** %10
%30 = load i32*, i32** %10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32* %30)
%32 = load i32, i32* %6
%33 = call i32 @print_status_vm_values(i32 %32)
%34 = load i32*, i32** %10
%35 = load i32, i32* %8
%36 = call i32 @memset(i32* %34, i32 85, i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32, i32* %6
%39 = call i32 @print_status_vm_values(i32 %38)
%40 = load i32*, i32** %9
%41 = call i32 @free(i32* %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = call i32 @print_status_vm_values(i32 %43)
%45 = load i32*, i32** %10
%46 = call i32 @free(i32* %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%48 = load i32, i32* %6
%49 = call i32 @print_status_vm_values(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Current PID is %d. PPID is %d.\0A\00"
@.str.1 = [26 x i8] c"1st malloc() returned %p\0A\00"
@.str.3 = [26 x i8] c"2nd malloc() returned %p\0A\00"
@str = [48 x i8] c"Wrote to every byte of the 1st allocated block.\00"
@str.8 = [48 x i8] c"Wrote to every byte of the 2nd allocated block.\00"
@str.9 = [31 x i8] c"Freed the 1st block of memory.\00"
@str.10 = [31 x i8] c"Freed the 2nd block of memory.\00"
@str.11 = [21 x i8] c"End of test program.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (...) @getppid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
%6 = tail call i32* @malloc(i32 1048576)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%8 = tail call i32 @print_status_vm_values(i32 %3)
%9 = tail call i32 @memset(i32* %6, i32 85, i32 1048576)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @print_status_vm_values(i32 %3)
%12 = tail call i32* @malloc(i32 1048576)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32* %12)
%14 = tail call i32 @print_status_vm_values(i32 %3)
%15 = tail call i32 @memset(i32* %12, i32 85, i32 1048576)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.8, i64 0, i64 0))
%17 = tail call i32 @print_status_vm_values(i32 %3)
%18 = tail call i32 @free(i32* %6)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
%20 = tail call i32 @print_status_vm_values(i32 %3)
%21 = tail call i32 @free(i32* %12)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.10, i64 0, i64 0))
%23 = tail call i32 @print_status_vm_values(i32 %3)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
ret i32 0
}