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


x86 assembly (clang, -O0):
<mhandle_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <initialize@plt>
mov    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <mhandle_calloc+0x52>
mov    -0x18(%rbp),%rdi
call   1060 <outofmem@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <mark_corruption@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <ht_insert@plt>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
add    $0x30,%rsp
pop    %rbp
ret

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

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