// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %r14
movq %rdi, 0x48(%rsp)
leaq 0x58(%rsp), %rdi
pushq $0xa
popq %rsi
leaq 0x98(%rsp), %rdx
leaq 0x10(%rsp), %rbx
leaq 0x30(%rsp), %r8
movq %rbx, %rcx
callq 0x7532
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0x98(%rsp), %rdi
callq 0x5b7c
pushq $0x8
popq %rsi
xorl %r12d, %r12d
movq %r14, 0x50(%rsp)
movq (%r14), %r13
movq 0x8(%r14), %rax
subq %r13, %rax
cqto
pushq $0x30
popq %rcx
idivq %rcx
cmpq %rax, %r12
jae 0x6d5d
movq %rsi, %rbp
leaq (%rsi,%r13), %rbx
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x7380
testq %rax, %rax
jne 0x6d49
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x73b2
subq %r14, %r15
shrq $0x3, %r15
movl %r15d, (%rax)
addq %rbp, %r13
addq $0x8, %r13
leaq 0x98(%rsp), %rdi
movq %r13, %rsi
callq 0x5bb0
movl (%rbx), %eax
movl %eax, 0x30(%rsp)
leaq 0x98(%rsp), %rdi
movq %r13, %rsi
callq 0x5ca0
movl %eax, 0x34(%rsp)
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x73b2
subq %r14, %r15
shrq $0x3, %r15
movl %r15d, (%rax)
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x7410
incq %r12
movq %rbp, %rsi
addq $0x30, %rsi
movq 0x50(%rsp), %r14
jmp 0x6c8f
leaq 0x88(%rsp), %rdx
andl $0x0, 0x8(%rdx)
andq $0x0, (%rdx)
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rcx
movq %rax, %rsi
callq 0x742e
pushq $0x8
popq %rbp
xorl %r12d, %r12d
xorl %ecx, %ecx
xorl %ebx, %ebx
movq (%r14), %r15
movq 0x8(%r14), %rax
subq %r15, %rax
cqto
pushq $0x30
popq %rsi
idivq %rsi
cmpq %rax, %rbx
jae 0x6e2f
movq 0x30(%rsp), %r13
movl (%r15,%r12,4), %eax
cmpl %ecx, %eax
ja 0x6dcf
leaq 0x3781(%rip), %rdi      # 0xa539
movl $0x92, %esi
leaq 0x37a6(%rip), %rdx      # 0xa56a
xorl %eax, %eax
callq 0x94d0
movl (%r15,%r12,4), %eax
movl 0x4(%r15,%r12,4), %ecx
cmpl %eax, %ecx
jae 0x6dfb
leaq 0x375a(%rip), %rdi      # 0xa539
movl $0x93, %esi
leaq 0x37a3(%rip), %rdx      # 0xa58e
xorl %eax, %eax
callq 0x94d0
movl (%r15,%r12,4), %eax
movl 0x4(%r15,%r12,4), %ecx
movl %eax, (%r13,%r12)
movl %ecx, 0x4(%r13,%r12)
leaq (%r15,%rbp), %rsi
leaq 0x58(%rsp), %rdi
callq 0x73b2
movl (%rax), %eax
movl %eax, 0x8(%r13,%r12)
movl 0x4(%r15,%r12,4), %ecx
incq %rbx
addq $0xc, %r12
addq $0x30, %rbp
jmp 0x6d89
leaq 0x30(%rsp), %rsi
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x4756
leaq 0x98(%rsp), %rsi
movq %rbx, %rdi
callq 0x5c33
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x748c
leaq 0x30(%rsp), %rdi
callq 0x5318
leaq 0x98(%rsp), %rdi
callq 0x5d5a
leaq 0x10(%rsp), %rdi
callq 0x7948
leaq 0x58(%rsp), %rdi
callq 0x751e
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x6ed6
jmp 0x6ead
jmp 0x6ead
movq %rax, %rbx
jmp 0x6ecc
jmp 0x6eb2
jmp 0x6ead
movq %rax, %rbx
jmp 0x6ebf
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5318
leaq 0x98(%rsp), %rdi
callq 0x5d5a
leaq 0x10(%rsp), %rdi
callq 0x7948
leaq 0x58(%rsp), %rdi
callq 0x751e
movq %rbx, %rdi
callq 0x3370
movq %rax, %rdi
callq 0x3e8f