// File: nilnilnil[P]autocomplete/src/main.cpp
// Function: handle_import(mg_event, mg_connection*, mg_request_info const*)
static void*
handle_import(enum mg_event event,
              struct mg_connection *conn,
              const struct mg_request_info *request_info) {
    std::string file = get_qs(request_info, "file");
    int sorted = atoi(get_qs(request_info, "sorted").c_str());
    uint_t limit  = atoi(get_qs(request_info, "limit").c_str());
    int nadded, nlines;
    const time_t start_time = time(NULL);

    if (!limit) {
        limit = minus_one;
    }

    int ret = do_import(file, sorted, limit, nadded, nlines);
    if (ret < 0) {
        switch (-ret) {
        case IMPORT_FILE_NOT_FOUND:
            print_HTTP_response(conn, 404, "Not Found");
            break;

        default:
            cerr<<"ERROR::Unknown error: "<<ret<<endl;
        }
    }
    else {
        print_HTTP_response(conn, 200, "OK");
        mg_printf(conn, "Successfully added %d/%d records from \"%s\" in %d second(s)\n", 
                  nadded, nlines, file.c_str(), time(NULL) - start_time);
    }

    return (void*)"";
}

// Assembly:
subq $0x1b8, %rsp            # imm = 0x1B8
movl %edi, 0x1b4(%rsp)
movq %rsi, 0x1a8(%rsp)
movq %rdx, 0x1a0(%rsp)
movq 0x1a0(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x15f(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x5a50
movq 0x78(%rsp), %rdx
leaq 0x1615c(%rip), %rsi     # 0x22a75
leaq 0x160(%rsp), %rdi
callq 0xddd0
jmp 0xc928
movq 0x70(%rsp), %rsi
leaq 0x180(%rsp), %rdi
leaq 0x160(%rsp), %rdx
callq 0x9b20
jmp 0xc944
leaq 0x160(%rsp), %rdi
callq 0x5320
leaq 0x15f(%rsp), %rdi
callq 0x55e0
movq 0x1a0(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x107(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x5a50
movq 0x68(%rsp), %rdx
leaq 0x15ad1(%rip), %rsi     # 0x2245a
leaq 0x108(%rsp), %rdi
callq 0xddd0
jmp 0xc998
movq 0x60(%rsp), %rsi
leaq 0x128(%rsp), %rdi
leaq 0x108(%rsp), %rdx
callq 0x9b20
jmp 0xc9b4
leaq 0x128(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x5200
movq %rax, %rdi
callq 0x5950
movq 0x40(%rsp), %rdi
movl %eax, 0x4c(%rsp)
callq 0x5320
leaq 0x108(%rsp), %rdi
callq 0x5320
leaq 0x107(%rsp), %rdi
callq 0x55e0
movl 0x4c(%rsp), %eax
movl %eax, 0x148(%rsp)
movq 0x1a0(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x5a50
movq 0x58(%rsp), %rdx
leaq 0x15beb(%rip), %rsi     # 0x22617
leaq 0xc0(%rsp), %rdi
callq 0xddd0
jmp 0xca3b
movq 0x50(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x9b20
jmp 0xca57
leaq 0xe0(%rsp), %rdi
callq 0x5200
movq %rax, %rdi
callq 0x5950
movl %eax, 0x3c(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x5320
leaq 0xc0(%rsp), %rdi
callq 0x5320
leaq 0xbf(%rsp), %rdi
callq 0x55e0
movl 0x3c(%rsp), %eax
movl %eax, 0x100(%rsp)
xorl %eax, %eax
movl %eax, %edi
callq 0x54f0
movq %rax, 0xa8(%rsp)
cmpl $0x0, 0x100(%rsp)
jne 0xcbac
movl $0xffffffff, 0x100(%rsp) # imm = 0xFFFFFFFF
jmp 0xcbac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xcb08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x5320
leaq 0x15f(%rsp), %rdi
callq 0x55e0
jmp 0xcd98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xcb51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x5320
leaq 0x107(%rsp), %rdi
callq 0x55e0
jmp 0xcd8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xcb9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x5320
leaq 0xbf(%rsp), %rdi
callq 0x55e0
jmp 0xcd8b
leaq 0x80(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x5220
jmp 0xcbc3
movl 0x148(%rsp), %esi
movl 0x100(%rsp), %edx
leaq 0x80(%rsp), %rdi
leaq 0xb8(%rsp), %rcx
leaq 0xb4(%rsp), %r8
callq 0xb630
movl %eax, 0x38(%rsp)
jmp 0xcbf4
leaq 0x80(%rsp), %rdi
callq 0x5320
movl 0x38(%rsp), %eax
movl %eax, 0xa4(%rsp)
cmpl $0x0, 0xa4(%rsp)
jge 0xccd7
movl 0xa4(%rsp), %eax
subl $-0x1, %eax
je 0xcc67
jmp 0xcc8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xcd8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x5320
jmp 0xcd8b
movq 0x1a8(%rsp), %rdi
leaq 0x159a7(%rip), %rdx     # 0x2261d
leaq 0x1595d(%rip), %rcx     # 0x225da
movl $0x194, %esi            # imm = 0x194
callq 0x9d00
jmp 0xcc89
jmp 0xccd2
movq 0x1e35e(%rip), %rdi     # 0x2aff0
leaq 0x1598e(%rip), %rsi     # 0x22627
callq 0x5550
movq %rax, 0x30(%rsp)
jmp 0xcca5
movq 0x30(%rsp), %rdi
movl 0xa4(%rsp), %esi
callq 0x5a20
movq %rax, 0x28(%rsp)
jmp 0xccbd
movq 0x28(%rsp), %rdi
movq 0x1e2df(%rip), %rsi     # 0x2afa8
callq 0x55a0
jmp 0xccd0
jmp 0xccd2
jmp 0xcd6f
movq 0x1a8(%rsp), %rdi
leaq 0x15925(%rip), %rdx     # 0x2260b
leaq 0x158ed(%rip), %rcx     # 0x225da
movl $0xc8, %esi
callq 0x9d00
jmp 0xccf9
movq 0x1a8(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0xb8(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0xb4(%rsp), %eax
movl %eax, 0x14(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x5200
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movl %eax, 0x24(%rsp)
movl %eax, %edi
callq 0x54f0
movq 0x8(%rsp), %rdi
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %ecx
movq 0x18(%rsp), %r8
movq %rax, %r9
movl 0x24(%rsp), %eax
movq 0xa8(%rsp), %rsi
subq %rsi, %r9
leaq 0x15780(%rip), %rsi     # 0x224e6
callq 0x17030
jmp 0xcd6d
jmp 0xcd6f
leaq 0x180(%rsp), %rdi
callq 0x5320
leaq 0x1556d(%rip), %rax     # 0x222f0
addq $0x1b8, %rsp            # imm = 0x1B8
retq
leaq 0x180(%rsp), %rdi
callq 0x5320
movq 0x150(%rsp), %rdi
callq 0x5a40
nopw %cs:(%rax,%rax)