#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*/ MT_add_entry(unsigned long, size_t, char *, int,
                                char const *, char const *);
int /*<<< orphan*/ MT_init_redzone(void *, size_t);
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ perror(char *);
void *MT_Calloc(size_t numMembers, size_t size, int line, const char *func_name,
                const char *file_name) {
  void *ptr;
  size = numMembers * size + 4;
  if ((ptr = (void *)malloc(size)) == NULL) {
    perror("calloc failed to get memory!");
    exit(1);
  }
  memset(ptr, 0, size);
  MT_add_entry((unsigned long int)ptr, size, "CAL", line, func_name, file_name);
  MT_init_redzone(ptr, size);
  return ptr;
}


x86 assembly (clang, -O0):
<MT_Calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rax
imul   -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11b9 <MT_Calloc+0x59>
lea    0xe56(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    0xe3b(%rip),%rdx
call   1070 <MT_add_entry@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <MT_init_redzone@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MT_Calloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%r12d
mov    %rdi,%rbx
imul   %rsi,%rbx
add    $0x4,%rbx
mov    %rbx,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11cb <MT_Calloc+0x6b>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
lea    0xe7d(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%ecx
mov    %r15,%r8
mov    %r14,%r9
call   1070 <MT_add_entry@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <MT_init_redzone@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"calloc failed to get memory!\00"
@.str.1 = [4 x i8] c"CAL\00"
define i8* @MT_Calloc(i64 %0, i64 %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i64 %0, i64* %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = mul i64 %12, %13
%15 = add i64 %14, 4
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %11
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %5
%21 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %5
%24 = load i8*, i8** %11
%25 = load i64, i64* %7
%26 = call i32 @memset(i8* %24, i32 0, i64 %25)
%27 = load i8*, i8** %11
%28 = ptrtoint i8* %27 to i64
%29 = load i64, i64* %7
%30 = load i32, i32* %8
%31 = load i8*, i8** %9
%32 = load i8*, i8** %10
%33 = call i32 @MT_add_entry(i64 %28, i64 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8* %31, i8* %32)
%34 = load i8*, i8** %11
%35 = load i64, i64* %7
%36 = call i32 @MT_init_redzone(i8* %34, i64 %35)
%37 = load i8*, i8** %11
ret i8* %37
}

LLVM IR (-O2):
@.str = [29 x i8] c"calloc failed to get memory!\00"
@.str.1 = [4 x i8] c"CAL\00"
define i8* @MT_Calloc(i64 %0, i64 %1, i32 %2, i8* %3, i8* %4) {
%6 = mul i64 %1, %0
%7 = add i64 %6, 4
%8 = tail call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = tail call i32 @memset(i8* %9, i32 0, i64 %7)
%16 = tail call i32 @MT_add_entry(i64 %8, i64 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %2, i8* %3, i8* %4)
%17 = tail call i32 @MT_init_redzone(i8* %9, i64 %7)
ret i8* %9
}