#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(unsigned int);
void *kmalloc(int);
int /*<<< orphan*/ printf(char *, unsigned int);
void pool_test() {
  void *addr = kmalloc(50);
  printf("\nkalloc 50B, addr: ", 0);
  printf("%h", (unsigned int)addr);
  void *addr2 = kmalloc(50);
  printf("\nkalloc 50B, addr: ", 0);
  printf("%h", (unsigned int)addr2);
  void *addr4 = kmalloc(50);
  printf("\nkalloc 50B, addr: ", 0);
  printf("%h", (unsigned int)addr4);
  kfree((unsigned int)addr);
  printf("\nkfree 50B, addr: ", 0);
  printf("%h", (unsigned int)addr);
  kfree((unsigned int)addr2);
  printf("\nkfree 50B, addr: ", 0);
  printf("%h", (unsigned int)addr2);
  void *addr3 = kmalloc(70);
  printf("\nkalloc 70B, addr: ", 0);
  printf("%h", (unsigned int)addr3);
  kfree((unsigned int)addr3);
  printf("\nkfree 70B, addr: ", 0);
  printf("%h", (unsigned int)addr3);
}


x86 assembly (clang, -O0):
<pool_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x32,%edi
call   1050 <kmalloc@plt>
mov    %rax,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x32,%edi
call   1050 <kmalloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe85(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    $0x32,%edi
call   1050 <kmalloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe57(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1040 <kfree@plt>
lea    0xe43(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1040 <kfree@plt>
lea    0xe18(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe01(%rip),%rdi
call   1030 <printf@plt>
mov    $0x46,%edi
call   1050 <kmalloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xdfd(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
lea    0xdd3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1040 <kfree@plt>
lea    0xde6(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
lea    0xda8(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pool_test>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x32,%edi
call   1050 <kmalloc@plt>
mov    %rax,%r15
lea    0xeb3(%rip),%r12
mov    %r12,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
lea    0xeb6(%rip),%r14
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
mov    $0x32,%edi
call   1050 <kmalloc@plt>
mov    %rax,%r13
mov    %r12,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
mov    $0x32,%edi
call   1050 <kmalloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r15d,%edi
call   1040 <kfree@plt>
lea    0xe5c(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
mov    %r13d,%edi
call   1040 <kfree@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
mov    $0x46,%edi
call   1050 <kmalloc@plt>
mov    %rax,%rbx
lea    0xe29(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <kfree@plt>
lea    0xe1e(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"\0Akalloc 50B, addr: \00"
@.str.1 = [3 x i8] c"%h\00"
@.str.2 = [19 x i8] c"\0Akfree 50B, addr: \00"
@.str.3 = [20 x i8] c"\0Akalloc 70B, addr: \00"
@.str.4 = [19 x i8] c"\0Akfree 70B, addr: \00"
define void @pool_test() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i8* @kmalloc(i32 50)
store i8* %5, i8** %1
%6 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 0)
%7 = load i8*, i8** %1
%8 = ptrtoint i8* %7 to i32
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i8* @kmalloc(i32 50)
store i8* %10, i8** %2
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 0)
%12 = load i8*, i8** %2
%13 = ptrtoint i8* %12 to i32
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i8* @kmalloc(i32 50)
store i8* %15, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 0)
%17 = load i8*, i8** %3
%18 = ptrtoint i8* %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i8*, i8** %1
%21 = ptrtoint i8* %20 to i32
%22 = call i32 @kfree(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 0)
%24 = load i8*, i8** %1
%25 = ptrtoint i8* %24 to i32
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %2
%28 = ptrtoint i8* %27 to i32
%29 = call i32 @kfree(i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 0)
%31 = load i8*, i8** %2
%32 = ptrtoint i8* %31 to i32
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i8* @kmalloc(i32 70)
store i8* %34, i8** %4
%35 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 0)
%36 = load i8*, i8** %4
%37 = ptrtoint i8* %36 to i32
%38 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %4
%40 = ptrtoint i8* %39 to i32
%41 = call i32 @kfree(i32 %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 0)
%43 = load i8*, i8** %4
%44 = ptrtoint i8* %43 to i32
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %44)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"\0Akalloc 50B, addr: \00"
@.str.1 = [3 x i8] c"%h\00"
@.str.2 = [19 x i8] c"\0Akfree 50B, addr: \00"
@.str.3 = [20 x i8] c"\0Akalloc 70B, addr: \00"
@.str.4 = [19 x i8] c"\0Akfree 70B, addr: \00"
define void @pool_test() {
%1 = tail call i8* @kmalloc(i32 50)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 0)
%3 = ptrtoint i8* %1 to i64
%4 = trunc i64 %3 to i32
%5 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i8* @kmalloc(i32 50)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = ptrtoint i8* %6 to i64
%9 = trunc i64 %8 to i32
%10 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i8* @kmalloc(i32 50)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 0)
%13 = ptrtoint i8* %11 to i64
%14 = trunc i64 %13 to i32
%15 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = tail call i32 @kfree(i32 %4)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 0)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%19 = tail call i32 @kfree(i32 %9)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 0)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%22 = tail call i8* @kmalloc(i32 70)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 0)
%24 = ptrtoint i8* %22 to i64
%25 = trunc i64 %24 to i32
%26 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = tail call i32 @kfree(i32 %25)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 0)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
ret void
}