#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*/ EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, unsigned long,
                           size_t, int /*<<< orphan*/);
void *malloc(size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(scalar_t__);
void *safe_malloc(size_t size, unsigned long line) {
  errno = 0;
  void *p = malloc(size);
  if (!p) {
    fprintf(stderr, "[%s:%lu] Malloc failed (%zu bytes)\n\t%s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/jirka-h/aprng/refs/heads/master/src/"
            "libaprng-util.c",
            line, size, strerror(errno));
    exit(EXIT_FAILURE);
  }
  return p;
}


x86 assembly (clang, -O0):
<safe_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <safe_malloc+0x90>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    %eax,%r9d
lea    0xe4a(%rip),%rsi
lea    0xe6b(%rip),%rdx
call   1030 <fprintf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_malloc>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e87(%rip),%rax
movq   $0x0,(%rax)
call   1040 <malloc@plt>
test   %rax,%rax
je     1167 <safe_malloc+0x27>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e72(%rip),%rax
mov    (%rax),%ebp
xor    %edi,%edi
call   1060 <strerror@plt>
lea    0xe82(%rip),%rsi
lea    0xea3(%rip),%rdx
mov    %ebp,%edi
mov    %r14,%rcx
mov    %rbx,%r8
mov    %eax,%r9d
call   1030 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [40 x i8] c"[%s:%lu] Malloc failed (%zu bytes)\0A\09%s\0A\00"
@.str.1 = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jirka-h/aprng/refs/heads/master/src/libaprng-util.c\00"
@EXIT_FAILURE = global i32 0
define i8* @safe_malloc(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
store i64 0, i64* @errno
%6 = load i64, i64* %3
%7 = call i8* @malloc(i64 %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %19, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i64, i64* %4
%13 = load i64, i64* %3
%14 = load i64, i64* @errno
%15 = call i32 @strerror(i64 %14)
%16 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i64 %12, i64 %13, i32 %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8*, i8** %5
ret i8* %20
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [40 x i8] c"[%s:%lu] Malloc failed (%zu bytes)\0A\09%s\0A\00"
@.str.1 = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jirka-h/aprng/refs/heads/master/src/libaprng-util.c\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @safe_malloc(i64 %0, i64 %1) {
store i64 0, i64* @errno
%3 = tail call i8* @malloc(i64 %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @strerror(i64 0)
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i64 %1, i64 %0, i32 %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
ret i8* %3
}