#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*/ ENOMEM;
void *calloc(size_t, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void *mem_calloc_func(size_t count, size_t size) {
  void *res;
  if (!count || !size)
    return NULL;
  res = calloc(count, size);
  if (!res) {
    fprintf(stderr,
            "mem_calloc(): %s trying to allocate "
            "%zu"
            " bytes\n",
            strerror(ENOMEM), count * size);
    ;
    perror("mem_calloc");
  }
  return res;
}


x86 assembly (clang, -O0):
<mem_calloc_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <mem_calloc_func+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1173 <mem_calloc_func+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11d8 <mem_calloc_func+0x98>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d0 <mem_calloc_func+0x90>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
imul   -0x18(%rbp),%rcx
lea    0xe41(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe64(%rip),%rdi
call   1050 <perror@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_calloc_func>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
test   %rdi,%rdi
je     1163 <mem_calloc_func+0x23>
mov    %rsi,%r14
test   %rsi,%rsi
je     1163 <mem_calloc_func+0x23>
mov    %rdi,%rbx
mov    %r14,%rsi
call   1030 <calloc@plt>
test   %rax,%rax
je     1168 <mem_calloc_func+0x28>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e69(%rip),%rax
mov    (%rax),%ebp
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
imul   %rbx,%r14
lea    0xe76(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %r14,%rcx
call   1040 <fprintf@plt>
lea    0xe91(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
jmp    1163 <mem_calloc_func+0x23>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"mem_calloc(): %s trying to allocate %zu bytes\0A\00"
@ENOMEM = global i32 0
@.str.1 = [11 x i8] c"mem_calloc\00"
define noalias i8* @mem_calloc_func(i64 %0, i64 %1) {
%3 = icmp ne i64 %0, 0
%4 = icmp ne i64 %1, 0
%5 = and i1 %3, %4
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = tail call i8* @calloc(i64 %0, i64 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = load i32, i32* @ENOMEM
%12 = tail call i8* @strerror(i32 %11)
%13 = mul i64 %1, %0
%14 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %12, i64 %13)
%15 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %6, %9, %2
%17 = phi i8* [ null, %2 ], [ null, %9 ], [ %7, %6 ]
ret i8* %17
}