#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*/ lua_error(char *);
void *malloc(size_t);
void *realloc(void *, size_t);
void *luaI_realloc(void *oldblock, unsigned long size) {
  void *block;
  size_t s = (size_t)size;
  if (s != size)
    lua_error("Allocation Error: Block too big");
  block = oldblock ? realloc(oldblock, s) : malloc(s);
  if (block == 0)
    lua_error("not enough memory");
  return block;
}


x86 assembly (clang, -O0):
<luaI_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1162 <luaI_realloc+0x32>
lea    0xea3(%rip),%rdi
call   1050 <lua_error@plt>
cmpq   $0x0,-0x8(%rbp)
je     1183 <luaI_realloc+0x53>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
jmp    1190 <luaI_realloc+0x60>
mov    -0x20(%rbp),%rdi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11af <luaI_realloc+0x7f>
lea    0xe76(%rip),%rdi
call   1050 <lua_error@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luaI_realloc>:
push   %rbx
test   %rdi,%rdi
je     113d <luaI_realloc+0xd>
call   1040 <realloc@plt>
jmp    1145 <luaI_realloc+0x15>
mov    %rsi,%rdi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1159 <luaI_realloc+0x29>
lea    0xeac(%rip),%rdi
call   1050 <lua_error@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Allocation Error: Block too big\00"
@.str.1 = [18 x i8] c"not enough memory\00"
define i8* @luaI_realloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
store i64 %7, i64* %6
%8 = load i64, i64* %6
%9 = load i64, i64* %4
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @lua_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i64, i64* %6
%19 = call i8* @realloc(i8* %17, i64 %18)
br label %23
20: ; preds = %13
%21 = load i64, i64* %6
%22 = call i8* @malloc(i64 %21)
br label %23
23: ; preds = %20, %16
%24 = phi i8* [ %19, %16 ], [ %22, %20 ]
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @lua_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = load i8*, i8** %5
ret i8* %30
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"not enough memory\00"
define i8* @luaI_realloc(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i8* @realloc(i8* %0, i64 %1)
br label %8
6: ; preds = %2
%7 = tail call i8* @malloc(i64 %1)
br label %8
8: ; preds = %6, %4
%9 = phi i8* [ %5, %4 ], [ %7, %6 ]
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @lua_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
ret i8* %9
}