#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*/ abort();
int /*<<< orphan*/ err_f(char *);
void *heap_malloc(size_t);
int pool_cell_size(size_t);
void *pool_malloc(size_t);
void *tmalloc(size_t count) {
  if (count == 0)
    do {
      err_f("trying to allocate 0 bytes");
      abort();
    } while (0);
  ;
  if (pool_cell_size(count) <= 2048)
    return pool_malloc(count);
  return heap_malloc(count);
}


x86 assembly (clang, -O0):
<tmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117f <tmalloc+0x2f>
jmp    116c <tmalloc+0x1c>
lea    0xe8d(%rip),%rdi
call   1070 <err_f@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rdi
call   1060 <pool_cell_size@plt>
cmp    $0x800,%eax
jg     11a5 <tmalloc+0x55>
mov    -0x10(%rbp),%rdi
call   1040 <pool_malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11b2 <tmalloc+0x62>
mov    -0x10(%rbp),%rdi
call   1050 <heap_malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmalloc>:
push   %rbx
test   %rdi,%rdi
je     1174 <tmalloc+0x24>
mov    %rdi,%rbx
call   1060 <pool_cell_size@plt>
mov    %rbx,%rdi
cmp    $0x800,%eax
jg     116e <tmalloc+0x1e>
pop    %rbx
jmp    1040 <pool_malloc@plt>
pop    %rbx
jmp    1050 <heap_malloc@plt>
lea    0xe85(%rip),%rdi
call   1070 <err_f@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"trying to allocate 0 bytes\00"
define i8* @tmalloc(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
br label %7
7: ; preds = %6
%8 = call i32 @err_f(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @abort()
unreachable
10: ; No predecessors!
br label %11
11: ; preds = %10, %1
%12 = load i64, i64* %3
%13 = call i32 @pool_cell_size(i64 %12)
%14 = icmp sle i32 %13, 2048
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i64, i64* %3
%17 = call i8* @pool_malloc(i64 %16)
store i8* %17, i8** %2
br label %21
18: ; preds = %11
%19 = load i64, i64* %3
%20 = call i8* @heap_malloc(i64 %19)
store i8* %20, i8** %2
br label %21
21: ; preds = %18, %15
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@.str = [27 x i8] c"trying to allocate 0 bytes\00"
define i8* @tmalloc(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @err_f(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (...) @abort()
unreachable
6: ; preds = %1
%7 = tail call i32 @pool_cell_size(i64 %0)
%8 = icmp slt i32 %7, 2049
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i8* @pool_malloc(i64 %0)
br label %13
11: ; preds = %6
%12 = tail call i8* @heap_malloc(i64 %0)
br label %13
13: ; preds = %11, %9
%14 = phi i8* [ %10, %9 ], [ %12, %11 ]
ret i8* %14
}