#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 *Rmalloc(size_t, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ stderr;
void *Rcalloc(size_t nelem, size_t size, const char *file) {
  void *ret;
  size *= nelem;
  if (size == 0) {
    fprintf(stderr,
            "<MALLOC_DEBUG>\t"
            "WARNING: calloc() demands 0 Bytes (in %s)\n",
            file);
  }
  ret = Rmalloc(size, file);
  if (ret) {
    memset(ret, 0, size);
    return ret;
  } else {
    fprintf(stderr,
            "<MALLOC_DEBUG>\t"
            "WARNING: Out of memory! Returning NULL (in %s)\n",
            file);
    return NULL;
  }
}


x86 assembly (clang, -O0):
<Rcalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1175 <Rcalloc+0x45>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe90(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <Rmalloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ad <Rcalloc+0x7d>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ce <Rcalloc+0x9e>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Rcalloc>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
imul   %rsi,%rbx
test   %rbx,%rbx
jne    115c <Rcalloc+0x2c>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <Rmalloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     117e <Rcalloc+0x4e>
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
jmp    1196 <Rcalloc+0x66>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [58 x i8] c"<MALLOC_DEBUG>\09WARNING: calloc() demands 0 Bytes (in %s)\0A\00"
@.str.1 = [63 x i8] c"<MALLOC_DEBUG>\09WARNING: Out of memory! Returning NULL (in %s)\0A\00"
define i8* @Rcalloc(i64 %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store i64 %0, i64* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%9 = load i64, i64* %5
%10 = load i64, i64* %6
%11 = mul i64 %10, %9
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %7
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %14, %3
%19 = load i64, i64* %6
%20 = load i8*, i8** %7
%21 = call i8* @Rmalloc(i64 %19, i8* %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load i8*, i8** %8
%26 = load i64, i64* %6
%27 = call i32 @memset(i8* %25, i32 0, i64 %26)
%28 = load i8*, i8** %8
store i8* %28, i8** %4
br label %33
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %7
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %31)
store i8* null, i8** %4
br label %33
33: ; preds = %29, %24
%34 = load i8*, i8** %4
ret i8* %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [58 x i8] c"<MALLOC_DEBUG>\09WARNING: calloc() demands 0 Bytes (in %s)\0A\00"
@.str.1 = [63 x i8] c"<MALLOC_DEBUG>\09WARNING: Out of memory! Returning NULL (in %s)\0A\00"
define i8* @Rcalloc(i64 %0, i64 %1, i8* %2) {
%4 = mul i64 %1, %0
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %9
9: ; preds = %6, %3
%10 = tail call i8* @Rmalloc(i64 %4, i8* %2)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @memset(i8* %10, i32 0, i64 %4)
br label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %17
17: ; preds = %14, %12
ret i8* %10
}