#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 */
void *calloc(size_t, size_t);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
void *eca_calloc(size_t Num, size_t bytes, char *NumName, char *VarName) {
  void *temp;
  if (Num * bytes == 0)
    return (NULL);
  if ((temp = calloc(Num, bytes)) == NULL) {
    printf("\n\nMEMORY ALLOCATION FAILURE:");
    printf("\nAttempted function: calloc(%s,%s)", NumName, VarName);
    printf("\n%s = %d Elements", NumName, (int)Num);
    printf("\n%s = %d bytes", VarName, (int)bytes);
    printf("\n\nExiting to system...\n\n");
    exit(1);
  }
  return (temp);
}


x86 assembly (clang, -O0):
<eca_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    $0x0,%rax
jne    1168 <eca_calloc+0x38>
movq   $0x0,-0x8(%rbp)
jmp    11f7 <eca_calloc+0xc7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ef <eca_calloc+0xbf>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eca_calloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
imul   %rdi,%rax
test   %rax,%rax
je     11c9 <eca_calloc+0x89>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
call   1050 <calloc@plt>
test   %rax,%rax
jne    11cb <eca_calloc+0x8b>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
mov    %r14,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"\0A\0AMEMORY ALLOCATION FAILURE:\00"
@.str.1 = [35 x i8] c"\0AAttempted function: calloc(%s,%s)\00"
@.str.2 = [18 x i8] c"\0A%s = %d Elements\00"
@.str.3 = [15 x i8] c"\0A%s = %d bytes\00"
@.str.4 = [25 x i8] c"\0A\0AExiting to system...\0A\0A\00"
define i8* @eca_calloc(i64 %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i64 %0, i64* %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i64, i64* %6
%12 = load i64, i64* %7
%13 = mul i64 %11, %12
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
store i8* null, i8** %5
br label %38
16: ; preds = %4
%17 = load i64, i64* %6
%18 = load i64, i64* %7
%19 = call i8* @calloc(i64 %17, i64 %18)
store i8* %19, i8** %10
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %36
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %8
%24 = load i8*, i8** %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %24)
%26 = load i8*, i8** %8
%27 = load i64, i64* %6
%28 = trunc i64 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %26, i32 %28)
%30 = load i8*, i8** %9
%31 = load i64, i64* %7
%32 = trunc i64 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %30, i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %16
%37 = load i8*, i8** %10
store i8* %37, i8** %5
br label %38
38: ; preds = %36, %15
%39 = load i8*, i8** %5
ret i8* %39
}

LLVM IR (-O2):
@.str = [29 x i8] c"\0A\0AMEMORY ALLOCATION FAILURE:\00"
@.str.1 = [35 x i8] c"\0AAttempted function: calloc(%s,%s)\00"
@.str.2 = [18 x i8] c"\0A%s = %d Elements\00"
@.str.3 = [15 x i8] c"\0A%s = %d bytes\00"
@str = [24 x i8] c"\0A\0AExiting to system...\0A\00"
define noalias i8* @eca_calloc(i64 %0, i64 %1, i8* %2, i8* %3) {
%5 = mul i64 %1, %0
%6 = icmp eq i64 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = tail call i8* @calloc(i64 %0, i64 %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3)
%13 = trunc i64 %0 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %13)
%15 = trunc i64 %1 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %3, i32 %15)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %7, %4
%20 = phi i8* [ null, %4 ], [ %8, %7 ]
ret i8* %20
}