#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*/ debug_addpointer(void *, size_t, char const *, int);
int /*<<< orphan*/ debug_print(char const *, int, char *, void *, size_t, int);
void *malloc(size_t);
void *debug_malloc(size_t size, const char *file, int line) {
  void *ptr;
  debug_print(file, line, "malloc", 0, size, 0);
  ptr = malloc(size);
  debug_addpointer(ptr, size, file, line);
  debug_print(file, line, "malloc", ptr, size, 1);
  return ptr;
}


x86 assembly (clang, -O0):
<debug_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%r8
lea    0xeab(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r9d,%r9d
call   1050 <debug_print@plt>
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1030 <debug_addpointer@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe68(%rip),%rdx
mov    $0x1,%r9d
call   1050 <debug_print@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_malloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xeb8(%rip),%r15
mov    %rsi,%rdi
mov    %edx,%esi
mov    %r15,%rdx
xor    %ecx,%ecx
mov    %rbx,%r8
xor    %r9d,%r9d
call   1050 <debug_print@plt>
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r14d,%ecx
call   1030 <debug_addpointer@plt>
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %rbx,%r8
mov    $0x1,%r9d
call   1050 <debug_print@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
define i8* @debug_malloc(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = load i64, i64* %4
%11 = call i32 @debug_print(i8* %8, i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* null, i64 %10, i32 0)
%12 = load i64, i64* %4
%13 = call i8* @malloc(i64 %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = load i64, i64* %4
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = call i32 @debug_addpointer(i8* %14, i64 %15, i8* %16, i32 %17)
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = load i8*, i8** %7
%22 = load i64, i64* %4
%23 = call i32 @debug_print(i8* %19, i32 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %21, i64 %22, i32 1)
%24 = load i8*, i8** %7
ret i8* %24
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
define i8* @debug_malloc(i64 %0, i8* %1, i32 %2) {
%4 = tail call i32 @debug_print(i8* %1, i32 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* null, i64 %0, i32 0)
%5 = tail call i8* @malloc(i64 %0)
%6 = tail call i32 @debug_addpointer(i8* %5, i64 %0, i8* %1, i32 %2)
%7 = tail call i32 @debug_print(i8* %1, i32 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %5, i64 %0, i32 1)
ret i8* %5
}