#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 get_long(int);
int get_word(int);
int unlzss(void *, int, int);
int unpack_room(void *out, int entry) {
  int d0, a2, a3;
  int resources;
  resources = get_long(0xf908);
  if (entry >= get_word(resources)) {
    return -1;
  }
  d0 = get_long(resources + 2 + (entry << 2));
  a2 = get_long(d0);
  a3 = get_long(d0 + 4);
  return unlzss(out, a2, a3);
}


x86 assembly (clang, -O0):
<unpack_room>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0xf908,%edi
call   1030 <get_long@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <get_word@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jl     1173 <unpack_room+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <unpack_room+0x84>
mov    -0x24(%rbp),%edi
add    $0x2,%edi
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    %eax,%edi
call   1030 <get_long@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <get_long@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
add    $0x4,%edi
call   1030 <get_long@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <unlzss@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack_room>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    $0xf908,%edi
call   1030 <get_long@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <get_word@plt>
cmp    %r15d,%eax
jle    118c <unpack_room+0x5c>
lea    (%rbx,%r15,4),%edi
add    $0x2,%edi
call   1030 <get_long@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <get_long@plt>
mov    %eax,%ebp
add    $0x4,%ebx
mov    %ebx,%edi
call   1030 <get_long@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <unlzss@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @unpack_room(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = call i32 @get_long(i32 63752)
store i32 %10, i32* %9
%11 = load i32, i32* %5
%12 = load i32, i32* %9
%13 = call i32 @get_word(i32 %12)
%14 = icmp sge i32 %11, %13
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %32
16: ; preds = %2
%17 = load i32, i32* %9
%18 = add nsw i32 %17, 2
%19 = load i32, i32* %5
%20 = shl i32 %19, 2
%21 = add nsw i32 %18, %20
%22 = call i32 @get_long(i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 @get_long(i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 4
%27 = call i32 @get_long(i32 %26)
store i32 %27, i32* %8
%28 = load i8*, i8** %4
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = call i32 @unlzss(i8* %28, i32 %29, i32 %30)
store i32 %31, i32* %3
br label %32
32: ; preds = %16, %15
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @unpack_room(i8* %0, i32 %1) {
%3 = tail call i32 @get_long(i32 63752)
%4 = tail call i32 @get_word(i32 %3)
%5 = icmp sgt i32 %4, %1
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = shl i32 %1, 2
%8 = or i32 %7, 2
%9 = add i32 %8, %3
%10 = tail call i32 @get_long(i32 %9)
%11 = tail call i32 @get_long(i32 %10)
%12 = add nsw i32 %10, 4
%13 = tail call i32 @get_long(i32 %12)
%14 = tail call i32 @unlzss(i8* %0, i32 %11, i32 %13)
br label %15
15: ; preds = %2, %6
%16 = phi i32 [ %14, %6 ], [ -1, %2 ]
ret i32 %16
}