#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*/ unpack_resource(unsigned short);
unsigned char *find_room(unsigned short id) {
  unsigned char *dataptr = (unsigned char *)0xd000;
  unpack_resource(id);
  while (1) {
    if (dataptr[1] == 'Q') {
      if (dataptr[2] == (id & 0xff) && dataptr[3] == (id >> 8)) {
        return dataptr;
      }
    }
    dataptr += *dataptr + 1;
    while (*dataptr) {
      dataptr += *dataptr + 1;
    }
    dataptr++;
  }
}


x86 assembly (clang, -O0):
<find_room>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    $0xd000,%eax
mov    %rax,-0x10(%rbp)
movzwl -0x2(%rbp),%edi
call   1030 <unpack_resource@plt>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x51,%eax
jne    1182 <find_room+0x72>
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
movzwl -0x2(%rbp),%ecx
and    $0xff,%ecx
cmp    %ecx,%eax
jne    117d <find_room+0x6d>
mov    -0x10(%rbp),%rax
movzbl 0x3(%rax),%eax
movzwl -0x2(%rbp),%ecx
sar    $0x8,%ecx
cmp    %ecx,%eax
jne    117d <find_room+0x6d>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret
jmp    1182 <find_room+0x72>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c4 <find_room+0xb4>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    119a <find_room+0x8a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1131 <find_room+0x21>

x86 assembly (clang, -O2):
<find_room>:
push   %rbx
mov    %edi,%ebx
call   1030 <unpack_resource@plt>
mov    %ebx,%esi
shr    $0x8,%esi
mov    $0xd000,%eax
cmpb   $0x51,0x1(%rax)
je     117d <find_room+0x6d>
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
lea    (%rcx,%rax,1),%rdx
add    $0x1,%rdx
mov    0x1(%rcx,%rax,1),%cl
test   %cl,%cl
je     1170 <find_room+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl %cl,%ecx
lea    (%rcx,%rdx,1),%rax
add    $0x1,%rax
movzbl 0x1(%rcx,%rdx,1),%ecx
mov    %rax,%rdx
test   %cl,%cl
jne    1150 <find_room+0x40>
jmp    1173 <find_room+0x63>
nopl   0x0(%rax)
mov    %rdx,%rax
add    $0x1,%rax
cmpb   $0x51,0x1(%rax)
jne    1130 <find_room+0x20>
cmp    %bl,0x2(%rax)
jne    1130 <find_room+0x20>
movzbl 0x3(%rax),%ecx
cmp    %cx,%si
jne    1130 <find_room+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define i8* @find_room(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i8*
store i16 %0, i16* %2
store i8* inttoptr (i64 53248 to i8*), i8** %3
%4 = load i16, i16* %2
%5 = call i32 @unpack_resource(i16 zeroext %4)
br label %6
6: ; preds = %1, %53
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = icmp eq i32 %10, 81
br i1 %11, label %12, label %33
12: ; preds = %6
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 2
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = load i16, i16* %2
%18 = zext i16 %17 to i32
%19 = and i32 %18, 255
%20 = icmp eq i32 %16, %19
br i1 %20, label %21, label %32
21: ; preds = %12
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 3
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = load i16, i16* %2
%27 = zext i16 %26 to i32
%28 = ashr i32 %27, 8
%29 = icmp eq i32 %25, %28
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = load i8*, i8** %3
ret i8* %31
32: ; preds = %21, %12
br label %33
33: ; preds = %32, %6
%34 = load i8*, i8** %3
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = add nsw i32 %36, 1
%38 = load i8*, i8** %3
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %3
br label %41
41: ; preds = %45, %33
%42 = load i8*, i8** %3
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load i8*, i8** %3
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = add nsw i32 %48, 1
%50 = load i8*, i8** %3
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %50, i64 %51
store i8* %52, i8** %3
br label %41
53: ; preds = %41
%54 = load i8*, i8** %3
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %3
br label %6
}

LLVM IR (-O2):
define i8* @find_room(i16 zeroext %0) {
%2 = tail call i32 @unpack_resource(i16 zeroext %0)
%3 = trunc i16 %0 to i8
%4 = lshr i16 %0, 8
br label %5
5: ; preds = %35, %1
%6 = phi i8* [ inttoptr (i64 53248 to i8*), %1 ], [ %37, %35 ]
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 81
br i1 %9, label %10, label %20
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %6, i64 2
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, %3
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %6, i64 3
%16 = load i8, i8* %15
%17 = zext i8 %16 to i16
%18 = icmp eq i16 %4, %17
br i1 %18, label %19, label %20
19: ; preds = %14
ret i8* %6
20: ; preds = %10, %14, %5
%21 = load i8, i8* %6
%22 = zext i8 %21 to i64
%23 = add nuw nsw i64 %22, 1
%24 = getelementptr inbounds i8, i8* %6, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %20, %27
%28 = phi i8 [ %33, %27 ], [ %25, %20 ]
%29 = phi i8* [ %32, %27 ], [ %24, %20 ]
%30 = zext i8 %28 to i64
%31 = add nuw nsw i64 %30, 1
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %27
35: ; preds = %27, %20
%36 = phi i8* [ %24, %20 ], [ %32, %27 ]
%37 = getelementptr inbounds i8, i8* %36, i64 1
br label %5
}