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


x86 assembly (clang, -O0):
<luaM_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1172 <luaM_realloc+0x32>
lea    0xe93(%rip),%rdi
call   1060 <lua_error@plt>
cmpq   $0x0,-0x18(%rbp)
jne    119e <luaM_realloc+0x5e>
cmpq   $0x0,-0x10(%rbp)
je     1191 <luaM_realloc+0x51>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <luaM_realloc+0xb3>
cmpq   $0x0,-0x10(%rbp)
je     11bf <luaM_realloc+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
jmp    11cc <luaM_realloc+0x8c>
mov    -0x20(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11eb <luaM_realloc+0xab>
lea    0xe3a(%rip),%rdi
call   1060 <lua_error@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luaM_realloc>:
push   %rax
test   %rsi,%rsi
je     1157 <luaM_realloc+0x17>
test   %rdi,%rdi
je     1163 <luaM_realloc+0x23>
call   1050 <realloc@plt>
test   %rax,%rax
je     1170 <luaM_realloc+0x30>
pop    %rcx
ret
test   %rdi,%rdi
je     117c <luaM_realloc+0x3c>
call   1030 <free@plt>
jmp    117c <luaM_realloc+0x3c>
mov    %rsi,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
jne    1155 <luaM_realloc+0x15>
lea    0xe89(%rip),%rdi
call   1060 <lua_error@plt>
xor    %eax,%eax
pop    %rcx
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* @luaM_realloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
store i64 %7, i64* %6
%8 = load i64, i64* %6
%9 = load i64, i64* %5
%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 i64, i64* %5
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %19, %16
store i8* null, i8** %3
br label %41
23: ; preds = %13
%24 = load i8*, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = load i64, i64* %6
%29 = call i8* @realloc(i8* %27, i64 %28)
br label %33
30: ; preds = %23
%31 = load i64, i64* %6
%32 = call i8* @malloc(i64 %31)
br label %33
33: ; preds = %30, %26
%34 = phi i8* [ %29, %26 ], [ %32, %30 ]
store i8* %34, i8** %4
%35 = load i8*, i8** %4
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @lua_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
%40 = load i8*, i8** %4
store i8* %40, i8** %3
br label %41
41: ; preds = %39, %22
%42 = load i8*, i8** %3
ret i8* %42
}

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