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


x86 assembly (clang, -O0):
<kore_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x8(%rbp)
cmp    -0x10(%rbp),%rax
jae    1168 <kore_calloc+0x38>
lea    0xe9d(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x8(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <kore_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kore_calloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e96(%rip),%rax
mov    (%rax),%rax
mov    %rax,%rcx
or     %rdi,%rcx
shr    $0x20,%rcx
je     118c <kore_calloc+0x5c>
xor    %edx,%edx
div    %r14
cmp    %r15,%rax
jae    1167 <kore_calloc+0x37>
lea    0xe9e(%rip),%rdi
call   1050 <fatal@plt>
imul   %r14,%r15
mov    %r15,%rdi
call   1030 <kore_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <memset@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %edx,%edx
div    %r14d
cmp    %r15,%rax
jb     115b <kore_calloc+0x2b>
jmp    1167 <kore_calloc+0x37>

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

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