// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movq %rdi, %r14
addq $0x20, %rdi
callq 0x6f88
testb %al, %al
je 0x814d
movq %r14, %rdi
callq 0x7e54
leaq 0x50(%r14), %r15
leaq 0x150(%r14), %rbx
movzbl (%r15), %eax
testl %eax, %eax
je 0x8174
cmpl $0x23, %eax
je 0x8174
movsbl %al, %esi
movq %rbx, %rdi
callq 0x8490
incq %r15
jmp 0x8130
movl 0x20(%r14), %eax
movl 0x44(%r14), %ecx
incl %ecx
movl %ecx, 0x44(%r14)
pushq $0x1
popq %rbx
cmpl $0x708, %ecx            # imm = 0x708
je 0x8210
cmpl $-0x1, %eax
jne 0x81cb
jmp 0x8210
cmpw $0x2f, 0xd0(%r14)
jne 0x8189
movq %r14, %rdi
callq 0x7fd8
jmp 0x81b2
leaq 0xd0(%r14), %rdi
leaq 0x2a66(%rip), %rsi      # 0xabfd
pushq $0xb
popq %rdx
callq 0x4210
movq %r14, %rdi
testl %eax, %eax
je 0x81ad
callq 0x832e
jmp 0x81b2
callq 0x8270
xorl %eax, %eax
movb %al, 0xd0(%r14)
movb %al, 0x50(%r14)
andl $0x0, 0x44(%r14)
cmpl $-0x1, 0x20(%r14)
je 0x820d
xorl %ebx, %ebx
cmpl $0x0, 0x150(%r14)
je 0x8210
addq $0x150, %r14            # imm = 0x150
movq %r14, %rdi
callq 0x84b2
movzbl %al, %eax
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
jbe 0x8218
leal -0x61(%rax), %ecx
cmpl $0x5, %ecx
ja 0x822c
leaq 0x29d4(%rip), %rax      # 0xabd4
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
pushq $0x6
jmp 0x820f
pushq $0x1
popq %rbx
movl %ebx, %eax
popq %rbx
popq %r14
popq %r15
retq
leaq 0x299d(%rip), %rax      # 0xabbc
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
pushq $0x7
jmp 0x820f
cmpl $0x53, %eax
je 0x8268
cmpl $0x57, %eax
je 0x8264
cmpl $0x73, %eax
je 0x826c
cmpl $0x77, %eax
jne 0x8210
pushq $0xa
jmp 0x820f
pushq $0xf
jmp 0x820f
pushq $0x3
jmp 0x820f
pushq $0x9
jmp 0x820f
pushq $0x5
jmp 0x820f
pushq $0xe
jmp 0x820f
pushq $0x2
jmp 0x820f
pushq $0x8
jmp 0x820f
pushq $0x4
jmp 0x820f
pushq $0xb
jmp 0x820f
pushq $0xd
jmp 0x820f
pushq $0xc
jmp 0x820f