#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;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           char const *, char const *, long long, long long,
                           int /*<<< orphan*/);
void *malloc(long long);
int /*<<< orphan*/ stderr;
void *safe_malloc_helper(long long s, size_t t, const char *typ,
                         const char *file, int line, const char *func) {
  void *pn = malloc(s * t);
  if (pn == NULL || s < 0) {
    fprintf(
        stderr,
        "%s:%d @%s :: Failed to allocate %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_malloc_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
imul   -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1178 <safe_malloc_helper+0x48>
cmpq   $0x0,-0x8(%rbp)
jge    11cd <safe_malloc_helper+0x9d>
mov    0x2e61(%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    0x2e24(%rip),%rax
mov    (%rax),%eax
lea    0xe53(%rip),%rsi
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1030 <fprintf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_malloc_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,%rbx
mov    %rdi,%r14
imul   %rdi,%rbx
mov    %rbx,%rdi
call   1040 <malloc@plt>
test   %r14,%r14
js     1172 <safe_malloc_helper+0x42>
test   %rax,%rax
je     1172 <safe_malloc_helper+0x42>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
lea    0xe71(%rip),%rsi
mov    %rbp,%rdx
mov    %r13d,%ecx
mov    %r15,%r8
mov    %r12,%r9
push   %rax
push   %rbx
push   %r14
call   1030 <fprintf@plt>
add    $0x20,%rsp
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [98 x i8] c"%s:%d @%s :: Failed to allocate %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_malloc_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 = mul i64 %14, %15
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %13
%18 = load i8*, i8** %13
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %6
%21 = load i64, i64* %7
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %37
23: ; preds = %20, %6
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %10
%26 = load i32, i32* %11
%27 = load i8*, i8** %12
%28 = load i8*, i8** %9
%29 = load i64, i64* %7
%30 = load i64, i64* %7
%31 = load i64, i64* %8
%32 = mul i64 %30, %31
%33 = load i32, i32* @SIZE_MAX
%34 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %26, i8* %27, i8* %28, i64 %29, i64 %32, i32 %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %20
%38 = load i8*, i8** %13
ret i8* %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [98 x i8] c"%s:%d @%s :: Failed to allocate %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_malloc_helper(i64 %0, i64 %1, i8* %2, i8* %3, i32 %4, i8* %5) {
%7 = mul i64 %1, %0
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
%10 = icmp slt i64 %0, 0
%11 = or i1 %10, %9
br i1 %11, label %12, label %18
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = load i32, i32* @SIZE_MAX
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %4, i8* %5, i8* %2, i64 %0, i64 %7, i32 %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %6
ret i8* %8
}