// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rdi, %r14
leaq 0xc(%rsp), %rax
leaq 0x30(%rsp), %r10
leaq 0x68(%rsp), %rdi
leaq 0x58(%rsp), %rdx
leaq 0x98(%rsp), %rcx
leaq 0x10(%rsp), %r15
leaq 0xd(%rsp), %rbx
movl $0xa, %esi
movq %r15, %r8
movq %rbx, %r9
pushq %rax
pushq %r10
callq 0x8322
addq $0x10, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
leaq 0xe(%rsp), %rax
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0xf(%rsp), %r9
movl $0xa, %esi
pushq %rax
pushq %rbx
callq 0x686c
addq $0x10, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0xc8(%rsp)
movups %xmm0, 0xd8(%rsp)
movups %xmm0, 0xe8(%rsp)
movq (%r12), %rbx
movq %r12, 0x28(%rsp)
movq 0x8(%r12), %rdi
movq %rdi, %rsi
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
subq %rbx, %rsi
movq %r14, 0x48(%rsp)
je 0x79f8
xorl %r8d, %r8d
leaq 0x98(%rsp), %rbp
movq 0x28(%rsp), %r14
leaq (%r8,%r8,2), %r15
shlq $0x4, %r15
movl 0x8(%rbx,%r15), %ecx
movq %rcx, %rax
xorl %edx, %edx
divq 0x78(%rsp)
movq 0x70(%rsp), %rax
movq (%rax,%rdx,8), %rax
testq %rax, %rax
je 0x78ff
xorl %edx, %edx
xorl %esi, %esi
cmpl (%rax), %ecx
sete %sil
addq %rsi, %rdx
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x78e2
testq %rdx, %rdx
jne 0x79dc
movq %r8, 0x50(%rsp)
leaq (%rbx,%r15), %r13
addq $0x8, %r13
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r12
leaq 0x68(%rsp), %rdi
movq %r13, %rsi
callq 0x8186
addq %r15, %rbx
subq %r14, %r12
shrq $0x3, %r12
movl %r12d, (%rax)
addq $0x10, %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x66dc
movl (%r13), %eax
movl %eax, 0x30(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x7784
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rdx
cmpq (%rcx,%rdx,8), %rax
je 0x7977
movl 0x20(%rax), %eax
jmp 0x797c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x34(%rsp)
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
leaq 0x68(%rsp), %rdi
movq %r13, %rsi
callq 0x8186
subq %r14, %rbx
shrq $0x3, %rbx
movl %ebx, (%rax)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x79bc
movq 0x30(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x79cb
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x8724
movq 0x28(%rsp), %r14
movq (%r14), %rbx
movq 0x8(%r14), %rdi
movq 0x50(%rsp), %r8
incq %r8
movq %rdi, %rsi
subq %rbx, %rsi
sarq $0x4, %rsi
imulq %r12, %rsi
cmpq %rsi, %r8
jb 0x78bb
jmp 0x7a05
sarq $0x4, %rsi
imulq %r12, %rsi
movq 0x28(%rsp), %r14
leaq 0x58(%rsp), %rdx
movl $0x0, 0x8(%rdx)
movq $0x0, (%rdx)
leaq 0x30(%rsp), %rdi
leaq 0xd(%rsp), %rcx
callq 0x81c0
movq (%r14), %rbp
cmpq %rbp, 0x8(%r14)
je 0x7aee
movl $0x8, %r15d
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %eax, %eax
movq 0x30(%rsp), %r12
movl (%rbp,%r13,4), %ecx
cmpl %eax, %ecx
ja 0x7a6e
leaq 0x3b11(%rip), %rdi      # 0xb567
movl $0x92, %esi
leaq 0x3b36(%rip), %rdx      # 0xb598
xorl %eax, %eax
callq 0xa594
movl (%rbp,%r13,4), %ecx
movl 0x4(%rbp,%r13,4), %eax
cmpl %ecx, %eax
jae 0x7a9b
leaq 0x3ae9(%rip), %rdi      # 0xb567
movl $0x93, %esi
leaq 0x3b32(%rip), %rdx      # 0xb5bc
xorl %eax, %eax
callq 0xa594
movl (%rbp,%r13,4), %ecx
movl 0x4(%rbp,%r13,4), %eax
movl %ecx, (%r12,%r13)
movl %eax, 0x4(%r12,%r13)
leaq (%r15,%rbp), %rsi
leaq 0x68(%rsp), %rdi
callq 0x8186
movl (%rax), %eax
movl %eax, 0x8(%r12,%r13)
movl 0x4(%rbp,%r13,4), %eax
incq %rbx
movq (%r14), %rbp
movq 0x8(%r14), %rcx
subq %rbp, %rcx
sarq $0x4, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
addq $0xc, %r13
addq $0x30, %r15
cmpq %rcx, %rbx
jb 0x7a41
leaq 0x30(%rsp), %rsi
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x4ad2
leaq 0xc8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5274
leaq 0xe0(%rsp), %rsi
movq %rbx, %rdi
callq 0x740a
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x826c
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7b3c
callq 0x31d0
leaq 0x98(%rsp), %rdi
callq 0x682a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7b58
callq 0x31d0
leaq 0x68(%rsp), %rbx
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq %rbx, %rdi
callq 0x86d8
movq $0x0, 0x18(%rbx)
movq 0x8(%rbx), %rdi
callq 0x31d0
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7b9b
movq %rax, %rbx
jmp 0x7bbf
jmp 0x7ba0
jmp 0x7b9b
movq %rax, %rbx
jmp 0x7bb2
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7bb2
callq 0x31d0
leaq 0x98(%rsp), %rdi
callq 0x682a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7bce
callq 0x31d0
leaq 0x68(%rsp), %rdi
callq 0x82fe
movq %rbx, %rdi
callq 0x3350
movq %rax, %rdi
callq 0x4185