#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 *calloc(int, 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_calloc(unsigned long nmemb, unsigned long size, char *at) {
  void *ptr;
  void *eff_ptr;
  unsigned long total;
  unsigned long eff_total;
  mhandle_init();
  total = nmemb * size;
  eff_total = total + (2 * 2);
  eff_ptr = calloc(1, eff_total);
  if (!eff_ptr)
    mhandle_out_of_memory(at);
  ptr = eff_ptr + 2;
  mhandle_mark_corrupt(eff_ptr, eff_total);
  mhandle_hash_table_insert(ptr, total, at, 1);
  return ptr;
}


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

x86 assembly (clang, -O2):
<mhandle_calloc>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <mhandle_init@plt>
imul   %rbx,%r12
lea    0x4(%r12),%r15
mov    $0x1,%edi
mov    %r15,%rsi
call   1060 <calloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    118f <mhandle_calloc+0x3f>
mov    %r14,%rdi
call   1040 <mhandle_out_of_memory@plt>
mov    %r13,%rbx
add    $0x2,%rbx
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <mhandle_mark_corrupt@plt>
mov    %rbx,%rdi
mov    %r12,%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_calloc(i64 %0, i64 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%11 = call i32 (...) @mhandle_init()
%12 = load i64, i64* %4
%13 = load i64, i64* %5
%14 = mul i64 %12, %13
store i64 %14, i64* %9
%15 = load i64, i64* %9
%16 = add i64 %15, 4
store i64 %16, i64* %10
%17 = load i64, i64* %10
%18 = call i8* @calloc(i32 1, i64 %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %3
%22 = load i8*, i8** %6
%23 = call i32 @mhandle_out_of_memory(i8* %22)
br label %24
24: ; preds = %21, %3
%25 = load i8*, i8** %8
%26 = getelementptr i8, i8* %25, i64 2
store i8* %26, i8** %7
%27 = load i8*, i8** %8
%28 = load i64, i64* %10
%29 = call i32 @mhandle_mark_corrupt(i8* %27, i64 %28)
%30 = load i8*, i8** %7
%31 = load i64, i64* %9
%32 = load i8*, i8** %6
%33 = call i32 @mhandle_hash_table_insert(i8* %30, i64 %31, i8* %32, i32 1)
%34 = load i8*, i8** %7
ret i8* %34
}

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