#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 *realloc(void *, size_t);
int /*<<< orphan*/ suicidef(char *, int /*<<< orphan*/, ...);
int /*<<< orphan*/ ucommatize(size_t);
void *realloc_or_die(char *id, void *_p, size_t size) {
  void *p;
  if (size == 0)
    size = 1;
  p = realloc(_p, size);
  if (p == NULL) {
    if (id == NULL)
      suicidef("call to realloc failed to allocate %s bytes", ucommatize(size));
    else
      suicidef("call to realloc failed to allocate %s bytes, for %s",
               ucommatize(size), id);
  };
  ;
  return p;
}


x86 assembly (clang, -O0):
<realloc_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1157 <realloc_or_die+0x27>
movq   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11be <realloc_or_die+0x8e>
cmpq   $0x0,-0x8(%rbp)
jne    119c <realloc_or_die+0x6c>
mov    -0x18(%rbp),%rdi
call   1050 <ucommatize@plt>
mov    %eax,%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <suicidef@plt>
jmp    11b9 <realloc_or_die+0x89>
mov    -0x18(%rbp),%rdi
call   1050 <ucommatize@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <suicidef@plt>
jmp    11be <realloc_or_die+0x8e>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realloc_or_die>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rdx,%rdx
mov    $0x1,%ebx
cmovne %rdx,%rbx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1040 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1189 <realloc_or_die+0x59>
mov    %rbx,%rdi
call   1050 <ucommatize@plt>
test   %r14,%r14
je     1179 <realloc_or_die+0x49>
lea    0xec1(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <suicidef@plt>
jmp    1189 <realloc_or_die+0x59>
lea    0xe80(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <suicidef@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [44 x i8] c"call to realloc failed to allocate %s bytes\00"
@.str.1 = [52 x i8] c"call to realloc failed to allocate %s bytes, for %s\00"
define i8* @realloc_or_die(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %3
store i64 1, i64* %6
br label %11
11: ; preds = %10, %3
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i8* @realloc(i8* %12, i64 %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %30
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i64, i64* %6
%22 = call i32 @ucommatize(i64 %21)
%23 = call i32 (i8*, i32, ...) @suicidef(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %29
24: ; preds = %17
%25 = load i64, i64* %6
%26 = call i32 @ucommatize(i64 %25)
%27 = load i8*, i8** %4
%28 = call i32 (i8*, i32, ...) @suicidef(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %26, i8* %27)
br label %29
29: ; preds = %24, %20
br label %30
30: ; preds = %29, %11
%31 = load i8*, i8** %7
ret i8* %31
}

LLVM IR (-O2):
@.str = [44 x i8] c"call to realloc failed to allocate %s bytes\00"
@.str.1 = [52 x i8] c"call to realloc failed to allocate %s bytes, for %s\00"
define noalias i8* @realloc_or_die(i8* %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
%5 = select i1 %4, i64 1, i64 %2
%6 = tail call i8* @realloc(i8* %1, i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %15
8: ; preds = %3
%9 = icmp eq i8* %0, null
%10 = tail call i32 @ucommatize(i64 %5)
br i1 %9, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i8*, i32, ...) @suicidef(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %15
13: ; preds = %8
%14 = tail call i32 (i8*, i32, ...) @suicidef(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %10, i8* %0)
br label %15
15: ; preds = %11, %13, %3
ret i8* %6
}