#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 */
typedef size_t u_long;

/* Variables and functions */
void **calloc(size_t, size_t);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
void *gcalloc(size_t nmemb, size_t size) {
  void **ptr;
  if (nmemb == 0 || size == 0) {
    printf("gcalloc: zero size\n");
    exit(-1);
  }
  ptr = calloc(nmemb, size);
  if (ptr == NULL) {
    printf("gcalloc: out of memory (allocating %lu bytes)\n",
           (u_long)nmemb * size);
    exit(-1);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<gcalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1156 <gcalloc+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    116e <gcalloc+0x3e>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <gcalloc+0x7b>
mov    -0x8(%rbp),%rsi
imul   -0x10(%rbp),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gcalloc>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1169 <gcalloc+0x29>
mov    %rsi,%r14
test   %rsi,%rsi
je     1169 <gcalloc+0x29>
mov    %rdi,%rbx
mov    %r14,%rsi
call   1050 <calloc@plt>
test   %rax,%rax
je     117f <gcalloc+0x3f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
imul   %rbx,%r14
lea    0xe76(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"gcalloc: zero size\0A\00"
@.str.1 = [47 x i8] c"gcalloc: out of memory (allocating %lu bytes)\0A\00"
define i8* @gcalloc(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* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i64, i64* %4
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8, %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %8
%15 = load i64, i64* %3
%16 = load i64, i64* %4
%17 = call i8** @calloc(i64 %15, i64 %16)
store i8** %17, i8*** %5
%18 = load i8**, i8*** %5
%19 = icmp eq i8** %18, null
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = load i64, i64* %3
%22 = load i64, i64* %4
%23 = mul i64 %21, %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %23)
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %14
%27 = load i8**, i8*** %5
%28 = bitcast i8** %27 to i8*
ret i8* %28
}

LLVM IR (-O2):
@.str.1 = [47 x i8] c"gcalloc: out of memory (allocating %lu bytes)\0A\00"
@str = [19 x i8] c"gcalloc: zero size\00"
define noalias i8* @gcalloc(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 %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = tail call i8** @calloc(i64 %0, i64 %1)
%11 = icmp eq i8** %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = mul i64 %1, %0
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %13)
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %9
%17 = bitcast i8** %10 to i8*
ret i8* %17
}