#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 */
struct ll_dict {
  int dummy;
};

/* Variables and functions */
char EOF;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ dict_add(struct ll_dict *, char *);
struct ll_dict *dict_destroy(struct ll_dict *);
int /*<<< orphan*/ dict_dump(struct ll_dict *);
int dict_find(struct ll_dict *, char *);
struct ll_dict *dict_init();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ queue_flush();
int /*<<< orphan*/ queue_put(int);
int /*<<< orphan*/ queue_put_s(char *);
int /*<<< orphan*/ show_version();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  struct ll_dict *dict;
  char c;
  char str[1000 + 1];
  char curstr[1000 + 1];
  int code;
  int curcode;
  show_version();
  dict = dict_init();
  fprintf(stdout, "%c%c", 0x1f, 0x9d);
  fprintf(stdout, "%c", (char)(0x80 | 9));
  str[0] = '\0';
  curstr[0] = '\0';
  while ((c = fgetc(stdin)) != EOF) {
    strncat(curstr, &c, 1);
    fprintf(stderr, "ALGO: curstr={%s}\n", curstr);
    curcode = dict_find(dict, curstr);
    if (curcode < 0) {
      dict_add(dict, curstr);
      if (code < 0)
        queue_put_s(str);
      else
        queue_put(code);
      curstr[0] = c;
      curstr[1] = '\0';
    }
    code = curcode;
    strncpy(str, curstr, 1000);
  }
  if (code < 0)
    queue_put_s(str);
  else
    queue_put(code);
  dict_dump(dict);
  dict = dict_destroy(dict);
  queue_flush();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <show_version@plt>
mov    $0x0,%al
call   10f0 <dict_init@plt>
mov    %rax,-0x18(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
mov    $0x1f,%edx
mov    $0x9d,%ecx
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
mov    $0xffffff89,%edx
mov    $0x0,%al
call   10b0 <fprintf@plt>
movb   $0x0,-0x410(%rbp)
movb   $0x0,-0x800(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1090 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2d6f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1344 <main+0x164>
lea    -0x800(%rbp),%rdi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1080 <strncat@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    -0x800(%rbp),%rdx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x800(%rbp),%rsi
call   1060 <dict_find@plt>
mov    %eax,-0x808(%rbp)
cmpl   $0x0,-0x808(%rbp)
jge    131b <main+0x13b>
mov    -0x18(%rbp),%rdi
lea    -0x800(%rbp),%rsi
call   10d0 <dict_add@plt>
cmpl   $0x0,-0x804(%rbp)
jge    1300 <main+0x120>
lea    -0x410(%rbp),%rdi
call   1040 <queue_put_s@plt>
jmp    130b <main+0x12b>
mov    -0x804(%rbp),%edi
call   10a0 <queue_put@plt>
mov    -0x19(%rbp),%al
mov    %al,-0x800(%rbp)
movb   $0x0,-0x7ff(%rbp)
mov    -0x808(%rbp),%eax
mov    %eax,-0x804(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x800(%rbp),%rsi
mov    $0x3e8,%edx
call   1050 <strncpy@plt>
jmp    1256 <main+0x76>
cmpl   $0x0,-0x804(%rbp)
jge    1362 <main+0x182>
lea    -0x410(%rbp),%rdi
call   1040 <queue_put_s@plt>
jmp    136d <main+0x18d>
mov    -0x804(%rbp),%edi
call   10a0 <queue_put@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <dict_dump@plt>
mov    -0x18(%rbp),%rdi
call   10e0 <dict_destroy@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <queue_flush@plt>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7f8,%rsp
xor    %eax,%eax
call   1030 <show_version@plt>
xor    %eax,%eax
call   10f0 <dict_init@plt>
mov    %rax,%r14
mov    0x2dbf(%rip),%rbx
mov    (%rbx),%edi
lea    0xdee(%rip),%rsi
mov    $0x1f,%edx
mov    $0x9d,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdd6(%rip),%rsi
mov    $0xffffff89,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
movb   $0x0,0x400(%rsp)
movb   $0x0,0x10(%rsp)
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1090 <fgetc@plt>
mov    %al,0xf(%rsp)
lea    0x10(%rsp),%rbx
lea    0x400(%rsp),%r13
mov    0x2d75(%rip),%r12
jmp    12b0 <main+0xd0>
nopl   (%rax)
mov    %ebp,%edi
call   10a0 <queue_put@plt>
movzbl 0xf(%rsp),%eax
mov    %al,0x10(%rsp)
movb   $0x0,0x11(%rsp)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1050 <strncpy@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1090 <fgetc@plt>
mov    %al,0xf(%rsp)
mov    %r15d,%ebp
cmp    (%r12),%al
je     130e <main+0x12e>
mov    %rbx,%rdi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1080 <strncat@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    0xd33(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <dict_find@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    1285 <main+0xa5>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10d0 <dict_add@plt>
test   %ebp,%ebp
jns    1270 <main+0x90>
mov    %r13,%rdi
call   1040 <queue_put_s@plt>
jmp    1277 <main+0x97>
test   %r15d,%r15d
jns    1322 <main+0x142>
lea    0x400(%rsp),%rdi
call   1040 <queue_put_s@plt>
jmp    132a <main+0x14a>
mov    %r15d,%edi
call   10a0 <queue_put@plt>
mov    %r14,%rdi
call   10c0 <dict_dump@plt>
mov    %r14,%rdi
call   10e0 <dict_destroy@plt>
xor    %eax,%eax
call   1070 <queue_flush@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.ll_dict = type { i32 }
@stdout = global i32 0
@.str = [5 x i8] c"%c%c\00"
@.str.1 = [3 x i8] c"%c\00"
@stdin = global i32 0
@EOF = global i8 0
@stderr = global i32 0
@.str.2 = [19 x i8] c"ALGO: curstr={%s}\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ll_dict*
%7 = alloca i8
%8 = alloca [1001 x i8]
%9 = alloca [1001 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (...) @show_version()
%13 = call %struct.ll_dict* (...) @dict_init()
store %struct.ll_dict* %13, %struct.ll_dict** %6
%14 = load i32, i32* @stdout
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 31, i32 157)
%16 = load i32, i32* @stdout
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 -119)
%18 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
store i8 0, i8* %18
%19 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
store i8 0, i8* %19
br label %20
20: ; preds = %54, %2
%21 = load i32, i32* @stdin
%22 = call signext i8 @fgetc(i32 %21)
store i8 %22, i8* %7
%23 = sext i8 %22 to i32
%24 = load i8, i8* @EOF
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %59
27: ; preds = %20
%28 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%29 = call i32 @strncat(i8* %28, i8* %7, i32 1)
%30 = load i32, i32* @stderr
%31 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load %struct.ll_dict*, %struct.ll_dict** %6
%34 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%35 = call i32 @dict_find(%struct.ll_dict* %33, i8* %34)
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %54
38: ; preds = %27
%39 = load %struct.ll_dict*, %struct.ll_dict** %6
%40 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%41 = call i32 @dict_add(%struct.ll_dict* %39, i8* %40)
%42 = load i32, i32* %10
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
%46 = call i32 @queue_put_s(i8* %45)
br label %50
47: ; preds = %38
%48 = load i32, i32* %10
%49 = call i32 @queue_put(i32 %48)
br label %50
50: ; preds = %47, %44
%51 = load i8, i8* %7
%52 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
store i8 %51, i8* %52
%53 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 1
store i8 0, i8* %53
br label %54
54: ; preds = %50, %27
%55 = load i32, i32* %11
store i32 %55, i32* %10
%56 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
%57 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%58 = call i32 @strncpy(i8* %56, i8* %57, i32 1000)
br label %20
59: ; preds = %20
%60 = load i32, i32* %10
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
%64 = call i32 @queue_put_s(i8* %63)
br label %68
65: ; preds = %59
%66 = load i32, i32* %10
%67 = call i32 @queue_put(i32 %66)
br label %68
68: ; preds = %65, %62
%69 = load %struct.ll_dict*, %struct.ll_dict** %6
%70 = call i32 @dict_dump(%struct.ll_dict* %69)
%71 = load %struct.ll_dict*, %struct.ll_dict** %6
%72 = call %struct.ll_dict* @dict_destroy(%struct.ll_dict* %71)
store %struct.ll_dict* %72, %struct.ll_dict** %6
%73 = call i32 (...) @queue_flush()
%74 = load i32, i32* @EXIT_SUCCESS
%75 = call i32 @exit(i32 %74)
unreachable
}

LLVM IR (-O2):
%struct.ll_dict = type { i32 }
@stdout = global i32 0
@.str = [5 x i8] c"%c%c\00"
@.str.1 = [3 x i8] c"%c\00"
@stdin = global i32 0
@EOF = global i8 0
@stderr = global i32 0
@.str.2 = [19 x i8] c"ALGO: curstr={%s}\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca [1001 x i8]
%5 = alloca [1001 x i8]
%6 = getelementptr inbounds [1001 x i8], [1001 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%8 = tail call i32 (...) @show_version()
%9 = tail call %struct.ll_dict* (...) @dict_init()
%10 = load i32, i32* @stdout
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 31, i32 157)
%12 = load i32, i32* @stdout
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 -119)
store i8 0, i8* %6
store i8 0, i8* %7
%14 = load i32, i32* @stdin
%15 = call signext i8 @fgetc(i32 %14)
store i8 %15, i8* %3
%16 = load i8, i8* @EOF
%17 = icmp ne i8 %15, %16
%18 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 1
br label %19
19: ; preds = %2, %35
%20 = phi i32 [ undef, %2 ], [ %24, %35 ]
%21 = call i32 @strncat(i8* %7, i8* %3, i32 1)
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%24 = call i32 @dict_find(%struct.ll_dict* %9, i8* %7)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %19
%27 = call i32 @dict_add(%struct.ll_dict* %9, i8* %7)
%28 = icmp slt i32 %20, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @queue_put_s(i8* %6)
br label %33
31: ; preds = %26
%32 = call i32 @queue_put(i32 %20)
br label %33
33: ; preds = %31, %29
%34 = load i8, i8* %3
store i8 %34, i8* %7
store i8 0, i8* %18
br label %35
35: ; preds = %33, %19
%36 = call i32 @strncpy(i8* %6, i8* %7, i32 1000)
%37 = load i32, i32* @stdin
%38 = call signext i8 @fgetc(i32 %37)
store i8 %38, i8* %3
%39 = load i8, i8* @EOF
%40 = icmp eq i8 %38, %39
br i1 %40, label %41, label %19
41: ; preds = %35
%42 = icmp slt i32 %24, 0
br i1 %42, label %43, label %45
43: ; preds = %41
%44 = call i32 @queue_put_s(i8* %6)
br label %47
45: ; preds = %41
%46 = call i32 @queue_put(i32 %24)
br label %47
47: ; preds = %45, %43
%48 = call i32 @dict_dump(%struct.ll_dict* %9)
%49 = call %struct.ll_dict* @dict_destroy(%struct.ll_dict* %9)
%50 = call i32 (...) @queue_flush()
%51 = load i32, i32* @EXIT_SUCCESS
%52 = call i32 @exit(i32 %51)
unreachable
}