#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 */
scalar_t__ eestrmatch(int, char *);
int findend(int);
int findoccupied(int);
int findKey(char *id) {
  int start = 0;
  while (start < 2047 - 4) {
    start = findoccupied(start);
    if (start == ((int)-1))
      return ((int)-1);
    if (eestrmatch(start, id))
      return start;
    start = findend(start);
    start = findend(start);
  }
  return ((int)-1);
}


x86 assembly (clang, -O0):
<findKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x7fb,-0x14(%rbp)
jge    11ad <findKey+0x7d>
mov    -0x14(%rbp),%edi
call   1030 <findoccupied@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1171 <findKey+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <findKey+0x84>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <eestrmatch@plt>
cmp    $0x0,%rax
je     1192 <findKey+0x62>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <findKey+0x84>
mov    -0x14(%rbp),%edi
call   1050 <findend@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <findend@plt>
mov    %eax,-0x14(%rbp)
jmp    1143 <findKey+0x13>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findKey>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
mov    $0xffffffff,%ebx
xchg   %ax,%ax
mov    %eax,%edi
call   1030 <findoccupied@plt>
cmp    $0xffffffff,%eax
je     1176 <findKey+0x46>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <eestrmatch@plt>
test   %rax,%rax
jne    1174 <findKey+0x44>
mov    %ebp,%edi
call   1050 <findend@plt>
mov    %eax,%edi
call   1050 <findend@plt>
cmp    $0x7fb,%eax
jl     1140 <findKey+0x10>
jmp    1176 <findKey+0x46>
mov    %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @findKey(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %21, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 2043
br i1 %7, label %8, label %26
8: ; preds = %5
%9 = load i32, i32* %4
%10 = call i32 @findoccupied(i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 -1, i32* %2
br label %27
14: ; preds = %8
%15 = load i32, i32* %4
%16 = load i8*, i8** %3
%17 = call i64 @eestrmatch(i32 %15, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %27
21: ; preds = %14
%22 = load i32, i32* %4
%23 = call i32 @findend(i32 %22)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = call i32 @findend(i32 %24)
store i32 %25, i32* %4
br label %5
26: ; preds = %5
store i32 -1, i32* %2
br label %27
27: ; preds = %26, %19, %13
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @findKey(i8* %0) {
br label %2
2: ; preds = %1, %9
%3 = phi i32 [ 0, %1 ], [ %11, %9 ]
%4 = tail call i32 @findoccupied(i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = tail call i64 @eestrmatch(i32 %4, i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = tail call i32 @findend(i32 %4)
%11 = tail call i32 @findend(i32 %10)
%12 = icmp slt i32 %11, 2043
br i1 %12, label %2, label %13
13: ; preds = %9, %6, %2
%14 = phi i32 [ -1, %2 ], [ %4, %6 ], [ -1, %9 ]
ret i32 %14
}