#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);
void *calloc(size_t nmemb, size_t size) {
  if (size == 0)
    return NULL;
  if (nmemb == 0)
    return NULL;
  void *data = malloc(nmemb * size);
  if (data == NULL)
    return NULL;
  memset(data, 0, nmemb * size);
  return data;
}


x86 assembly (clang, -O0):
<calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1148 <calloc+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <calloc+0x86>
cmpq   $0x0,-0x10(%rbp)
jne    1160 <calloc+0x40>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <calloc+0x86>
mov    -0x10(%rbp),%rdi
imul   -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118a <calloc+0x6a>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <calloc+0x86>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
imul   -0x18(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calloc>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     115a <calloc+0x3a>
mov    %rsi,%rbx
test   %rsi,%rsi
je     115a <calloc+0x3a>
imul   %rdi,%rbx
mov    %rbx,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1157 <calloc+0x37>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
jmp    115a <calloc+0x3a>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @calloc(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* %5
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %29
10: ; preds = %2
%11 = load i64, i64* %4
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i8* null, i8** %3
br label %29
14: ; preds = %10
%15 = load i64, i64* %4
%16 = load i64, i64* %5
%17 = mul i64 %15, %16
%18 = call i8* @malloc(i64 %17)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %14
store i8* null, i8** %3
br label %29
22: ; preds = %14
%23 = load i8*, i8** %6
%24 = load i64, i64* %4
%25 = load i64, i64* %5
%26 = mul i64 %24, %25
%27 = call i32 @memset(i8* %23, i32 0, i64 %26)
%28 = load i8*, i8** %6
store i8* %28, i8** %3
br label %29
29: ; preds = %22, %21, %13, %9
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
define i8* @calloc(i64 %0, i64 %1) {
%3 = icmp eq i64 %1, 0
%4 = icmp eq i64 %0, 0
%5 = or i1 %4, %3
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = mul i64 %1, %0
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @memset(i8* %8, i32 0, i64 %7)
br label %12
12: ; preds = %10, %6, %2
%13 = phi i8* [ null, %2 ], [ %8, %10 ], [ null, %6 ]
ret i8* %13
}