#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 */
void *malloc(unsigned long);
int /*<<< orphan*/ mhandle_hash_table_insert(void *, unsigned long, char *,
                                             int);
int /*<<< orphan*/ mhandle_init();
int /*<<< orphan*/ mhandle_mark_corrupt(void *, unsigned long);
int /*<<< orphan*/ mhandle_out_of_memory(char *);
void *mhandle_malloc(unsigned long size, char *at) {
  void *ptr;
  void *eff_ptr;
  unsigned long eff_size;
  mhandle_init();
  eff_size = size + (2 * 2);
  eff_ptr = malloc(eff_size);
  if (!eff_ptr)
    mhandle_out_of_memory(at);
  ptr = eff_ptr + 2;
  mhandle_mark_corrupt(eff_ptr, eff_size);
  mhandle_hash_table_insert(ptr, size, at, 1);
  return ptr;
}


x86 assembly (clang, -O0):
<mhandle_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <mhandle_init@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <mhandle_malloc+0x44>
mov    -0x10(%rbp),%rdi
call   1040 <mhandle_out_of_memory@plt>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <mhandle_mark_corrupt@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x1,%ecx
call   1070 <mhandle_hash_table_insert@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mhandle_malloc>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <mhandle_init@plt>
lea    0x4(%r15),%r12
mov    %r12,%rdi
call   1060 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1182 <mhandle_malloc+0x32>
mov    %r14,%rdi
call   1040 <mhandle_out_of_memory@plt>
mov    %r13,%rbx
add    $0x2,%rbx
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <mhandle_mark_corrupt@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x1,%ecx
call   1070 <mhandle_hash_table_insert@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @mhandle_malloc(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i64 %0, i64* %3
store i8* %1, i8** %4
%8 = call i32 (...) @mhandle_init()
%9 = load i64, i64* %3
%10 = add i64 %9, 4
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32 @mhandle_out_of_memory(i8* %16)
br label %18
18: ; preds = %15, %2
%19 = load i8*, i8** %6
%20 = getelementptr i8, i8* %19, i64 2
store i8* %20, i8** %5
%21 = load i8*, i8** %6
%22 = load i64, i64* %7
%23 = call i32 @mhandle_mark_corrupt(i8* %21, i64 %22)
%24 = load i8*, i8** %5
%25 = load i64, i64* %3
%26 = load i8*, i8** %4
%27 = call i32 @mhandle_hash_table_insert(i8* %24, i64 %25, i8* %26, i32 1)
%28 = load i8*, i8** %5
ret i8* %28
}

LLVM IR (-O2):
define i8* @mhandle_malloc(i64 %0, i8* %1) {
%3 = tail call i32 (...) @mhandle_init()
%4 = add i64 %0, 4
%5 = tail call i8* @malloc(i64 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @mhandle_out_of_memory(i8* %1)
br label %9
9: ; preds = %7, %2
%10 = getelementptr i8, i8* %5, i64 2
%11 = tail call i32 @mhandle_mark_corrupt(i8* %5, i64 %4)
%12 = tail call i32 @mhandle_hash_table_insert(i8* %10, i64 %0, i8* %1, i32 1)
ret i8* %10
}