// File: /workspace/github_cpp_makefile_star2_O3/mikeakohn[P]cloudtari/build/../src/TelevisionHttp.cxx
// Function: TelevisionHttp::read_http()
int TelevisionHttp::read_http()
{
  uint8_t buffer[8192];
  char line[1024];
  int ptr = 0, length;
  bool end_of_headers = false;

  while (!end_of_headers)
  {
    length = net_recv(buffer, sizeof(buffer), false);

    if (length <= 0 || length == 8192)
    {
      printf("Network receive error (return value %d).\n", length);
      return -1;
    }

    for (int n = 0; n < length; n++)
    {
      if (buffer[n] == '\r') { continue; }
      if (buffer[n] == '\n')
      {
        line[ptr] = 0;
        ptr = 0;

        if (line[0] == 0) { end_of_headers = true; }

        if (strncmp(line, "GET /", 5) == 0)
        {
//printf("line=%s\n", line);
          int ptr = 4;
          uint32_t n = 0;

          while (line[ptr] != 0)
          {
            if (line[ptr] == ' ') { break; }
            if (line[ptr] == '?') { break; }

            filename[n++] = line[ptr++];
            if (n >= sizeof(filename) - 1) { break; }
          }

          filename[n] = 0;
          n = 0;

          if (line[ptr++] == '?')
          {
            while (line[ptr] != 0)
            {
              if (line[ptr] == ' ') { break; }

              query_string[n++] = line[ptr++];
              if (n >= sizeof(query_string) - 1) { break; }
            }
          }

          query_string[n] = 0;
        }

        continue;
      }

      line[ptr++] = buffer[n];

      if (ptr == sizeof(line) - 1)
      {
        printf("Error: Http line too long (%d).\n", length);
        return -1;
      }
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2408, %rsp           # imm = 0x2408
movq %rdi, %r14
leaq 0x20(%rdi), %r15
xorl %ebx, %ebx
leaq 0x1(%rsp), %r13
movl $0x20544547, %ebp       # imm = 0x20544547
movabsq $-0x7ffffffeffffffff, %r12 # imm = 0x8000000100000001
movq %r15, %rdi
leaq 0x400(%rsp), %rsi
movl $0x2000, %edx           # imm = 0x2000
xorl %ecx, %ecx
callq 0x7358
testl %eax, %eax
jle 0x8876
cmpl $0x2000, %eax           # imm = 0x2000
je 0x8876
movl %eax, %ecx
xorl %edx, %edx
xorl %esi, %esi
movzbl 0x400(%rsp,%rdx), %edi
cmpl $0xd, %edi
je 0x8835
movslq %ebx, %r8
cmpl $0xa, %edi
jne 0x87db
movb $0x0, (%rsp,%r8)
cmpb $0x0, (%rsp)
sete %dil
orb %dil, %sil
movl (%rsp), %edi
xorl %ebp, %edi
movzbl 0x4(%rsp), %r8d
xorl $0x2f, %r8d
xorl %ebx, %ebx
orl %edi, %r8d
jne 0x8835
xorl %edi, %edi
movzbl 0x4(%rsp,%rdi), %r8d
cmpq $0x3f, %r8
ja 0x87bd
btq %r8, %r12
jb 0x87ed
movb %r8b, 0xd0(%r14,%rdi)
incq %rdi
cmpq $0x7f, %rdi
jne 0x87ab
movl $0x7f, %edi
movl $0x83, %r8d
jmp 0x87f1
leal 0x1(%r8), %ebx
movb %dil, (%rsp,%r8)
cmpl $0x3ff, %ebx            # imm = 0x3FF
jne 0x8835
jmp 0x884f
leal 0x4(%rdi), %r8d
movb $0x0, 0xd0(%r14,%rdi)
movslq %r8d, %rdi
cmpb $0x3f, (%rsp,%rdi)
jne 0x882d
movl %r8d, %r8d
addq %r13, %r8
xorl %edi, %edi
movzbl (%r8,%rdi), %r9d
testb $-0x21, %r9b
je 0x8829
movb %r9b, 0x50(%r14,%rdi)
incq %rdi
cmpq $0x7f, %rdi
jne 0x880b
movl $0x7f, %edi
movl %edi, %edi
jmp 0x882f
xorl %edi, %edi
movb $0x0, 0x50(%r14,%rdi)
incq %rdx
cmpq %rcx, %rdx
jne 0x8766
testb $0x1, %sil
je 0x8736
xorl %eax, %eax
jmp 0x8864
leaq 0x3552(%rip), %rdi      # 0xbda8
movl %eax, %esi
xorl %eax, %eax
callq 0x4050
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x2408, %rsp           # imm = 0x2408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x34fb(%rip), %rdi      # 0xbd78
jmp 0x8856
nop