// File: /workspace/github_cpp_makefile_star2_O1/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 $0x108, %rsp            # imm = 0x108
movq %rdi, %rbx
movl (%rdi), %edi
movl $0xa, %esi
callq 0x4390
leaq -0x4c(%rbp), %rdx
movl $0x10, (%rdx)
movq %rbx, -0x38(%rbp)
movl (%rbx), %edi
leaq -0x128(%rbp), %rsi
callq 0x4140
movl %eax, -0x2c(%rbp)
testl %eax, %eax
js 0x136d0
movl $0x3f4001, %edi         # imm = 0x3F4001
callq 0x4030
movq %rax, %r12
xorl %r15d, %r15d
xorl %ebx, %ebx
testq %rbx, %rbx
jne 0x13404
leaq (%r12,%r15), %rsi
movl $0x3f4000, %edx         # imm = 0x3F4000
subq %r15, %rdx
movl -0x2c(%rbp), %edi
xorl %ecx, %ecx
callq 0x4150
testq %rax, %rax
je 0x13404
addq %rax, %r15
movb $0x0, (%r12,%r15)
movq %r12, %rdi
movq %r15, %rsi
callq 0x10093
movq %rax, %rbx
jmp 0x133cc
movq %r12, %rdi
callq 0x4420
testq %r15, %r15
je 0x134ab
movq %rbx, %rdi
callq 0xbb4c
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rax
cmpq %rax, 0x10(%rcx)
je 0x134bb
xorl %edx, %edx
movq %rbx, -0x58(%rbp)
movq %rdx, -0x48(%rbp)
movq (%rax,%rdx,8), %r12
movq %rbx, %rdi
leaq -0xd8(%rbp), %r14
callq 0xb3c6
movl %eax, %r13d
movq %r14, %rdi
movq %rbx, %rsi
callq 0xb390
movq %r12, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0x14e50
movl %eax, %ebx
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x13482
callq 0x4310
testb %bl, %bl
jne 0x134c2
movq -0x48(%rbp), %rdx
incq %rdx
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rdx
movq -0x58(%rbp), %rbx
jb 0x13435
jmp 0x134bd
movl -0x2c(%rbp), %edi
callq 0x4600
xorl %r12d, %r12d
jmp 0x13549
xorl %edx, %edx
xorl %r12d, %r12d
jmp 0x134e8
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %r12d, %r12d
movq -0x58(%rbp), %rbx
movq %rbx, %rsi
callq 0x14e94
movq %rax, %r12
movq -0x48(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rax
subq 0x8(%rcx), %rax
sarq $0x3, %rax
cmpq %rax, %rdx
jne 0x13512
movq 0x20(%rcx), %rdi
testq %rdi, %rdi
je 0x13512
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x10(%rax)
movq %rax, %r12
leaq 0x88(%rbx), %rdi
callq 0xaa2e
leaq 0x58(%rbx), %rdi
callq 0xaa2e
leaq 0x28(%rbx), %rdi
callq 0xaa2e
movq (%rbx), %rdi
leaq 0x10(%rbx), %rax
cmpq %rax, %rdi
je 0x13541
callq 0x4310
movq %rbx, %rdi
callq 0x4310
testq %r15, %r15
je 0x135db
movq %r12, %rdi
xorl %esi, %esi
callq 0x8cca
leaq -0x78(%rbp), %rdi
movq %r12, %rsi
leaq -0x3c(%rbp), %rdx
callq 0x84f0
leaq 0x48(%r12), %rdi
callq 0xaa2e
movq 0x28(%r12), %rdi
leaq 0x38(%r12), %rax
cmpq %rax, %rdi
je 0x1358a
callq 0x4310
movq 0x8(%r12), %rdi
leaq 0x18(%r12), %rax
cmpq %rax, %rdi
je 0x1359e
callq 0x4310
movq %r12, %rdi
callq 0x4310
movq -0x78(%rbp), %rsi
movslq -0x3c(%rbp), %rdx
movl -0x2c(%rbp), %edi
xorl %ecx, %ecx
callq 0x4200
cmpl %eax, -0x3c(%rbp)
jne 0x13739
movl -0x2c(%rbp), %edi
callq 0x4600
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x135db
callq 0x4310
movq -0x38(%rbp), %rax
movl (%rax), %edi
leaq -0x128(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
jmp 0x133aa
movq %rdx, %rbx
movq %rax, %r13
jmp 0x13628
jmp 0x1361f
jmp 0x1361f
movq %rdx, %rbx
movq %rax, %r13
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x13625
callq 0x4310
jmp 0x13625
jmp 0x1361f
movq %rdx, %rbx
movq %rax, %r13
xorl %r12d, %r12d
cmpl $0x1, %ebx
jne 0x13921
movq %r13, %rdi
callq 0x41a0
movq %rax, %rbx
testq %r12, %r12
je 0x1367b
leaq 0x48(%r12), %rdi
callq 0xaa2e
movq 0x28(%r12), %rdi
leaq 0x38(%r12), %rax
cmpq %rax, %rdi
je 0x1365f
callq 0x4310
movq 0x8(%r12), %rdi
leaq 0x18(%r12), %rax
cmpq %rax, %rdi
je 0x13673
callq 0x4310
movq %r12, %rdi
callq 0x4310
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
callq 0x7e12
movq %rbx, %rdi
callq 0x1432c
movq %rax, %r12
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x136c6
callq 0x4310
callq 0x4540
jmp 0x13552
movl $0x28, %edi
callq 0x41f0
movq %rax, %rbx
callq 0x4060
movl (%rax), %edi
callq 0x4170
leaq -0x78(%rbp), %rdi
leaq -0x118(%rbp), %rdx
movq %rax, %rsi
callq 0x4190
leaq 0x60cc(%rip), %rcx      # 0x197cf
leaq -0x78(%rbp), %rdi
movl $0x11, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x43a0
leaq -0xe8(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x137a5
movups (%rcx), %xmm0
movups %xmm0, (%r15)
jmp 0x137b6
movl $0x28, %edi
callq 0x41f0
movq %rax, %rbx
callq 0x4060
movl (%rax), %edi
callq 0x4170
leaq -0x118(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
movq %rax, %rsi
callq 0x4190
leaq 0x6075(%rip), %rcx      # 0x197e1
leaq -0x118(%rbp), %rdi
movl $0xc, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x43a0
leaq -0xa8(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x137fa
movups (%rcx), %xmm0
movups %xmm0, (%r15)
jmp 0x1380b
movq %rdx, -0xf8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xe8(%rbp)
movq 0x8(%rax), %rdx
leaq -0xf8(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movb $0x1, %r14b
movq %rbx, %rdi
callq 0x139e0
xorl %r14d, %r14d
leaq 0xb2e7(%rip), %rsi      # 0x1ead0
leaq -0xbca6(%rip), %rdx     # 0x7b4a
movq %rbx, %rdi
callq 0x4570
jmp 0x1384d
movq %rdx, -0xb8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xa8(%rbp)
movq 0x8(%rax), %rdx
leaq -0xb8(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movb $0x1, %r14b
movq %rbx, %rdi
callq 0x139e0
xorl %r14d, %r14d
leaq 0xb292(%rip), %rsi      # 0x1ead0
leaq -0xbcfb(%rip), %rdx     # 0x7b4a
movq %rbx, %rdi
callq 0x4570
movq %rax, %r13
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x1386d
callq 0x4310
jmp 0x1386d
movq %rax, %r13
callq 0x4540
jmp 0x13921
movq %rax, %rdi
callq 0x6f5d
movq %rax, %r13
movq -0xb8(%rbp), %rdi
cmpq %r15, %rdi
je 0x1389b
callq 0x4310
jmp 0x1389b
movq %rax, %r13
movb $0x1, %r14b
leaq -0x108(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x138b8
callq 0x4310
jmp 0x138b8
movq %rax, %r13
movb $0x1, %r14b
testb %r14b, %r14b
je 0x138fa
movq %rbx, %rdi
callq 0x4290
jmp 0x138fa
movq %rax, %r13
movq -0xf8(%rbp), %rdi
cmpq %r15, %rdi
je 0x138e3
callq 0x4310
jmp 0x138e3
movq %rax, %r13
movb $0x1, %r14b
leaq -0x68(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13914
callq 0x4310
jmp 0x13914
movq %rax, %r13
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x13921
callq 0x4310
jmp 0x13921
movq %rax, %r13
movb $0x1, %r14b
testb %r14b, %r14b
je 0x13921
movq %rbx, %rdi
callq 0x4290
movq %r13, %rdi
callq 0x45a0
nop