#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*/ HTS_error(int, char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
void *HTS_calloc(const size_t num, const size_t size) {
  size_t n = num * size;
  void *mem;
  if (n == 0)
    return NULL;
  mem = (void *)malloc(n);
  memset(mem, 0, n);
  if (mem == NULL)
    HTS_error(1, "HTS_calloc: Cannot allocate memory.\n");
  return mem;
}


x86 assembly (clang, -O0):
<HTS_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1165 <HTS_calloc+0x35>
movq   $0x0,-0x8(%rbp)
jmp    11a5 <HTS_calloc+0x75>
mov    -0x20(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
cmpq   $0x0,-0x28(%rbp)
jne    119d <HTS_calloc+0x6d>
mov    $0x1,%edi
lea    0xe68(%rip),%rsi
call   1050 <HTS_error@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HTS_calloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
imul   %rsi,%rbx
test   %rbx,%rbx
je     1170 <HTS_calloc+0x40>
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
test   %r14,%r14
jne    1173 <HTS_calloc+0x43>
lea    0xe9c(%rip),%rsi
mov    $0x1,%edi
call   1050 <HTS_error@plt>
jmp    1173 <HTS_calloc+0x43>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [37 x i8] c"HTS_calloc: Cannot allocate memory.\0A\00"
define i8* @HTS_calloc(i64 %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i64 %0, i64* %4
store i64 %1, i64* %5
%8 = load i64, i64* %4
%9 = load i64, i64* %5
%10 = mul i64 %8, %9
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* null, i8** %3
br label %27
14: ; preds = %2
%15 = load i64, i64* %6
%16 = call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = load i64, i64* %6
%20 = call i32 @memset(i8* %18, i32 0, i64 %19)
%21 = load i8*, i8** %7
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @HTS_error(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %14
%26 = load i8*, i8** %7
store i8* %26, i8** %3
br label %27
27: ; preds = %25, %13
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
@.str = [37 x i8] c"HTS_calloc: Cannot allocate memory.\0A\00"
define i8* @HTS_calloc(i64 %0, i64 %1) {
%3 = mul i64 %1, %0
%4 = icmp eq i64 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = tail call i64 @malloc(i64 %3)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @memset(i8* %7, i32 0, i64 %3)
%9 = icmp eq i64 %6, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @HTS_error(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %5, %10, %2
%13 = phi i8* [ null, %2 ], [ %7, %10 ], [ %7, %5 ]
ret i8* %13
}