#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*/ addtolist(void *, size_t const, int /*<<< orphan*/,
                             int const);
int /*<<< orphan*/ filefrompath(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
void *malloc(size_t const);
int /*<<< orphan*/ stderr;
void *mem_alloc(const size_t n, const char *file, const int line) {
  void *new;
  if (n == 0) {
    fprintf(stderr, "Warning: Tried to allocate 0 bytes\n");
    fprintf(stderr, " in file %s, line %d.\n", file, line);
  }
  new = malloc(n);
  addtolist(new, n, filefrompath(file), line);
  return new;
}


x86 assembly (clang, -O0):
<mem_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1193 <mem_alloc+0x53>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <filefrompath@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
mov    -0x14(%rbp),%ecx
call   1030 <addtolist@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_alloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1184 <mem_alloc+0x44>
mov    0x2e84(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe9a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xead(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %r15,%rdi
call   1040 <filefrompath@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r14d,%ecx
call   1030 <addtolist@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Warning: Tried to allocate 0 bytes\0A\00"
@.str.1 = [23 x i8] c" in file %s, line %d.\0A\00"
define i8* @mem_alloc(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 i64, i64* %4
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %15)
br label %17
17: ; preds = %10, %3
%18 = load i64, i64* %4
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = load i64, i64* %4
%22 = load i8*, i8** %5
%23 = call i32 @filefrompath(i8* %22)
%24 = load i32, i32* %6
%25 = call i32 @addtolist(i8* %20, i64 %21, i32 %23, i32 %24)
%26 = load i8*, i8** %7
ret i8* %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Warning: Tried to allocate 0 bytes\0A\00"
@.str.1 = [23 x i8] c" in file %s, line %d.\0A\00"
define i8* @mem_alloc(i64 %0, i8* %1, i32 %2) {
%4 = icmp eq i64 %0, 0
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %2)
br label %10
10: ; preds = %5, %3
%11 = tail call i8* @malloc(i64 %0)
%12 = tail call i32 @filefrompath(i8* %1)
%13 = tail call i32 @addtolist(i8* %11, i64 %0, i32 %12, i32 %2)
ret i8* %11
}