// File: loadzero[P]geoloc/geoloc/asns.hpp
// Function: save_asns(BinaryFile&, std::vector<ASN, std::allocator<ASN>> const&)
inline void save_asns(BinaryFile &file, const std::vector<ASN> &asns)
{
    hash_map<unsigned, unsigned> asn_to_idx;
    std::vector<PackedASN> packed_asns;

    StringTable text;

    for (size_t i = 0; i < asns.size(); ++i)
    {
        const ASN &asn = asns[i];

        if (asn_to_idx.count(asn.number))
        {
            continue;
        }

        asn_to_idx[asn.number] = packed_asns.size();
        text.insert(asn.text);

        PackedASN pasn;

        pasn.number = asn.number;
        pasn.text = text.index_of(asn.text);

        asn_to_idx[asn.number] = packed_asns.size();
        packed_asns.push_back(pasn);
    }

    std::vector<Block> asn_blocks(asns.size());

    unsigned last = 0;

    for (size_t i = 0; i < asns.size(); ++i)
    {
        Block &block = asn_blocks[i];
        const ASN &asn = asns[i];

        REL_ASSERT(asn.start_ip > last);
        REL_ASSERT(asn.end_ip >= asn.start_ip);

        block.start_ip = asn.start_ip;
        block.end_ip = asn.end_ip;
        block.loc = asn_to_idx[asn.number];

        last = asn.end_ip;
    }

    save_blocks(file, asn_blocks);
    save_string_table(file, text);
    file.save_pod_vector(packed_asns);
}

// Assembly:
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, 0x1b0(%rsp)
movq %rsi, 0x1a8(%rsp)
leaq 0x175(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x137d0
movq 0x80(%rsp), %r8
leaq 0x178(%rsp), %rdi
movl $0xa, %esi
leaq 0x177(%rsp), %rdx
leaq 0x176(%rsp), %rcx
callq 0x137e0
jmp 0x121c8
leaq 0x175(%rsp), %rdi
callq 0x13820
leaq 0x148(%rsp), %rdi
callq 0x13830
jmp 0x121e4
leaq 0xe8(%rsp), %rdi
callq 0xc720
jmp 0x121f3
movq $0x0, 0xe0(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x13410
movq %rax, %rcx
movq 0x78(%rsp), %rax
cmpq %rcx, %rax
jae 0x1240d
movq 0x1a8(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x13840
movq %rax, 0x70(%rsp)
jmp 0x12246
movq 0x70(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x178(%rsp), %rdi
callq 0x13860
movq %rax, 0x68(%rsp)
jmp 0x12273
movq 0x68(%rsp), %rax
cmpq $0x0, %rax
je 0x122f4
jmp 0x123f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
leaq 0x175(%rsp), %rdi
callq 0x13820
jmp 0x126ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0x126ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0x126dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0x126cc
leaq 0x148(%rsp), %rdi
callq 0x13920
movq %rax, 0x60(%rsp)
jmp 0x12308
movq 0x60(%rsp), %rax
movl %eax, 0x54(%rsp)
movq 0xd8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x178(%rsp), %rdi
callq 0x13940
movq %rax, 0x58(%rsp)
jmp 0x12331
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
movl %ecx, (%rax)
movq 0xd8(%rsp), %rsi
addq $0x10, %rsi
leaq 0xe8(%rsp), %rdi
callq 0xc870
jmp 0x12357
movq 0xd8(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0xd0(%rsp)
movq 0xd8(%rsp), %rsi
addq $0x10, %rsi
leaq 0xe8(%rsp), %rdi
callq 0xcb00
movl %eax, 0x50(%rsp)
jmp 0x12388
movl 0x50(%rsp), %eax
movl %eax, 0xd4(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x13920
movq %rax, 0x48(%rsp)
jmp 0x123a7
movq 0x48(%rsp), %rax
movl %eax, 0x3c(%rsp)
movq 0xd8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x178(%rsp), %rdi
callq 0x13940
movq %rax, 0x40(%rsp)
jmp 0x123d0
movq 0x40(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl %ecx, (%rax)
leaq 0x148(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x13a40
jmp 0x123f2
jmp 0x123f4
movq 0xe0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xe0(%rsp)
jmp 0x121ff
movq 0x1a8(%rsp), %rdi
callq 0x13410
movq %rax, 0x28(%rsp)
movl $0x0, 0xb0(%rsp)
movq $0x0, 0xa8(%rsp)
leaq 0xa7(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x13ab0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rcx
leaq 0xb8(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x13ac0
jmp 0x12469
leaq 0xa7(%rsp), %rdi
callq 0x13b50
movl $0x0, 0xa0(%rsp)
movq $0x0, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x13410
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x12643
movq 0x98(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x13b60
movq %rax, 0x18(%rsp)
jmp 0x124d4
movq 0x18(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x1a8(%rsp), %rdi
movq 0x98(%rsp), %rsi
callq 0x13840
movq %rax, 0x10(%rsp)
jmp 0x124fd
movq 0x10(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rax
movl (%rax), %eax
cmpl 0xa0(%rsp), %eax
ja 0x12587
leaq 0x9fd3(%rip), %rdi      # 0x1c4f7
leaq 0x9ffd(%rip), %rdx      # 0x1c528
xorl %eax, %eax
movl $0x92, %esi
callq 0x1b800
jmp 0x12539
jmp 0x12587
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
leaq 0xa7(%rsp), %rdi
callq 0x13b50
jmp 0x126cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x7260
jmp 0x126ca
movq 0x88(%rsp), %rax
movl 0x4(%rax), %eax
movq 0x88(%rsp), %rcx
cmpl (%rcx), %eax
jae 0x125bc
leaq 0x9f52(%rip), %rdi      # 0x1c4f7
leaq 0x9fa0(%rip), %rdx      # 0x1c54c
xorl %eax, %eax
movl $0x93, %esi
callq 0x1b800
jmp 0x125ba
jmp 0x125bc
movq 0x88(%rsp), %rax
movl (%rax), %ecx
movq 0x90(%rsp), %rax
movl %ecx, (%rax)
movq 0x88(%rsp), %rax
movl 0x4(%rax), %ecx
movq 0x90(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x88(%rsp), %rsi
addq $0x8, %rsi
leaq 0x178(%rsp), %rdi
callq 0x13940
movq %rax, 0x8(%rsp)
jmp 0x12606
movq 0x8(%rsp), %rax
movl (%rax), %ecx
movq 0x90(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x88(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0xa0(%rsp)
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
jmp 0x1248d
movq 0x1b0(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x6e70
jmp 0x1265a
movq 0x1b0(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0xc970
jmp 0x12671
movq 0x1b0(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x13b80
jmp 0x12688
leaq 0xb8(%rsp), %rdi
callq 0x7260
jmp 0x12697
leaq 0xe8(%rsp), %rdi
callq 0xcce0
jmp 0x126a6
leaq 0x148(%rsp), %rdi
callq 0x13c60
jmp 0x126b5
leaq 0x178(%rsp), %rdi
callq 0x13ce0
addq $0x1b8, %rsp            # imm = 0x1B8
retq
jmp 0x126cc
leaq 0xe8(%rsp), %rdi
callq 0xcce0
jmp 0x126db
jmp 0x126dd
leaq 0x148(%rsp), %rdi
callq 0x13c60
jmp 0x126ec
jmp 0x126ee
leaq 0x178(%rsp), %rdi
callq 0x13ce0
jmp 0x126fd
jmp 0x126ff
movq 0x168(%rsp), %rdi
callq 0x44d0
movq %rax, %rdi
callq 0x5b40
nopw %cs:(%rax,%rax)
nop