#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(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ stderr;
void *xcalloc(void *pointer, int size) {
  void *ret;
  if (pointer)
    free(pointer);
  if (!(ret = calloc(1, size))) {
    fprintf(stderr, "xcalloc: allocation error, size = %d\n", size);
    exit(1);
  } else {
    return ret;
  }
}


x86 assembly (clang, -O0):
<xcalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1163 <xcalloc+0x23>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a0 <xcalloc+0x60>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcalloc>:
push   %rbx
mov    %esi,%ebx
test   %rdi,%rdi
je     114d <xcalloc+0xd>
call   1030 <free@plt>
mov    $0x1,%edi
mov    %ebx,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1160 <xcalloc+0x20>
pop    %rbx
ret
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"xcalloc: allocation error, size = %d\0A\00"
define i8* @xcalloc(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32 @free(i8* %9)
br label %11
11: ; preds = %8, %2
%12 = load i32, i32* %4
%13 = call i8* @calloc(i32 1, i32 %12)
store i8* %13, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = load i32, i32* %4
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = load i8*, i8** %5
ret i8* %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"xcalloc: allocation error, size = %d\0A\00"
define noalias i8* @xcalloc(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @free(i8* %0)
br label %6
6: ; preds = %4, %2
%7 = tail call i8* @calloc(i32 1, i32 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %1)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6
ret i8* %7
}