#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*/ kfree(char *);
scalar_t__ kmalloc(int);
int /*<<< orphan*/ kmalloc_init();
int /*<<< orphan*/ mem_init();
int /*<<< orphan*/ show_mem();
int main(void) {
  char *v1, *v2, *v3;
  mem_init();
  kmalloc_init();
  show_mem();
  v1 = (char *)kmalloc(24);
  v2 = (char *)kmalloc(64);
  v3 = (char *)kmalloc(4088);
  show_mem();
  kfree(v3);
  show_mem();
  kfree(v2);
  show_mem();
  kfree(v1);
  show_mem();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <mem_init@plt>
mov    $0x0,%al
call   1030 <kmalloc_init@plt>
mov    $0x0,%al
call   1060 <show_mem@plt>
mov    $0x18,%edi
call   1070 <kmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x40,%edi
call   1070 <kmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0xff8,%edi
call   1070 <kmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <show_mem@plt>
mov    -0x20(%rbp),%rdi
call   1040 <kfree@plt>
mov    $0x0,%al
call   1060 <show_mem@plt>
mov    -0x18(%rbp),%rdi
call   1040 <kfree@plt>
mov    $0x0,%al
call   1060 <show_mem@plt>
mov    -0x10(%rbp),%rdi
call   1040 <kfree@plt>
mov    $0x0,%al
call   1060 <show_mem@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <mem_init@plt>
xor    %eax,%eax
call   1030 <kmalloc_init@plt>
xor    %eax,%eax
call   1060 <show_mem@plt>
mov    $0x18,%edi
call   1070 <kmalloc@plt>
mov    %rax,%r14
mov    $0x40,%edi
call   1070 <kmalloc@plt>
mov    %rax,%r15
mov    $0xff8,%edi
call   1070 <kmalloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <show_mem@plt>
mov    %rbx,%rdi
call   1040 <kfree@plt>
xor    %eax,%eax
call   1060 <show_mem@plt>
mov    %r15,%rdi
call   1040 <kfree@plt>
xor    %eax,%eax
call   1060 <show_mem@plt>
mov    %r14,%rdi
call   1040 <kfree@plt>
xor    %eax,%eax
call   1060 <show_mem@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 (...) @mem_init()
%6 = call i32 (...) @kmalloc_init()
%7 = call i32 (...) @show_mem()
%8 = call i64 @kmalloc(i32 24)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %2
%10 = call i64 @kmalloc(i32 64)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
%12 = call i64 @kmalloc(i32 4088)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %4
%14 = call i32 (...) @show_mem()
%15 = load i8*, i8** %4
%16 = call i32 @kfree(i8* %15)
%17 = call i32 (...) @show_mem()
%18 = load i8*, i8** %3
%19 = call i32 @kfree(i8* %18)
%20 = call i32 (...) @show_mem()
%21 = load i8*, i8** %2
%22 = call i32 @kfree(i8* %21)
%23 = call i32 (...) @show_mem()
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 (...) @mem_init()
%2 = tail call i32 (...) @kmalloc_init()
%3 = tail call i32 (...) @show_mem()
%4 = tail call i64 @kmalloc(i32 24)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i64 @kmalloc(i32 64)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i64 @kmalloc(i32 4088)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 (...) @show_mem()
%11 = tail call i32 @kfree(i8* %9)
%12 = tail call i32 (...) @show_mem()
%13 = tail call i32 @kfree(i8* %7)
%14 = tail call i32 (...) @show_mem()
%15 = tail call i32 @kfree(i8* %5)
%16 = tail call i32 (...) @show_mem()
ret i32 0
}