#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*/ ht_insert(void *, unsigned long, char *);
int /*<<< orphan*/ initialize();
void *malloc(unsigned long);
int /*<<< orphan*/ mark_corruption(void *, unsigned long);
int /*<<< orphan*/ outofmem(char *);
void *mhandle_malloc(unsigned long size, char *at) {
  void *ptr;
  initialize();
  ptr = malloc(size + (2 * 2));
  if (!ptr)
    outofmem(at);
  mark_corruption(ptr, size);
  ht_insert(ptr, size, at);
  return ptr + 2;
}


x86 assembly (clang, -O0):
<mhandle_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <initialize@plt>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <mhandle_malloc+0x3c>
mov    -0x10(%rbp),%rdi
call   1060 <outofmem@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <mark_corruption@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <ht_insert@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mhandle_malloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <initialize@plt>
lea    0x4(%r15),%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117b <mhandle_malloc+0x2b>
mov    %r14,%rdi
call   1060 <outofmem@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <mark_corruption@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <ht_insert@plt>
add    $0x2,%rbx
mov    %rbx,%rax
pop    %rbx
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*
store i64 %0, i64* %3
store i8* %1, i8** %4
%6 = call i32 (...) @initialize()
%7 = load i64, i64* %3
%8 = add i64 %7, 4
%9 = call i8* @malloc(i64 %8)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @outofmem(i8* %13)
br label %15
15: ; preds = %12, %2
%16 = load i8*, i8** %5
%17 = load i64, i64* %3
%18 = call i32 @mark_corruption(i8* %16, i64 %17)
%19 = load i8*, i8** %5
%20 = load i64, i64* %3
%21 = load i8*, i8** %4
%22 = call i32 @ht_insert(i8* %19, i64 %20, i8* %21)
%23 = load i8*, i8** %5
%24 = getelementptr i8, i8* %23, i64 2
ret i8* %24
}

LLVM IR (-O2):
define i8* @mhandle_malloc(i64 %0, i8* %1) {
%3 = tail call i32 (...) @initialize()
%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 @outofmem(i8* %1)
br label %9
9: ; preds = %7, %2
%10 = tail call i32 @mark_corruption(i8* %5, i64 %0)
%11 = tail call i32 @ht_insert(i8* %5, i64 %0, i8* %1)
%12 = getelementptr i8, i8* %5, i64 2
ret i8* %12
}