// File: /workspace/github_cpp_makefile_star2_O2/UTAP[P]APHTTP/server/server.cpp
// Function: Server::run()
void Server::run() {
  ::listen(sc, 10);

  struct sockaddr_in cli_addr;
  socklen_t clilen;
  clilen = sizeof(cli_addr);
  SOCKET newsc;

  while (true) {
    newsc = ::accept(sc, (struct sockaddr *)&cli_addr, &clilen);
    if (!ISVALIDSOCKET(newsc))
      throw Exception("Error on accept: " + string(getSocketError()));
    Response *res = NULL;
    try {
      char* data = new char[BUFSIZE + 1];
      size_t recv_len, recv_total_len = 0;
      Request *req = NULL;
      while (!req) {
        recv_len =
            recv(newsc, data + recv_total_len, BUFSIZE - recv_total_len, 0);
        if (recv_len > 0) {
          recv_total_len += recv_len;
          data[recv_total_len >= 0 ? recv_total_len : 0] = 0;
          req = parseRawReq(data, recv_total_len);
        } else
          break;
      }
      delete[] data;
      if (!recv_total_len) {
        CLOSESOCKET(newsc);
        continue;
      }
      req->log();
      size_t i = 0;
      for (; i < routes.size(); i++) {
        if (routes[i]->isMatch(req->getMethod(), req->getPath())) {
          res = routes[i]->handle(req);
          break;
        }
      }
      if (i == routes.size() && notFoundHandler) {
        res = notFoundHandler->callback(req);
      }
      delete req;
    } catch (const Exception& exc) {
      delete res;
      res = ServerErrorHandler::callback(exc.getMessage());
    }
    int si;
    res->log();
    string res_data = res->print(si);
    delete res;
    int wr = send(newsc, res_data.c_str(), si, 0);
    if (wr != si)
      throw Exception("Send error: " + string(getSocketError()));
    CLOSESOCKET(newsc);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, -0x38(%rbp)
movl (%rdi), %edi
pushq $0xa
popq %rsi
callq 0x43b0
leaq -0x40(%rbp), %rax
movl $0x10, (%rax)
movq -0x38(%rbp), %rax
movl (%rax), %edi
leaq -0xf0(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x4150
movl %eax, -0x2c(%rbp)
testl %eax, %eax
js 0xe109
movl $0x3f4001, %edi         # imm = 0x3F4001
callq 0x4030
movq %rax, %r13
xorl %r12d, %r12d
xorl %r15d, %r15d
testq %r15, %r15
jne 0xdf4d
leaq (%r12,%r13), %rsi
movl $0x3f4000, %edx         # imm = 0x3F4000
subq %r12, %rdx
movl -0x2c(%rbp), %edi
xorl %ecx, %ecx
callq 0x4160
testq %rax, %rax
je 0xdf4d
addq %rax, %r12
movb $0x0, (%r13,%r12)
movq %r13, %rdi
movq %r12, %rsi
callq 0xbc88
movq %rax, %r15
jmp 0xdf14
movq %r13, %rdi
callq 0x4420
testq %r12, %r12
je 0xdfc0
movq %r15, %rdi
callq 0x92f2
xorl %ebx, %ebx
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rbx
jae 0xdfcd
movq (%rax,%rbx,8), %r12
movq %r15, %rdi
leaq -0x110(%rbp), %r14
callq 0x8e02
movl %eax, %r13d
movq %r14, %rdi
movq %r15, %rsi
callq 0x8de0
movq %r12, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0xf2d4
movl %eax, %r12d
movq %r14, %rdi
callq 0x4638
testb %r12b, %r12b
jne 0xdfd2
incq %rbx
jmp 0xdf64
movl -0x2c(%rbp), %edi
callq 0x4600
jmp 0xdee0
xorl %r13d, %r13d
jmp 0xdffc
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax,%rbx,8), %rdi
xorl %r13d, %r13d
movq %r15, %rsi
callq 0xf2fa
movq -0x38(%rbp), %rdx
movq 0x10(%rdx), %rcx
subq 0x8(%rdx), %rcx
sarq $0x3, %rcx
movq %rax, %r13
cmpq %rbx, %rcx
jne 0xe01a
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdi
testq %rdi, %rdi
je 0xe01a
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movq %rax, %r13
movq %r15, %rdi
callq 0xe9b2
movq %r15, %rdi
callq 0x4330
movq %r13, %rdi
xorl %esi, %esi
callq 0x739a
leaq -0x60(%rbp), %rdi
movq %r13, %rsi
leaq -0x3c(%rbp), %rdx
callq 0x702e
movq %r13, %rdi
callq 0xe9e8
movq %r13, %rdi
callq 0x4330
movq -0x60(%rbp), %rsi
movslq -0x3c(%rbp), %rdx
movl -0x2c(%rbp), %edi
xorl %ecx, %ecx
callq 0x4220
cmpl %eax, -0x3c(%rbp)
jne 0xe16d
movl -0x2c(%rbp), %edi
callq 0x4600
leaq -0x60(%rbp), %rdi
callq 0x4638
jmp 0xdee0
movq %rdx, %r15
movq %rax, %r12
jmp 0xe0ac
jmp 0xe0a3
jmp 0xe0a3
movq %rdx, %r15
movq %rax, %r12
movq %r14, %rdi
callq 0x4638
jmp 0xe0a9
jmp 0xe0a3
movq %rdx, %r15
movq %rax, %r12
xorl %r13d, %r13d
cmpl $0x1, %r15d
jne 0xe266
movq %r12, %rdi
callq 0x41b0
movq %rax, %r15
testq %r13, %r13
je 0xe0ce
movq %r13, %rdi
callq 0xe9e8
movq %r13, %rdi
callq 0x4330
addq $0x8, %r15
leaq -0xe0(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0xea16
movq %rax, %r13
movq %rbx, %rdi
callq 0x4638
callq 0x4530
jmp 0xe02a
pushq $0x28
popq %rdi
callq 0x4210
movq %rax, %rbx
callq 0xdd75
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rdx
movq %rax, %rsi
callq 0x41a0
leaq 0x368b(%rip), %rsi      # 0x117bb
leaq -0xc0(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x673e
movb $0x1, %r14b
leaq -0xc0(%rbp), %rsi
movq %rbx, %rdi
callq 0xe304
xorl %r14d, %r14d
leaq 0x997c(%rip), %rsi      # 0x17ad8
leaq -0x7a4f(%rip), %rdx     # 0x6714
movq %rbx, %rdi
callq 0x4560
jmp 0xe1cf
pushq $0x28
popq %rdi
callq 0x4210
movq %rax, %rbx
callq 0xdd75
leaq -0x80(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
movq %rax, %rsi
callq 0x41a0
leaq 0x3639(%rip), %rsi      # 0x117cd
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x673e
movb $0x1, %r14b
leaq -0xa0(%rbp), %rsi
movq %rbx, %rdi
callq 0xe304
xorl %r14d, %r14d
leaq 0x9918(%rip), %rsi      # 0x17ad8
leaq -0x7ab3(%rip), %rdx     # 0x6714
movq %rbx, %rdi
callq 0x4560
movq %rax, %r12
leaq -0xe0(%rbp), %rdi
callq 0x4638
jmp 0xe1e3
movq %rax, %r12
callq 0x4530
jmp 0xe266
movq %rax, %rdi
callq 0x5ec6
movq %rax, %r12
leaq -0xa0(%rbp), %rdi
callq 0x4638
jmp 0xe209
movq %rax, %r12
movb $0x1, %r14b
leaq -0x80(%rbp), %rdi
callq 0x4638
testb %r14b, %r14b
jne 0xe243
jmp 0xe25d
movq %rax, %r12
leaq -0xc0(%rbp), %rdi
callq 0x4638
jmp 0xe230
movq %rax, %r12
movb $0x1, %r14b
leaq -0x60(%rbp), %rdi
callq 0x4638
testb %r14b, %r14b
jne 0xe250
jmp 0xe266
movq %rax, %r12
movq %rbx, %rdi
callq 0x42a0
jmp 0xe25d
movq %rax, %r12
movq %rbx, %rdi
callq 0x42a0
jmp 0xe266
movq %rax, %r12
leaq -0x60(%rbp), %rdi
callq 0x4638
movq %r12, %rdi
callq 0x4580