#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 const *gb_first_rom(char const *, size_t);
const void *gb_next_rom(const void *data, size_t length, const void *rom) {
  size_t diff = (const char *)rom - (const char *)data;
  if (diff > length) {
    return NULL;
  }
  size_t effective_length = length - diff;
  if (effective_length <= 0x200) {
    return NULL;
  }
  return gb_first_rom((const char *)rom + 0x134, effective_length - 0x134);
}


x86 assembly (clang, -O0):
<gb_next_rom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    114e <gb_next_rom+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    1194 <gb_next_rom+0x84>
mov    -0x18(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x200,-0x30(%rbp)
ja     1175 <gb_next_rom+0x65>
movq   $0x0,-0x8(%rbp)
jmp    1194 <gb_next_rom+0x84>
mov    -0x20(%rbp),%rdi
add    $0x134,%rdi
mov    -0x30(%rbp),%rsi
sub    $0x134,%rsi
call   1030 <gb_first_rom@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gb_next_rom>:
mov    %rdx,%rax
sub    %rdi,%rax
cmp    %rsi,%rax
ja     1127 <gb_next_rom+0x17>
sub    %rax,%rsi
cmp    $0x201,%rsi
jae    112a <gb_next_rom+0x1a>
xor    %eax,%eax
ret
add    $0x134,%rdx
add    $0xfffffffffffffecc,%rsi
mov    %rdx,%rdi
jmp    1030 <gb_first_rom@plt>

LLVM IR (-O0):
define i8* @gb_next_rom(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = load i8*, i8** %5
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
store i64 %14, i64* %8
%15 = load i64, i64* %8
%16 = load i64, i64* %6
%17 = icmp ugt i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %3
store i8* null, i8** %4
br label %32
19: ; preds = %3
%20 = load i64, i64* %6
%21 = load i64, i64* %8
%22 = sub i64 %20, %21
store i64 %22, i64* %9
%23 = load i64, i64* %9
%24 = icmp ule i64 %23, 512
br i1 %24, label %25, label %26
25: ; preds = %19
store i8* null, i8** %4
br label %32
26: ; preds = %19
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i64 308
%29 = load i64, i64* %9
%30 = sub i64 %29, 308
%31 = call i8* @gb_first_rom(i8* %28, i64 %30)
store i8* %31, i8** %4
br label %32
32: ; preds = %26, %25, %18
%33 = load i8*, i8** %4
ret i8* %33
}

LLVM IR (-O2):
define i8* @gb_next_rom(i8* %0, i64 %1, i8* %2) {
%4 = ptrtoint i8* %2 to i64
%5 = ptrtoint i8* %0 to i64
%6 = sub i64 %4, %5
%7 = icmp ugt i64 %6, %1
br i1 %7, label %15, label %8
8: ; preds = %3
%9 = sub i64 %1, %6
%10 = icmp ult i64 %9, 513
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %2, i64 308
%13 = add i64 %9, -308
%14 = tail call i8* @gb_first_rom(i8* %12, i64 %13)
br label %15
15: ; preds = %11, %8, %3
%16 = phi i8* [ null, %3 ], [ %14, %11 ], [ null, %8 ]
ret i8* %16
}