#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 */
size_t SIZE_MAX;
int /*<<< orphan*/ fatal(char *);
void *kore_malloc(size_t);
void *kore_calloc(size_t memb, size_t len) {
  if (memb == 0 || len == 0)
    fatal("kore_calloc(): zero size");
  if (SIZE_MAX / memb < len)
    fatal("kore_calloc: memb * len > SIZE_MAX");
  return (kore_malloc(memb * len));
}


x86 assembly (clang, -O0):
<kore_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1146 <kore_calloc+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    1152 <kore_calloc+0x32>
lea    0xeb3(%rip),%rdi
call   1040 <fatal@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x8(%rbp)
cmp    -0x10(%rbp),%rax
jae    117a <kore_calloc+0x5a>
lea    0xea4(%rip),%rdi
call   1040 <fatal@plt>
mov    -0x8(%rbp),%rdi
imul   -0x10(%rbp),%rdi
call   1030 <kore_malloc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kore_calloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
je     1134 <kore_calloc+0x14>
test   %rbx,%rbx
jne    1140 <kore_calloc+0x20>
lea    0xec5(%rip),%rdi
call   1040 <fatal@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%rax
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
je     117f <kore_calloc+0x5f>
xor    %edx,%edx
div    %r14
cmp    %rbx,%rax
jae    116c <kore_calloc+0x4c>
lea    0xeb2(%rip),%rdi
call   1040 <fatal@plt>
imul   %r14,%rbx
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <kore_malloc@plt>
xor    %edx,%edx
div    %r14d
cmp    %rbx,%rax
jb     1160 <kore_calloc+0x40>
jmp    116c <kore_calloc+0x4c>

LLVM IR (-O0):
@.str = [25 x i8] c"kore_calloc(): zero size\00"
@SIZE_MAX = global i64 0
@.str.1 = [35 x i8] c"kore_calloc: memb * len > SIZE_MAX\00"
define i8* @kore_calloc(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%5 = load i64, i64* %3
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7, %2
%11 = call i32 @fatal(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = load i64, i64* @SIZE_MAX
%14 = load i64, i64* %3
%15 = udiv i64 %13, %14
%16 = load i64, i64* %4
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @fatal(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = load i64, i64* %3
%22 = load i64, i64* %4
%23 = mul i64 %21, %22
%24 = call i8* @kore_malloc(i64 %23)
ret i8* %24
}

LLVM IR (-O2):
@.str = [25 x i8] c"kore_calloc(): zero size\00"
@SIZE_MAX = global i64 0
@.str.1 = [35 x i8] c"kore_calloc: memb * len > SIZE_MAX\00"
define i8* @kore_calloc(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, 0
%4 = icmp eq i64 %1, 0
%5 = or i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @fatal(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %2, %6
%9 = load i64, i64* @SIZE_MAX
%10 = udiv i64 %9, %0
%11 = icmp ult i64 %10, %1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @fatal(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = mul i64 %1, %0
%16 = tail call i8* @kore_malloc(i64 %15)
ret i8* %16
}