#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*/ Panic(char *, char *, int, ...);
void *realloc(void *, size_t);
void *UtilSafeReallocInternal(int bugNumber, void *ptr, size_t size, char *file,
                              int lineno) {
  void *result = realloc(ptr, size);
  if (result == ((void *)0) && size != 0) {
    if (bugNumber == -1) {
      Panic("Unrecoverable memory allocation failure at %s:%d\n", file, lineno);
    } else {
      Panic("Unrecoverable memory allocation failure at %s:%d.  Bug "
            "number: %d\n",
            file, lineno, bugNumber);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<UtilSafeReallocInternal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a3 <UtilSafeReallocInternal+0x83>
cmpq   $0x0,-0x18(%rbp)
je     11a3 <UtilSafeReallocInternal+0x83>
cmpl   $0xffffffff,-0x4(%rbp)
jne    1186 <UtilSafeReallocInternal+0x66>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <Panic@plt>
jmp    119e <UtilSafeReallocInternal+0x7e>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <Panic@plt>
jmp    11a3 <UtilSafeReallocInternal+0x83>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UtilSafeReallocInternal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %edi,%r12d
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <realloc@plt>
mov    %rax,%rbx
test   %rbp,%rbp
je     117f <UtilSafeReallocInternal+0x5f>
test   %rbx,%rbx
jne    117f <UtilSafeReallocInternal+0x5f>
cmp    $0xffffffff,%r12d
je     116b <UtilSafeReallocInternal+0x4b>
lea    0xed9(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1030 <Panic@plt>
jmp    117f <UtilSafeReallocInternal+0x5f>
lea    0xe8e(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <Panic@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Unrecoverable memory allocation failure at %s:%d\0A\00"
@.str.1 = [67 x i8] c"Unrecoverable memory allocation failure at %s:%d. Bug number: %d\0A\00"
define i8* @UtilSafeReallocInternal(i32 %0, i8* %1, i64 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%12 = load i8*, i8** %7
%13 = load i64, i64* %8
%14 = call i8* @realloc(i8* %12, i64 %13)
store i8* %14, i8** %11
%15 = load i8*, i8** %11
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %33
17: ; preds = %5
%18 = load i64, i64* %8
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8*, i8** %9
%25 = load i32, i32* %10
%26 = call i32 (i8*, i8*, i32, ...) @Panic(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %25)
br label %32
27: ; preds = %20
%28 = load i8*, i8** %9
%29 = load i32, i32* %10
%30 = load i32, i32* %6
%31 = call i32 (i8*, i8*, i32, ...) @Panic(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 %29, i32 %30)
br label %32
32: ; preds = %27, %23
br label %33
33: ; preds = %32, %17, %5
%34 = load i8*, i8** %11
ret i8* %34
}

LLVM IR (-O2):
@.str = [50 x i8] c"Unrecoverable memory allocation failure at %s:%d\0A\00"
@.str.1 = [67 x i8] c"Unrecoverable memory allocation failure at %s:%d. Bug number: %d\0A\00"
define noalias i8* @UtilSafeReallocInternal(i32 %0, i8* nocapture %1, i64 %2, i8* %3, i32 %4) {
%6 = tail call i8* @realloc(i8* %1, i64 %2)
%7 = icmp eq i8* %6, null
%8 = icmp ne i64 %2, 0
%9 = and i1 %8, %7
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = icmp eq i32 %0, -1
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 (i8*, i8*, i32, ...) @Panic(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %4)
br label %16
14: ; preds = %10
%15 = tail call i32 (i8*, i8*, i32, ...) @Panic(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %4, i32 %0)
br label %16
16: ; preds = %12, %14, %5
ret i8* %6
}