#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 */
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ realloc(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int64_t *realloc_int64(int64_t *ptr, size_t count, char *varname) {
  int64_t *res = (int64_t *)realloc(ptr, sizeof(int64_t) * count);
  if (!count)
    return NULL;
  if (!res) {
    fprintf(stderr, "[Error] Failed to allocate %s!\n", varname);
    exit(4);
  }
  return res;
}


x86 assembly (clang, -O0):
<realloc_int64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1173 <realloc_int64+0x43>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <realloc_int64+0x79>
cmpq   $0x0,-0x28(%rbp)
jne    11a1 <realloc_int64+0x71>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realloc_int64>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0x0(,%rsi,4),%esi
call   1040 <realloc@plt>
test   %rbx,%rbx
je     1172 <realloc_int64+0x42>
test   %rax,%rax
jne    1174 <realloc_int64+0x44>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1050 <exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"[Error] Failed to allocate %s!\0A\00"
define i32* @realloc_int64(i32* %0, i64 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32*
store i32* %0, i32** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%9 = load i32*, i32** %5
%10 = load i64, i64* %6
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @realloc(i32* %9, i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %8
%15 = load i64, i64* %6
%16 = icmp ne i64 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %3
store i32* null, i32** %4
br label %28
18: ; preds = %3
%19 = load i32*, i32** %8
%20 = icmp ne i32* %19, null
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %7
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 4)
unreachable
26: ; preds = %18
%27 = load i32*, i32** %8
store i32* %27, i32** %4
br label %28
28: ; preds = %26, %17
%29 = load i32*, i32** %4
ret i32* %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"[Error] Failed to allocate %s!\0A\00"
define i32* @realloc_int64(i32* %0, i64 %1, i8* %2) {
%4 = trunc i64 %1 to i32
%5 = shl i32 %4, 2
%6 = tail call i64 @realloc(i32* %0, i32 %5)
%7 = icmp eq i64 %1, 0
br i1 %7, label %15, label %8
8: ; preds = %3
%9 = inttoptr i64 %6 to i32*
%10 = icmp eq i64 %6, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %2)
%14 = tail call i32 @exit(i32 4)
unreachable
15: ; preds = %8, %3
%16 = phi i32* [ null, %3 ], [ %9, %8 ]
ret i32* %16
}