#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*/ die(char *, ...);
void *realloc(void *, size_t);
void *sRealloc(void *ptr, size_t size) {
  if (size == 0) {
    die("unable to reallocate 0 bytes");
  }
  void *data = realloc(ptr, size);
  if (data == NULL) {
    die("out of memory: failed to reallocate %zu bytes", size);
  }
  return data;
}


x86 assembly (clang, -O0):
<sRealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1149 <sRealloc+0x29>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <die@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <sRealloc+0x57>
mov    -0x10(%rbp),%rsi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <die@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sRealloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
jne    113d <sRealloc+0x1d>
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1040 <die@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1161 <sRealloc+0x41>
lea    0xec6(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <die@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [29 x i8] c"unable to reallocate 0 bytes\00"
@.str.1 = [46 x i8] c"out of memory: failed to reallocate %zu bytes\00"
define i8* @sRealloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = load i8*, i8** %3
%12 = load i64, i64* %4
%13 = call i8* @realloc(i8* %11, i64 %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i64, i64* %4
%18 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i64 %17)
br label %19
19: ; preds = %16, %10
%20 = load i8*, i8** %5
ret i8* %20
}

LLVM IR (-O2):
@.str = [29 x i8] c"unable to reallocate 0 bytes\00"
@.str.1 = [46 x i8] c"out of memory: failed to reallocate %zu bytes\00"
define noalias i8* @sRealloc(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = tail call i8* @realloc(i8* %0, i64 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i64 %1)
br label %11
11: ; preds = %9, %6
ret i8* %7
}