// File: loadzero[P]geoloc/geoloc/locations.hpp
// Function: save_locations(BinaryFile&, std::vector<Location, std::allocator<Location>> const&)
inline void save_locations(BinaryFile &file, 
                           const std::vector<Location> &locations)
{
    unsigned maxid = 0;

    StringTable country;
    StringTable region;
    StringTable city;

    for (size_t i = 0; i < locations.size(); ++i)
    {
        const Location &loc = locations[i];

        maxid = std::max(loc.id, maxid);

        country.insert(loc.country);
        region.insert(loc.region);
        city.insert(loc.city);
    }

    save_string_table(file, country);
    save_string_table(file, region);
    save_string_table(file, city);

    std::vector<PackedLocation> packed;
    packed.resize(maxid + 1);

    for (size_t i = 0; i < locations.size(); ++i)
    {
        const Location &loc = locations[i];

        PackedLocation &ploc = packed[loc.id];

        ploc.id = loc.id;
        ploc.country = country.index_of(loc.country);
        ploc.region = region.index_of(loc.region);
        ploc.city = city.index_of(loc.city);
        ploc.lat = strtof(loc.lat.c_str(), 0);
        ploc.lon = strtof(loc.lon.c_str(), 0);
    }

    file.save_pod_vector(packed);
}

// Assembly:
subq $0x218, %rsp            # imm = 0x218
movq %rdi, 0x210(%rsp)
movq %rsi, 0x208(%rsp)
movl $0x0, 0x204(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0xc720
leaq 0x140(%rsp), %rdi
callq 0xc720
jmp 0xaf8e
leaq 0xd0(%rsp), %rdi
callq 0xc720
jmp 0xaf9d
movq $0x0, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x208(%rsp), %rdi
callq 0xc340
movq %rax, %rcx
movq 0x70(%rsp), %rax
cmpq %rcx, %rax
jae 0xb0de
movq 0x208(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0xc810
movq %rax, 0x68(%rsp)
jmp 0xaff0
movq 0x68(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
leaq 0x204(%rsp), %rsi
callq 0xc830
movq %rax, 0x60(%rsp)
jmp 0xb019
movq 0x60(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x204(%rsp)
movq 0xc0(%rsp), %rsi
addq $0x8, %rsi
leaq 0x1a0(%rsp), %rdi
callq 0xc870
jmp 0xb042
movq 0xc0(%rsp), %rsi
addq $0x28, %rsi
leaq 0x140(%rsp), %rdi
callq 0xc870
jmp 0xb05d
movq 0xc0(%rsp), %rsi
addq $0x48, %rsi
leaq 0xd0(%rsp), %rdi
callq 0xc870
jmp 0xb078
jmp 0xb07a
movq 0xc8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc8(%rsp)
jmp 0xafa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0xb3b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0xb3a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0xb393
movq 0x210(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0xc970
jmp 0xb0f5
movq 0x210(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0xc970
jmp 0xb10c
movq 0x210(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0xc970
jmp 0xb123
leaq 0xa8(%rsp), %rdi
callq 0xc9d0
jmp 0xb132
movl 0x204(%rsp), %eax
incl %eax
movq %rax, 0x58(%rsp)
leaq 0x90(%rsp), %rdi
callq 0xcaa0
jmp 0xb14f
movq 0x58(%rsp), %rsi
movq 0xa0(%rsp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movups 0x90(%rsp), %xmm0
movups %xmm0, (%rax)
leaq 0xa8(%rsp), %rdi
callq 0xc9e0
jmp 0xb17d
movq $0x0, 0x88(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x208(%rsp), %rdi
callq 0xc340
movq %rax, %rcx
movq 0x50(%rsp), %rax
cmpq %rcx, %rax
jae 0xb338
movq 0x208(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0xc810
movq %rax, 0x48(%rsp)
jmp 0xb1d0
movq 0x48(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
movl (%rax), %eax
movl %eax, %esi
leaq 0xa8(%rsp), %rdi
callq 0xcae0
movq %rax, 0x40(%rsp)
jmp 0xb1fd
movq 0x40(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rax
movl (%rax), %ecx
movq 0x78(%rsp), %rax
movl %ecx, (%rax)
movq 0x80(%rsp), %rsi
addq $0x8, %rsi
leaq 0x1a0(%rsp), %rdi
callq 0xcb00
movl %eax, 0x3c(%rsp)
jmp 0xb237
movl 0x3c(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x80(%rsp), %rsi
addq $0x28, %rsi
leaq 0x140(%rsp), %rdi
callq 0xcb00
movl %eax, 0x38(%rsp)
jmp 0xb262
movl 0x38(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x80(%rsp), %rsi
addq $0x48, %rsi
leaq 0xd0(%rsp), %rdi
callq 0xcb00
movl %eax, 0x34(%rsp)
jmp 0xb28d
movl 0x34(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x80(%rsp), %rdi
addq $0x68, %rdi
callq 0x4100
movq %rax, 0x28(%rsp)
jmp 0xb2b1
movq 0x28(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x43d0
movq 0x78(%rsp), %rax
movss %xmm0, 0x10(%rax)
movq 0x80(%rsp), %rdi
addq $0x88, %rdi
callq 0x4100
movq %rax, 0x20(%rsp)
jmp 0xb2e4
movq 0x20(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x43d0
movq 0x78(%rsp), %rax
movss %xmm0, 0x14(%rax)
movq 0x88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
jmp 0xb189
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xcc60
jmp 0xb391
movq 0x210(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0xcb80
jmp 0xb34f
leaq 0xa8(%rsp), %rdi
callq 0xcc60
jmp 0xb35e
leaq 0xd0(%rsp), %rdi
callq 0xcce0
jmp 0xb36d
leaq 0x140(%rsp), %rdi
callq 0xcce0
jmp 0xb37c
leaq 0x1a0(%rsp), %rdi
callq 0xcce0
addq $0x218, %rsp            # imm = 0x218
retq
jmp 0xb393
leaq 0xd0(%rsp), %rdi
callq 0xcce0
jmp 0xb3a2
jmp 0xb3a4
leaq 0x140(%rsp), %rdi
callq 0xcce0
jmp 0xb3b3
jmp 0xb3b5
leaq 0x1a0(%rsp), %rdi
callq 0xcce0
jmp 0xb3c4
jmp 0xb3c6
movq 0x138(%rsp), %rdi
callq 0x44d0
movq %rax, %rdi
callq 0x5b40
nopl (%rax,%rax)