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


x86 assembly (clang, -O0):
<MT_Malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a0 <MT_Malloc+0x50>
lea    0xe6f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xe63(%rip),%rdx
call   1060 <MT_add_entry@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <MT_init_redzone@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MT_Malloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x4,%rbx
mov    %rbx,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     11a8 <MT_Malloc+0x58>
mov    %rax,%r12
lea    0xe9f(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%ecx
mov    %r15,%r8
mov    %r14,%r9
call   1060 <MT_add_entry@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <MT_init_redzone@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe51(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

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