#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long);
void *realloc(void *, unsigned long);
int /*<<< orphan*/ stderr;
void *zmalloc(unsigned long);
void *HTsrealloc(void *ptr, unsigned long new_size, long delta) {
  if (ptr == NULL)
    return zmalloc(new_size);
  ptr = realloc(ptr, new_size);
  if (!ptr && new_size > 0) {
    fprintf(stderr, "HTsrealloc: Unable to reallocate %lu bytes of memory\n",
            new_size);
    exit(1);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<HTsrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1171 <HTsrealloc+0x31>
mov    -0x18(%rbp),%rdi
call   1030 <zmalloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11c3 <HTsrealloc+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bb <HTsrealloc+0x7b>
cmpq   $0x0,-0x18(%rbp)
jbe    11bb <HTsrealloc+0x7b>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe54(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HTsrealloc>:
push   %rbx
mov    %rsi,%rbx
test   %rdi,%rdi
je     115d <HTsrealloc+0x1d>
mov    %rbx,%rsi
call   1050 <realloc@plt>
test   %rbx,%rbx
je     115b <HTsrealloc+0x1b>
test   %rax,%rax
je     1166 <HTsrealloc+0x26>
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <zmalloc@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"HTsrealloc: Unable to reallocate %lu bytes of memory\0A\00"
define i8* @HTsrealloc(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i64, i64* %6
%12 = call i8* @zmalloc(i64 %11)
store i8* %12, i8** %4
br label %29
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = call i8* @realloc(i8* %14, i64 %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %27, label %19
19: ; preds = %13
%20 = load i64, i64* %6
%21 = icmp ugt i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i64, i64* %6
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %19, %13
%28 = load i8*, i8** %5
store i8* %28, i8** %4
br label %29
29: ; preds = %27, %10
%30 = load i8*, i8** %4
ret i8* %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [54 x i8] c"HTsrealloc: Unable to reallocate %lu bytes of memory\0A\00"
define i8* @HTsrealloc(i8* %0, i64 %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i8* @zmalloc(i64 %1)
br label %16
7: ; preds = %3
%8 = tail call i8* @realloc(i8* %0, i64 %1)
%9 = icmp eq i8* %8, null
%10 = icmp ne i64 %1, 0
%11 = and i1 %10, %9
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 %1)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %7, %5
%17 = phi i8* [ %6, %5 ], [ %8, %7 ]
ret i8* %17
}