#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*/ abort();
int /*<<< orphan*/ add_entry(char *, int, void *, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ stderr;
void *safe_malloc_internal(size_t size, char *file, int line) {
  void *ret = malloc(size);
  if (!ret) {
    {
      fprintf(
          stderr, "Unrecoverable error in %s(%d): %s\n\n",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/memory.c",
          124, "Out of memory.");
      abort();
    };
  };
  memset(ret, 0, size);
  add_entry(file, line, ret, size);
  return ret;
}


x86 assembly (clang, -O0):
<safe_malloc_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11aa <safe_malloc_internal+0x5a>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
lea    0xe92(%rip),%rdx
mov    $0x7c,%ecx
lea    0xf0a(%rip),%r8
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rcx
call   1050 <add_entry@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_malloc_internal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
call   1070 <malloc@plt>
test   %rax,%rax
je     1199 <safe_malloc_internal+0x49>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1050 <add_entry@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
lea    0xe74(%rip),%rdx
lea    0xef1(%rip),%r8
mov    $0x7c,%ecx
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Unrecoverable error in %s(%d): %s\0A\0A\00"
@.str.1 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/memory.c\00"
@.str.2 = [15 x i8] c"Out of memory.\00"
define i8* @safe_malloc_internal(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 = call i8* @malloc(i64 %8)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 124, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %3
%17 = load i8*, i8** %7
%18 = load i64, i64* %4
%19 = call i32 @memset(i8* %17, i32 0, i64 %18)
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = load i8*, i8** %7
%23 = load i64, i64* %4
%24 = call i32 @add_entry(i8* %20, i32 %21, i8* %22, i64 %23)
%25 = load i8*, i8** %7
ret i8* %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Unrecoverable error in %s(%d): %s\0A\0A\00"
@.str.1 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/memory.c\00"
@.str.2 = [15 x i8] c"Out of memory.\00"
define i8* @safe_malloc_internal(i64 %0, i8* %1, i32 %2) {
%4 = tail call i8* @malloc(i64 %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 124, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %3
%11 = tail call i32 @memset(i8* %4, i32 0, i64 %0)
%12 = tail call i32 @add_entry(i8* %1, i32 %2, i8* %4, i64 %0)
ret i8* %4
}