#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;
void *calloc(size_t, size_t);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, unsigned long,
                           size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(scalar_t__);
void *safe_calloc(size_t nmemb, size_t size, unsigned long line) {
  errno = 0;
  void *p = calloc(nmemb, size);
  if (!p) {
    fprintf(stderr, "[%s:%lu] Calloc 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, nmemb, strerror(errno));
    exit(EXIT_FAILURE);
  }
  return p;
}


x86 assembly (clang, -O0):
<safe_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d8 <safe_calloc+0x98>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    %eax,%r9d
lea    0xe42(%rip),%rsi
lea    0xe63(%rip),%rdx
call   1040 <fprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_calloc>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2e87(%rip),%rax
movq   $0x0,(%rax)
call   1030 <calloc@plt>
test   %rax,%rax
je     1167 <safe_calloc+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   1040 <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] Calloc 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_calloc(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i64 0, i64* @errno
%8 = load i64, i64* %4
%9 = load i64, i64* %5
%10 = call i8* @calloc(i64 %8, i64 %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %22, label %13
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i64, i64* %6
%16 = load i64, i64* %4
%17 = load i64, i64* @errno
%18 = call i32 @strerror(i64 %17)
%19 = call i32 @fprintf(i32 %14, 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 %15, i64 %16, i32 %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %3
%23 = load i8*, i8** %7
ret i8* %23
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [40 x i8] c"[%s:%lu] Calloc 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_calloc(i64 %0, i64 %1, i64 %2) {
store i64 0, i64* @errno
%4 = tail call i8* @calloc(i64 %0, i64 %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @strerror(i64 0)
%9 = tail call i32 @fprintf(i32 %7, 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 %2, i64 %0, i32 %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %3
ret i8* %4
}