// File: /workspace/github_cpp_makefile_star2_O1/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 0x38(%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 0x8284
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 0x38(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0xf(%rsp), %r9
movl $0xa, %esi
pushq %rax
pushq %rbx
callq 0x67dc
addq $0x10, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0xc8(%rsp)
movups %xmm0, 0xd8(%rsp)
movups %xmm0, 0xe8(%rsp)
movq (%r12), %rbx
movq %r12, 0x30(%rsp)
movq 0x8(%r12), %rsi
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
subq %rbx, %rsi
movq %r14, 0x50(%rsp)
je 0x796f
xorl %ebp, %ebp
movq 0x30(%rsp), %r14
leaq (,%rbp,2), %r15
addq %rbp, %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 0x7878
xorl %edx, %edx
xorl %esi, %esi
cmpl (%rax), %ecx
sete %sil
addq %rsi, %rdx
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x785b
testq %rdx, %rdx
jne 0x794f
leaq (%rbx,%r15), %r13
addq $0x8, %r13
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r12
leaq 0x68(%rsp), %rdi
movq %r13, %rsi
callq 0x80e8
leaq 0x98(%rsp), %rcx
addq %r15, %rbx
subq %r14, %r12
shrq $0x3, %r12
movl %r12d, (%rax)
addq $0x10, %rbx
movq %rcx, %r14
movq %rcx, %rdi
movq %rbx, %rsi
callq 0x6654
movl (%r13), %eax
movl %eax, 0x38(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7702
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rdx
cmpq (%rcx,%rdx,8), %rax
je 0x78f6
movl 0x20(%rax), %eax
jmp 0x78fb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x3c(%rsp)
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
leaq 0x68(%rsp), %rdi
movq %r13, %rsi
callq 0x80e8
subq %r14, %rbx
shrq $0x3, %rbx
movl %ebx, (%rax)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x793b
movq 0x38(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x794a
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x868a
movq 0x30(%rsp), %r14
incq %rbp
movq (%r14), %rbx
movq 0x8(%r14), %rsi
subq %rbx, %rsi
sarq $0x4, %rsi
imulq %r12, %rsi
cmpq %rsi, %rbp
jb 0x782d
jmp 0x797c
sarq $0x4, %rsi
imulq %r12, %rsi
movq 0x30(%rsp), %r14
leaq 0x58(%rsp), %rdx
movl $0x0, 0x8(%rdx)
movq $0x0, (%rdx)
leaq 0x38(%rsp), %rdi
leaq 0xd(%rsp), %rcx
callq 0x813a
movq (%r14), %rbp
cmpq %rbp, 0x8(%r14)
je 0x7a57
movl $0x8, %r15d
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %eax, %eax
movq 0x38(%rsp), %r12
cmpl %eax, (%rbp,%r13,4)
ja 0x79de
leaq 0x3b9c(%rip), %rdi      # 0xb567
movl $0x92, %esi
leaq 0x3bc1(%rip), %rdx      # 0xb598
xorl %eax, %eax
callq 0xa50c
movl 0x4(%rbp,%r13,4), %eax
cmpl (%rbp,%r13,4), %eax
jae 0x7a04
leaq 0x3b76(%rip), %rdi      # 0xb567
movl $0x93, %esi
leaq 0x3bbf(%rip), %rdx      # 0xb5bc
xorl %eax, %eax
callq 0xa50c
movq (%rbp,%r13,4), %rax
movq %rax, (%r12,%r13)
leaq (%r15,%rbp), %rsi
leaq 0x68(%rsp), %rdi
callq 0x80e8
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 0x79b8
leaq 0x38(%rsp), %rsi
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0x4a46
leaq 0xc8(%rsp), %rsi
movq %rbx, %rdi
callq 0x51e0
leaq 0xe0(%rsp), %rsi
movq %rbx, %rdi
callq 0x738a
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x81ce
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x7aa5
callq 0x31d0
leaq 0x98(%rsp), %rdi
callq 0x679a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7ac1
callq 0x31d0
leaq 0x68(%rsp), %rbx
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq %rbx, %rdi
callq 0x863e
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 0x7b04
movq %rax, %rbx
jmp 0x7b28
jmp 0x7b09
jmp 0x7b04
movq %rax, %rbx
jmp 0x7b1b
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x7b1b
callq 0x31d0
leaq 0x98(%rsp), %rdi
callq 0x679a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7b37
callq 0x31d0
leaq 0x68(%rsp), %rdi
callq 0x8260
movq %rbx, %rdi
callq 0x3350
movq %rax, %rdi
callq 0x40f4
nop