// File: /workspace/github_cpp_makefile_star2_O1/mikeakohn[P]cloudtari/build/../src/TelevisionHttp.cxx
// Function: TelevisionHttp::handle_events()
int TelevisionHttp::handle_events()
{
  if (net_has_data())
  {
    read_http();

    // The query string from the browser is ?keys#timestamp.
    // The timestamp is unfortunate since it seems the browser is ignoring
    // the cache expire headers.
    int n = 0;

    while (query_string[n] != 0)
    {
      if (query_string[n] == '#') { break; }
      key_queue.append(query_string[n]);
      n++;
    }

    if (strcmp(filename, "/") == 0)
    {
      send_index_html();
    }
      else
    if (strcmp(filename, "/image.gif") == 0)
    {
      send_gif();
    }
      else
    {
      send_404();
    }

    filename[0] = 0;
    query_string[0] = 0;
    no_data_count = 0;
  }
    else
  {
    no_data_count++;

    // If there aren't any web requests for a while, assume the connection
    // is broken.
    if (no_data_count == 30 * 60) { return KEY_QUIT; }
  }

  if (!net_is_connected()) { return KEY_QUIT; }

  if (!key_queue.is_empty())
  {
    char c = key_queue.get_next();
    switch (c)
    {
      case 's': return KEY_DOWN_DOWN;
      case 'w': return KEY_UP_DOWN;
      case 'a': return KEY_LEFT_DOWN;
      case 'd': return KEY_RIGHT_DOWN;
      case 'f': return KEY_FIRE_DOWN;
      case 'e': return KEY_RESET_DOWN;
      case 'c': return KEY_SELECT_DOWN;
      case 'S': return KEY_DOWN_UP;
      case 'W': return KEY_UP_UP;
      case 'A': return KEY_LEFT_UP;
      case 'D': return KEY_RIGHT_UP;
      case 'F': return KEY_FIRE_UP;
      case 'E': return KEY_RESET_UP;
      case 'C': return KEY_SELECT_UP;
    }
  }

  return 0;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
addq $0x20, %rdi
callq 0x74a8
testb %al, %al
je 0x896d
movq %rbx, %rdi
callq 0x8518
leaq 0x50(%rbx), %rax
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x8993
cmpl $0x23, %ecx
je 0x8993
cmpl $0x20, 0x150(%rbx)
je 0x8968
movslq 0x158(%rbx), %rdx
leal 0x1(%rdx), %esi
movl %esi, 0x158(%rbx)
movb %cl, 0x15c(%rbx,%rdx)
cmpl $0x20, 0x158(%rbx)
jne 0x8962
movl $0x0, 0x158(%rbx)
incl 0x150(%rbx)
incq %rax
jmp 0x8923
movl 0x20(%rbx), %ecx
movl 0x44(%rbx), %edx
incl %edx
movl %edx, 0x44(%rbx)
movl $0x1, %eax
cmpl $0x708, %edx            # imm = 0x708
je 0x8aec
cmpl $-0x1, %ecx
jne 0x89f5
jmp 0x8aec
cmpw $0x2f, 0xd0(%rbx)
jne 0x89a7
movq %rbx, %rdi
callq 0x86bc
jmp 0x89dd
movabsq $0x672e6567616d692f, %rax # imm = 0x672E6567616D692F
xorq 0xd0(%rbx), %rax
movabsq $0x6669672e656761, %rcx # imm = 0x6669672E656761
xorq 0xd3(%rbx), %rcx
movq %rbx, %rdi
orq %rax, %rcx
je 0x89d8
callq 0x8d20
jmp 0x89dd
callq 0x8af6
xorl %eax, %eax
movb %al, 0xd0(%rbx)
movb %al, 0x50(%rbx)
movl $0x0, 0x44(%rbx)
cmpl $-0x1, 0x20(%rbx)
je 0x8a58
movl 0x150(%rbx), %edx
testl %edx, %edx
je 0x8aea
movslq 0x154(%rbx), %rax
leal 0x1(%rax), %esi
movl %esi, 0x154(%rbx)
movzbl 0x15c(%rbx,%rax), %eax
xorl %ecx, %ecx
cmpl $0x20, %esi
cmovel %ecx, %esi
movl %esi, 0x154(%rbx)
decl %edx
movl %edx, 0x150(%rbx)
cmpl $0x60, %eax
jg 0x8a62
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x8a81
leaq 0x2163(%rip), %rax      # 0xaba8
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0x7, %eax
jmp 0x8ae4
movl $0x1, %eax
jmp 0x8aec
leal -0x61(%rax), %edx
cmpl $0x5, %edx
ja 0x8a92
leaq 0x214f(%rip), %rax      # 0xabc0
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0x6, %eax
jmp 0x8ae4
cmpl $0x53, %eax
je 0x8adf
cmpl $0x57, %eax
jne 0x8aa3
movl $0xb, %eax
jmp 0x8ae4
cmpl $0x73, %eax
je 0x8aee
cmpl $0x77, %eax
jne 0x8aa3
movl $0xa, %eax
jmp 0x8ae4
movb $0x1, %cl
jmp 0x8ae6
movl $0x5, %eax
jmp 0x8ae4
movl $0x4, %eax
jmp 0x8ae4
movl $0x3, %eax
jmp 0x8ae4
movl $0x2, %eax
jmp 0x8ae4
movl $0x9, %eax
jmp 0x8ae4
movl $0x8, %eax
jmp 0x8ae4
movl $0xf, %eax
jmp 0x8ae4
movl $0xe, %eax
jmp 0x8ae4
movl $0xd, %eax
xorl %ecx, %ecx
testb %cl, %cl
je 0x8aec
xorl %eax, %eax
popq %rbx
retq
movl $0xc, %eax
jmp 0x8ae6
nop