#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 */
void *calloc(size_t, size_t);
int /*<<< orphan*/ sysdie(char *, unsigned long, char const *, int);
void *x_calloc(size_t n, size_t size, const char *file, int line) {
  void *p;
  n = (n > 0) ? n : 1;
  size = (size > 0) ? size : 1;
  p = calloc(n, size);
  if (p == NULL)
    sysdie("failed to calloc %lu bytes at %s line %d", (unsigned long)size,
           file, line);
  return p;
}


x86 assembly (clang, -O0):
<x_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jbe    114f <x_calloc+0x2f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    115d <x_calloc+0x3d>
mov    $0x1,%eax
mov    %rax,-0x30(%rbp)
jmp    115d <x_calloc+0x3d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    117d <x_calloc+0x5d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    118b <x_calloc+0x6b>
mov    $0x1,%eax
mov    %rax,-0x38(%rbp)
jmp    118b <x_calloc+0x6b>
mov    -0x38(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c6 <x_calloc+0xa6>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe3f(%rip),%rdi
call   1040 <sysdie@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x_calloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
mov    $0x1,%eax
cmove  %rax,%rdi
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
test   %rsi,%rsi
cmove  %rax,%rbp
mov    %rbp,%rsi
call   1030 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1168 <x_calloc+0x48>
lea    0xea6(%rip),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1040 <sysdie@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"failed to calloc %lu bytes at %s line %d\00"
define i8* @x_calloc(i64 %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i64 %0, i64* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i64, i64* %5
%11 = icmp ugt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = load i64, i64* %5
br label %15
14: ; preds = %4
br label %15
15: ; preds = %14, %12
%16 = phi i64 [ %13, %12 ], [ 1, %14 ]
store i64 %16, i64* %5
%17 = load i64, i64* %6
%18 = icmp ugt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i64, i64* %6
br label %22
21: ; preds = %15
br label %22
22: ; preds = %21, %19
%23 = phi i64 [ %20, %19 ], [ 1, %21 ]
store i64 %23, i64* %6
%24 = load i64, i64* %5
%25 = load i64, i64* %6
%26 = call i8* @calloc(i64 %24, i64 %25)
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i64, i64* %6
%31 = load i8*, i8** %7
%32 = load i32, i32* %8
%33 = call i32 @sysdie(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %30, i8* %31, i32 %32)
br label %34
34: ; preds = %29, %22
%35 = load i8*, i8** %9
ret i8* %35
}

LLVM IR (-O2):
@.str = [41 x i8] c"failed to calloc %lu bytes at %s line %d\00"
define noalias i8* @x_calloc(i64 %0, i64 %1, i8* %2, i32 %3) {
%5 = icmp eq i64 %0, 0
%6 = select i1 %5, i64 1, i64 %0
%7 = icmp eq i64 %1, 0
%8 = select i1 %7, i64 1, i64 %1
%9 = tail call i8* @calloc(i64 %6, i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 @sysdie(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %8, i8* %2, i32 %3)
br label %13
13: ; preds = %11, %4
ret i8* %9
}