#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 *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ msgMessage(int, char *, size_t, char *, size_t, char *);
void *CheckCalloc(size_t nelem, size_t elsize) {
  register void *r;
  if (!(r = malloc(nelem * elsize)))
    msgMessage((0x1000 | 0x0800 | 0x0001),
               "Can't calloc %d element%s of %d byte%s", nelem,
               nelem == 1 ? "" : "s", elsize, elsize == 1 ? "" : "s");
  memset(r, 0, nelem * elsize);
  return r;
}


x86 assembly (clang, -O0):
<CheckCalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
imul   -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a9 <CheckCalloc+0x79>
mov    -0x8(%rbp),%rdx
mov    -0x8(%rbp),%rsi
lea    0xeba(%rip),%rcx
lea    0xeb4(%rip),%rax
cmp    $0x1,%rsi
cmove  %rax,%rcx
mov    -0x10(%rbp),%r8
mov    -0x10(%rbp),%rsi
lea    0xe9c(%rip),%r9
lea    0xe96(%rip),%rax
cmp    $0x1,%rsi
cmove  %rax,%r9
mov    $0x1801,%edi
lea    0xe5c(%rip),%rsi
call   1050 <msgMessage@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
imul   -0x10(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckCalloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rbx
imul   %rdi,%rbx
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    118d <CheckCalloc+0x5d>
cmp    $0x1,%r12
lea    0xec6(%rip),%rax
lea    0xebe(%rip),%r9
mov    %r9,%rcx
cmove  %rax,%rcx
cmp    $0x1,%r15
cmove  %rax,%r9
lea    0xe83(%rip),%rsi
mov    $0x1801,%edi
mov    %r12,%rdx
mov    %r15,%r8
call   1050 <msgMessage@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Can't calloc %d element%s of %d byte%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
define i8* @CheckCalloc(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = load i64, i64* %3
%7 = load i64, i64* %4
%8 = mul i64 %6, %7
%9 = call i8* @malloc(i64 %8)
store i8* %9, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %23, label %11
11: ; preds = %2
%12 = load i64, i64* %3
%13 = load i64, i64* %3
%14 = icmp eq i64 %13, 1
%15 = zext i1 %14 to i64
%16 = select i1 %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%17 = load i64, i64* %4
%18 = load i64, i64* %4
%19 = icmp eq i64 %18, 1
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%22 = call i32 @msgMessage(i32 6145, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %12, i8* %16, i64 %17, i8* %21)
br label %23
23: ; preds = %11, %2
%24 = load i8*, i8** %5
%25 = load i64, i64* %3
%26 = load i64, i64* %4
%27 = mul i64 %25, %26
%28 = call i32 @memset(i8* %24, i32 0, i64 %27)
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
@.str = [39 x i8] c"Can't calloc %d element%s of %d byte%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
define i8* @CheckCalloc(i64 %0, i64 %1) {
%3 = mul i64 %1, %0
%4 = tail call i8* @malloc(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = icmp eq i64 %0, 1
%8 = select i1 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%9 = icmp eq i64 %1, 1
%10 = select i1 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%11 = tail call i32 @msgMessage(i32 6145, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %0, i8* %8, i64 %1, i8* %10)
br label %12
12: ; preds = %6, %2
%13 = tail call i32 @memset(i8* %4, i32 0, i64 %3)
ret i8* %4
}