#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;
int /*<<< orphan*/ SIZE_MAX;
void *calloc(long long, size_t);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           char const *, char const *, long long, long long,
                           int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void *safe_calloc_helper(long long s, size_t t, const char *typ,
                         const char *file, int line, const char *func) {
  void *pn = calloc(s, t);
  if (pn == NULL || s < 0) {
    fprintf(stderr,
            "%s:%d @%s :: Failed to reallocate %s array of size %lld (%llu "
            "bytes)!\n"
            "Maximal size of size_t : %lu\n",
            file, line, func, typ, s, s * t, SIZE_MAX);
    exit(EXIT_FAILURE);
  }
  return pn;
}


x86 assembly (clang, -O0):
<safe_calloc_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1177 <safe_calloc_helper+0x47>
cmpq   $0x0,-0x8(%rbp)
jge    11cc <safe_calloc_helper+0x9c>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x8(%rbp),%r11
mov    -0x8(%rbp),%r10
imul   -0x10(%rbp),%r10
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
lea    0xe54(%rip),%rsi
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <fprintf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_calloc_helper>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8d,%r13d
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <calloc@plt>
test   %rbx,%rbx
js     116b <safe_calloc_helper+0x3b>
test   %rax,%rax
je     116b <safe_calloc_helper+0x3b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
imul   %rbx,%r14
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
lea    0xe74(%rip),%rsi
mov    %rbp,%rdx
mov    %r13d,%ecx
mov    %r15,%r8
mov    %r12,%r9
push   %rax
push   %r14
push   %rbx
call   1040 <fprintf@plt>
add    $0x20,%rsp
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [100 x i8] c"%s:%d @%s :: Failed to reallocate %s array of size %lld (%llu bytes)!\0AMaximal size of size_t : %lu\0A\00"
@SIZE_MAX = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @safe_calloc_helper(i64 %0, i64 %1, i8* %2, i8* %3, i32 %4, i8* %5) {
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i64 %0, i64* %7
store i64 %1, i64* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i8* %5, i8** %12
%14 = load i64, i64* %7
%15 = load i64, i64* %8
%16 = call i8* @calloc(i64 %14, i64 %15)
store i8* %16, i8** %13
%17 = load i8*, i8** %13
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %6
%20 = load i64, i64* %7
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %19, %6
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %10
%25 = load i32, i32* %11
%26 = load i8*, i8** %12
%27 = load i8*, i8** %9
%28 = load i64, i64* %7
%29 = load i64, i64* %7
%30 = load i64, i64* %8
%31 = mul i64 %29, %30
%32 = load i32, i32* @SIZE_MAX
%33 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %25, i8* %26, i8* %27, i64 %28, i64 %31, i32 %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %19
%37 = load i8*, i8** %13
ret i8* %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [100 x i8] c"%s:%d @%s :: Failed to reallocate %s array of size %lld (%llu bytes)!\0AMaximal size of size_t : %lu\0A\00"
@SIZE_MAX = global i32 0
@EXIT_FAILURE = global i32 0
define noalias i8* @safe_calloc_helper(i64 %0, i64 %1, i8* %2, i8* %3, i32 %4, i8* %5) {
%7 = tail call i8* @calloc(i64 %0, i64 %1)
%8 = icmp eq i8* %7, null
%9 = icmp slt i64 %0, 0
%10 = or i1 %9, %8
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = mul i64 %1, %0
%14 = load i32, i32* @SIZE_MAX
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %4, i8* %5, i8* %2, i64 %0, i64 %13, i32 %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %6
ret i8* %7
}