// File: nilnilnil[P]autocomplete/src/main.cpp
// Function: handle_export(mg_event, mg_connection*, mg_request_info const*)
static void*
handle_export(enum mg_event event,
              struct mg_connection *conn,
              const struct mg_request_info *request_info) {
    std::string file = get_qs(request_info, "file");
    if (building) {
        print_HTTP_response(conn, 412, "Busy");
        mg_printf(conn, "Busy\n");
        return (void*)"";
    }

    // Prevent modifications to 'pm' while we export
    building = true;
    ofstream fout(file.c_str());
    const time_t start_time = time(NULL);

    for (size_t i = 0; i < pm.repr.size(); ++i) {
        fout<<pm.repr[i].weight<<'\t'<<pm.repr[i].phrase<<'\t'<<std::string(pm.repr[i].snippet)<<'\n';
    }

    building = false;
    mg_printf(conn, "Successfully wrote %u records to output file '%s' in %d second(s)\n", 
              pm.repr.size(), file.c_str(), time(NULL) - start_time);
    return (void*)"";
}

// Assembly:
subq $0x308, %rsp            # imm = 0x308
movl %edi, 0x2fc(%rsp)
movq %rsi, 0x2f0(%rsp)
movq %rdx, 0x2e8(%rsp)
movq 0x2e8(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x2a7(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x5a50
movq 0x58(%rsp), %rdx
leaq 0x15c7c(%rip), %rsi     # 0x22a75
leaq 0x2a8(%rsp), %rdi
callq 0xddd0
jmp 0xce08
movq 0x50(%rsp), %rsi
leaq 0x2c8(%rsp), %rdi
leaq 0x2a8(%rsp), %rdx
callq 0x9b20
jmp 0xce24
leaq 0x2a8(%rsp), %rdi
callq 0x5320
leaq 0x2a7(%rsp), %rdi
callq 0x55e0
testb $0x1, 0x1ecf3(%rip)     # 0x2bb38
je 0xcf06
movq 0x2f0(%rsp), %rdi
leaq 0x1577b(%rip), %rdx     # 0x225d5
leaq 0x15779(%rip), %rcx     # 0x225da
movl $0x19c, %esi            # imm = 0x19C
callq 0x9d00
jmp 0xce6d
movq 0x2f0(%rsp), %rdi
leaq 0x157c2(%rip), %rsi     # 0x2263e
xorl %eax, %eax
callq 0x17030
jmp 0xce85
leaq 0x15464(%rip), %rax     # 0x222f0
movq %rax, 0x300(%rsp)
movl $0x1, 0x290(%rsp)
jmp 0xd150
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x298(%rsp)
movl %eax, 0x294(%rsp)
jmp 0xcedb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x298(%rsp)
movl %eax, 0x294(%rsp)
leaq 0x2a8(%rsp), %rdi
callq 0x5320
leaq 0x2a7(%rsp), %rdi
callq 0x55e0
jmp 0xd17a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x298(%rsp)
movl %eax, 0x294(%rsp)
jmp 0xd16d
movb $0x1, 0x1ec2b(%rip)     # 0x2bb38
leaq 0x2c8(%rsp), %rdi
callq 0x5200
movq %rax, %rsi
leaq 0x90(%rsp), %rdi
movl $0x10, %edx
callq 0x55f0
jmp 0xcf31
xorl %eax, %eax
movl %eax, %edi
callq 0x54f0
movq %rax, 0x88(%rsp)
movq $0x0, 0x80(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x1eb8e(%rip), %rdi     # 0x2baf0
callq 0xe000
movq %rax, %rcx
movq 0x48(%rsp), %rax
cmpq %rcx, %rax
jae 0xd0a7
movq 0x80(%rsp), %rsi
leaq 0x1eb69(%rip), %rdi     # 0x2baf0
callq 0xe110
movl (%rax), %esi
leaq 0x90(%rsp), %rdi
callq 0x57a0
movq %rax, 0x40(%rsp)
jmp 0xcfa2
movq 0x40(%rsp), %rdi
movl $0x9, %esi
callq 0x5680
movq %rax, 0x38(%rsp)
jmp 0xcfb8
movq 0x80(%rsp), %rsi
leaq 0x1eb29(%rip), %rdi     # 0x2baf0
callq 0xe110
movq 0x38(%rsp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0x54b0
movq %rax, 0x30(%rsp)
jmp 0xcfe4
movq 0x30(%rsp), %rdi
movl $0x9, %esi
callq 0x5680
movq %rax, 0x28(%rsp)
jmp 0xcffa
movq 0x80(%rsp), %rsi
leaq 0x1eae7(%rip), %rdi     # 0x2baf0
callq 0xe110
movq %rax, %rsi
addq $0x28, %rsi
leaq 0x60(%rsp), %rdi
callq 0xe460
jmp 0xd021
movq 0x28(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x54b0
movq %rax, 0x20(%rsp)
jmp 0xd037
movq 0x20(%rsp), %rdi
movl $0xa, %esi
callq 0x5680
jmp 0xd048
leaq 0x60(%rsp), %rdi
callq 0x5320
movq 0x80(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x80(%rsp)
jmp 0xcf4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x298(%rsp)
movl %eax, 0x294(%rsp)
jmp 0xd141
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x298(%rsp)
movl %eax, 0x294(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x5320
jmp 0xd141
movb $0x0, 0x1ea8a(%rip)     # 0x2bb38
movq 0x2f0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x1ea2f(%rip), %rdi     # 0x2baf0
callq 0xe000
movq %rax, 0x8(%rsp)
leaq 0x2c8(%rsp), %rdi
callq 0x5200
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movl %eax, 0x1c(%rsp)
movl %eax, %edi
callq 0x54f0
movq (%rsp), %rdi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %rax, %r8
movl 0x1c(%rsp), %eax
movq 0x88(%rsp), %rsi
subq %rsi, %r8
leaq 0x15533(%rip), %rsi     # 0x22644
callq 0x17030
jmp 0xd118
leaq 0x151d1(%rip), %rax     # 0x222f0
movq %rax, 0x300(%rsp)
movl $0x1, 0x290(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x58c0
jmp 0xd150
leaq 0x90(%rsp), %rdi
callq 0x58c0
jmp 0xd16d
leaq 0x2c8(%rsp), %rdi
callq 0x5320
movq 0x300(%rsp), %rax
addq $0x308, %rsp            # imm = 0x308
retq
leaq 0x2c8(%rsp), %rdi
callq 0x5320
movq 0x298(%rsp), %rdi
callq 0x5a40
nopw (%rax,%rax)