// File: nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: handle_request
static void handle_request(struct mg_connection *conn) {
  struct mg_request_info *ri = &conn->request_info;
  char path[PATH_MAX];
  int uri_len;
  struct mgstat st;

  if ((conn->request_info.query_string = strchr(ri->uri, '?')) != NULL) {
    * conn->request_info.query_string++ = '\0';
  }
  uri_len = strlen(ri->uri);
  (void) url_decode(ri->uri, (size_t)uri_len, ri->uri, (size_t)(uri_len + 1), 0);
  remove_double_dots_and_double_slashes(ri->uri);
  convert_uri_to_file_name(conn, ri->uri, path, sizeof(path));

  DEBUG_TRACE(("%s", ri->uri));
  if (!check_authorization(conn, path)) {
    send_authorization_request(conn);
  } else if (call_user(conn, MG_NEW_REQUEST) != NULL) {
    // Do nothing, callback has served the request
  } else if (strstr(path, PASSWORDS_FILE_NAME)) {
    // Do not allow to view passwords files
    send_http_error(conn, 403, "Forbidden", "Access Forbidden");
  } else if (conn->ctx->config[DOCUMENT_ROOT] == NULL) {
    send_http_error(conn, 404, "Not Found", "Not Found");
  } else if ((!strcmp(ri->request_method, "PUT") ||
        !strcmp(ri->request_method, "DELETE")) &&
      (conn->ctx->config[PUT_DELETE_PASSWORDS_FILE] == NULL ||
       !is_authorized_for_put(conn))) {
    send_authorization_request(conn);
  } else if (!strcmp(ri->request_method, "PUT")) {
    put_file(conn, path);
  } else if (!strcmp(ri->request_method, "DELETE")) {
    if (mg_remove(path) == 0) {
      send_http_error(conn, 200, "OK", "");
    } else {
      send_http_error(conn, 500, http_500_error, "remove(%s): %s", path,
                      strerror(ERRNO));
    }
  } else if (mg_stat(path, &st) != 0) {
    send_http_error(conn, 404, "Not Found", "%s", "File not found");
  } else if (st.is_directory && ri->uri[uri_len - 1] != '/') {
    (void) mg_printf(conn,
        "HTTP/1.1 301 Moved Permanently\r\n"
        "Location: %s/\r\n\r\n", ri->uri);
  } else if (st.is_directory &&
             !substitute_index_file(conn, path, sizeof(path), &st)) {
    if (!mg_strcasecmp(conn->ctx->config[ENABLE_DIRECTORY_LISTING], "yes")) {
      handle_directory_request(conn, path);
    } else {
      send_http_error(conn, 403, "Directory Listing Denied",
          "Directory listing denied");
    }
  } else if (match_extension(path, conn->ctx->config[CGI_EXTENSIONS])) {
    if (strcmp(ri->request_method, "POST") &&
        strcmp(ri->request_method, "GET")) {
      send_http_error(conn, 501, "Not Implemented",
          "Method %s is not implemented", ri->request_method);
    } else {
      handle_cgi_request(conn, path);
    }
  } else if (match_extension(path, conn->ctx->config[SSI_EXTENSIONS])) {
    handle_ssi_file_request(conn, path);
  } else if (is_not_modified(conn, &st)) {
    send_http_error(conn, 304, "Not Modified", "");
  } else {
    handle_file_request(conn, path, &st);
  }
}

// Assembly:
subq $0x1058, %rsp           # imm = 0x1058
movq %rdi, 0x1050(%rsp)
movq 0x1050(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x1048(%rsp)
movq 0x1048(%rsp), %rax
movq 0x10(%rax), %rdi
movl $0x3f, %esi
callq 0x51d0
movq 0x1050(%rsp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
je 0x1c605
movq 0x1050(%rsp), %rcx
movq 0x28(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x28(%rcx)
movb $0x0, (%rax)
movq 0x1048(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x5230
movl %eax, 0x3c(%rsp)
movq 0x1048(%rsp), %rax
movq 0x10(%rax), %rdi
movslq 0x3c(%rsp), %rsi
movq 0x1048(%rsp), %rax
movq 0x10(%rax), %rdx
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
xorl %r8d, %r8d
callq 0x17450
movq 0x1048(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1d7e0
movq 0x1050(%rsp), %rdi
movq 0x1048(%rsp), %rax
movq 0x10(%rax), %rsi
leaq 0x40(%rsp), %rdx
movl $0x1000, %ecx           # imm = 0x1000
callq 0x1d8e0
movq 0x1050(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1d950
cmpl $0x0, %eax
jne 0x1c6a6
movq 0x1050(%rsp), %rdi
callq 0x1dae0
jmp 0x1caf0
movq 0x1050(%rsp), %rdi
xorl %esi, %esi
callq 0x1a7d0
cmpq $0x0, %rax
je 0x1c6c0
jmp 0x1caee
leaq 0x40(%rsp), %rdi
leaq 0x69e1(%rip), %rsi      # 0x230ad
callq 0x5100
cmpq $0x0, %rax
je 0x1c6fe
movq 0x1050(%rsp), %rdi
movl $0x193, %esi            # imm = 0x193
leaq 0x69d3(%rip), %rdx      # 0x230be
leaq 0x69c5(%rip), %rcx      # 0x230b7
movb $0x0, %al
callq 0x1bc40
jmp 0x1caec
movq 0x1050(%rsp), %rax
movq 0x458(%rax), %rax
cmpq $0x0, 0xa0(%rax)
jne 0x1c73a
movq 0x1050(%rsp), %rdi
movl $0x194, %esi            # imm = 0x194
leaq 0x5ef2(%rip), %rcx      # 0x2261d
movq %rcx, %rdx
movb $0x0, %al
callq 0x1bc40
jmp 0x1caea
movq 0x1048(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x67e0(%rip), %rsi      # 0x22f2d
callq 0x5810
cmpl $0x0, %eax
je 0x1c774
movq 0x1048(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x67c7(%rip), %rsi      # 0x22f31
callq 0x5810
cmpl $0x0, %eax
jne 0x1c7ae
movq 0x1050(%rsp), %rax
movq 0x458(%rax), %rax
cmpq $0x0, 0x20(%rax)
je 0x1c79c
movq 0x1050(%rsp), %rdi
callq 0x1db40
cmpl $0x0, %eax
jne 0x1c7ae
movq 0x1050(%rsp), %rdi
callq 0x1dae0
jmp 0x1cae8
movq 0x1048(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x676c(%rip), %rsi      # 0x22f2d
callq 0x5810
cmpl $0x0, %eax
jne 0x1c7e2
movq 0x1050(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1dbd0
jmp 0x1cae6
movq 0x1048(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x673c(%rip), %rsi      # 0x22f31
callq 0x5810
cmpl $0x0, %eax
jne 0x1c88f
leaq 0x40(%rsp), %rdi
callq 0x5aa0
cmpl $0x0, %eax
jne 0x1c836
movq 0x1050(%rsp), %rdi
movl $0xc8, %esi
leaq 0x5de5(%rip), %rdx      # 0x2260b
leaq 0x5ac3(%rip), %rcx      # 0x222f0
movb $0x0, %al
callq 0x1bc40
jmp 0x1c88a
movq 0x1050(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xf216(%rip), %rax      # 0x2ba60
movq %rax, 0x10(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
callq 0x5060
movl (%rax), %edi
callq 0x5190
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %r8
movq %rax, %r9
movl $0x1f4, %esi            # imm = 0x1F4
leaq 0x6845(%rip), %rcx      # 0x230c8
movb $0x0, %al
callq 0x1bc40
jmp 0x1cae4
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1a8a0
cmpl $0x0, %eax
je 0x1c8d1
movq 0x1050(%rsp), %rdi
movl $0x194, %esi            # imm = 0x194
leaq 0x5d66(%rip), %rdx      # 0x2261d
leaq 0x6eba(%rip), %rcx      # 0x23778
leaq 0x6812(%rip), %r8       # 0x230d7
movb $0x0, %al
callq 0x1bc40
jmp 0x1cae2
cmpl $0x0, 0x20(%rsp)
je 0x1c91e
movq 0x1048(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x3c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
je 0x1c91e
movq 0x1050(%rsp), %rdi
movq 0x1048(%rsp), %rax
movq 0x10(%rax), %rdx
leaq 0x67d4(%rip), %rsi      # 0x230e6
movb $0x0, %al
callq 0x17030
jmp 0x1cae0
cmpl $0x0, 0x20(%rsp)
je 0x1c9a9
movq 0x1050(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
leaq 0x20(%rsp), %rcx
callq 0x1de00
cmpl $0x0, %eax
jne 0x1c9a9
movq 0x1050(%rsp), %rax
movq 0x458(%rax), %rax
movq 0x58(%rax), %rdi
leaq 0x5f74(%rip), %rsi      # 0x228d8
callq 0x19510
cmpl $0x0, %eax
jne 0x1c982
movq 0x1050(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1df50
jmp 0x1c9a4
movq 0x1050(%rsp), %rdi
movl $0x193, %esi            # imm = 0x193
leaq 0x6782(%rip), %rdx      # 0x23118
leaq 0x6794(%rip), %rcx      # 0x23131
movb $0x0, %al
callq 0x1bc40
jmp 0x1cade
leaq 0x40(%rsp), %rdi
movq 0x1050(%rsp), %rax
movq 0x458(%rax), %rax
movq 0x10(%rax), %rsi
callq 0x1e3c0
cmpl $0x0, %eax
je 0x1ca50
movq 0x1048(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x6539(%rip), %rsi      # 0x22f1b
callq 0x5810
cmpl $0x0, %eax
je 0x1ca39
movq 0x1048(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x6518(%rip), %rsi      # 0x22f17
callq 0x5810
cmpl $0x0, %eax
je 0x1ca39
movq 0x1050(%rsp), %rdi
movq 0x1048(%rsp), %rax
movq 0x8(%rax), %r8
movl $0x1f5, %esi            # imm = 0x1F5
leaq 0x6721(%rip), %rdx      # 0x2314a
leaq 0x672a(%rip), %rcx      # 0x2315a
movb $0x0, %al
callq 0x1bc40
jmp 0x1ca4b
movq 0x1050(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1e450
jmp 0x1cadc
leaq 0x40(%rsp), %rdi
movq 0x1050(%rsp), %rax
movq 0x458(%rax), %rax
movq 0x40(%rax), %rsi
callq 0x1e3c0
cmpl $0x0, %eax
je 0x1ca86
movq 0x1050(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1ea00
jmp 0x1cada
movq 0x1050(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1eae0
cmpl $0x0, %eax
je 0x1cac1
movq 0x1050(%rsp), %rdi
movl $0x130, %esi            # imm = 0x130
leaq 0x66c6(%rip), %rdx      # 0x23177
leaq 0x5838(%rip), %rcx      # 0x222f0
movb $0x0, %al
callq 0x1bc40
jmp 0x1cad8
movq 0x1050(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x1eb50
jmp 0x1cada
jmp 0x1cadc
jmp 0x1cade
jmp 0x1cae0
jmp 0x1cae2
jmp 0x1cae4
jmp 0x1cae6
jmp 0x1cae8
jmp 0x1caea
jmp 0x1caec
jmp 0x1caee
jmp 0x1caf0
addq $0x1058, %rsp           # imm = 0x1058
retq
nopl (%rax,%rax)