#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;
void *calloc(size_t, size_t);
int /*<<< orphan*/ ssh_fatal(char *, ...);
void *ssh_calloc(size_t nmemb, size_t size) {
  void *ptr;
  if (size == 0 || nmemb == 0)
    ssh_fatal("xcalloc: zero size");
  if (SIZE_MAX / nmemb < size)
    ssh_fatal("xcalloc: nmemb * size > SIZE_MAX");
  ptr = calloc(nmemb, size);
  if (ptr == NULL)
    ssh_fatal("xcalloc: out of memory (allocating %zu bytes)", size * nmemb);
  return ptr;
}


x86 assembly (clang, -O0):
<ssh_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <ssh_calloc+0x26>
cmpq   $0x0,-0x8(%rbp)
jne    1154 <ssh_calloc+0x34>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <ssh_fatal@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x8(%rbp)
cmp    -0x10(%rbp),%rax
jae    117e <ssh_calloc+0x5e>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <ssh_fatal@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b1 <ssh_calloc+0x91>
mov    -0x10(%rbp),%rsi
imul   -0x8(%rbp),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <ssh_fatal@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssh_calloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdi,%rdi
je     1135 <ssh_calloc+0x15>
test   %r14,%r14
jne    1143 <ssh_calloc+0x23>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <ssh_fatal@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%rax
mov    %rax,%rcx
or     %r15,%rcx
shr    $0x20,%rcx
je     11a2 <ssh_calloc+0x82>
xor    %edx,%edx
div    %r15
cmp    %r14,%rax
jae    1171 <ssh_calloc+0x51>
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1040 <ssh_fatal@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1199 <ssh_calloc+0x79>
imul   %r15,%r14
lea    0xea5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <ssh_fatal@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %edx,%edx
div    %r15d
cmp    %r14,%rax
jb     1163 <ssh_calloc+0x43>
jmp    1171 <ssh_calloc+0x51>

LLVM IR (-O0):
@.str = [19 x i8] c"xcalloc: zero size\00"
@SIZE_MAX = global i64 0
@.str.1 = [33 x i8] c"xcalloc: nmemb * size > SIZE_MAX\00"
@.str.2 = [46 x i8] c"xcalloc: out of memory (allocating %zu bytes)\00"
define i8* @ssh_calloc(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i64, i64* %3
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = call i32 (i8*, ...) @ssh_fatal(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = load i64, i64* @SIZE_MAX
%15 = load i64, i64* %3
%16 = udiv i64 %14, %15
%17 = load i64, i64* %4
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 (i8*, ...) @ssh_fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = load i64, i64* %3
%23 = load i64, i64* %4
%24 = call i8* @calloc(i64 %22, i64 %23)
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i64, i64* %4
%29 = load i64, i64* %3
%30 = mul i64 %28, %29
%31 = call i32 (i8*, ...) @ssh_fatal(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 %30)
br label %32
32: ; preds = %27, %21
%33 = load i8*, i8** %5
ret i8* %33
}

LLVM IR (-O2):
@.str = [19 x i8] c"xcalloc: zero size\00"
@SIZE_MAX = global i64 0
@.str.1 = [33 x i8] c"xcalloc: nmemb * size > SIZE_MAX\00"
@.str.2 = [46 x i8] c"xcalloc: out of memory (allocating %zu bytes)\00"
define noalias i8* @ssh_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 %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @ssh_fatal(i8* getelementptr inbounds ([19 x i8], [19 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 (i8*, ...) @ssh_fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = tail call i8* @calloc(i64 %0, i64 %1)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = mul i64 %1, %0
%19 = tail call i32 (i8*, ...) @ssh_fatal(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 %18)
br label %20
20: ; preds = %17, %14
ret i8* %15
}