#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);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, size_t,
                           char const *, unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void *wrap_calloc(size_t nmemb, size_t size, const char *file,
                  unsigned int line, const char *func) {
  void *p = calloc(nmemb, size);
  if (NULL == p) {
    fprintf(stderr, "[%s] Failed to allocate %zd bytes at %s line %u: %s\n",
            func, nmemb * size, file, line, strerror(errno));
    exit(EXIT_FAILURE);
  }
  return p;
}


x86 assembly (clang, -O0):
<wrap_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    11e5 <wrap_calloc+0xa5>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x34(%rbp),%r9d
lea    0xe31(%rip),%rsi
mov    %eax,(%rsp)
call   1040 <fprintf@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x30(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrap_calloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1030 <calloc@plt>
test   %rax,%rax
je     1173 <wrap_calloc+0x33>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e66(%rip),%rax
mov    (%rax),%r13d
imul   %rbp,%rbx
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,(%rsp)
lea    0xe67(%rip),%rsi
mov    %r13d,%edi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
mov    %r14d,%r9d
call   1040 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"[%s] Failed to allocate %zd bytes at %s line %u: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @wrap_calloc(i64 %0, i64 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i64 %0, i64* %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = call i8* @calloc(i64 %12, i64 %13)
store i8* %14, i8** %11
%15 = load i8*, i8** %11
%16 = icmp eq i8* null, %15
br i1 %16, label %17, label %30
17: ; preds = %5
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %10
%20 = load i64, i64* %6
%21 = load i64, i64* %7
%22 = mul i64 %20, %21
%23 = load i8*, i8** %8
%24 = load i32, i32* %9
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %19, i64 %22, i8* %23, i32 %24, i32 %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %5
%31 = load i8*, i8** %11
ret i8* %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"[%s] Failed to allocate %zd bytes at %s line %u: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define noalias i8* @wrap_calloc(i64 %0, i64 %1, i8* %2, i32 %3, i8* %4) {
%6 = tail call i8* @calloc(i64 %0, i64 %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = mul i64 %1, %0
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %4, i64 %10, i8* %2, i32 %3, i32 %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %5
ret i8* %6
}