#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 */
int /*<<< orphan*/ fatal(char *);
void *realloc(void *, size_t);
void *ckrealloc(void *ptr, size_t bytes) {
  register void *ret = NULL;
  if (ptr == NULL)
    fatal("Bad call to ckrealloc\n");
  else if ((ret = realloc(ptr, bytes)) == NULL)
    fatal("Out of memory\n");
  else
    return ret;
  return ret;
}


x86 assembly (clang, -O0):
<ckrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <ckrealloc+0x34>
lea    0xeb6(%rip),%rdi
call   1040 <fatal@plt>
jmp    1192 <ckrealloc+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1180 <ckrealloc+0x60>
lea    0xea1(%rip),%rdi
call   1040 <fatal@plt>
jmp    118d <ckrealloc+0x6d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119a <ckrealloc+0x7a>
jmp    1192 <ckrealloc+0x72>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ckrealloc>:
push   %rax
test   %rdi,%rdi
je     1132 <ckrealloc+0x12>
call   1030 <realloc@plt>
test   %rax,%rax
je     113b <ckrealloc+0x1b>
pop    %rcx
ret
lea    0xec7(%rip),%rdi
jmp    1142 <ckrealloc+0x22>
lea    0xed5(%rip),%rdi
call   1040 <fatal@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Bad call to ckrealloc\0A\00"
@.str.1 = [15 x i8] c"Out of memory\0A\00"
define i8* @ckrealloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* null, i8** %6
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %21
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i8* @realloc(i8* %12, i64 %13)
store i8* %14, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @fatal(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %20
18: ; preds = %11
%19 = load i8*, i8** %6
store i8* %19, i8** %3
br label %23
20: ; preds = %16
br label %21
21: ; preds = %20, %9
%22 = load i8*, i8** %6
store i8* %22, i8** %3
br label %23
23: ; preds = %21, %18
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@.str = [23 x i8] c"Bad call to ckrealloc\0A\00"
@.str.1 = [15 x i8] c"Out of memory\0A\00"
define noalias i8* @ckrealloc(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i8* @realloc(i8* %0, i64 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4, %2
%8 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %4 ]
%9 = tail call i32 @fatal(i8* %8)
br label %10
10: ; preds = %7, %4
%11 = phi i8* [ %5, %4 ], [ null, %7 ]
ret i8* %11
}