// File: chhylp123[P]hifiasm/hic.cpp
// Function: write_hc_hits_v14(kvec_pe_hit_hap*, char const*)
void write_hc_hits_v14(kvec_pe_hit_hap* i_hits, const char *fn)
{
    char *buf = (char*)calloc(strlen(fn) + 25, 1);
	sprintf(buf, "%s.v14.hic.lk.bin", fn);
    FILE* fp = fopen(buf, "w");
    kvec_pe_hit hits; 
    kv_init(hits.a);
    uint64_t i, m_u = (uint64_t)-1, m_m = (uint64_t)-1;
    pe_hit* p = NULL;
    for (i = 0; i < i_hits->n; i++)
    {
        if(i_hits->a[i].occ1 == 1 && i_hits->a[i].occ2 == 1) 
        {
            kv_pushp(pe_hit, hits.a, &p);
            p->id = i_hits->a[i].id;
            p->s = i_hits->a[i].a[0];
            p->e = i_hits->a[i].a[1];
            m_u = i;
        }
        else
        {
            if(m_m == (uint64_t)-1) m_m = i;
        }
    }
    fprintf(stderr, "m_u: %lu, m_m: %lu, n_u: %lu\n", m_u, m_m, i_hits->n_u);

    fwrite(&hits.a.n, sizeof(hits.a.n), 1, fp);
    fwrite(hits.a.a, sizeof(pe_hit), hits.a.n, fp);

    kv_destroy(hits.a);
    fclose(fp);
    free(buf);
    exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x19, %rdi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x1b7e8e(%rip), %rsi    # 0x38c45e
movb $0x0, %al
callq 0x2050
movq -0x18(%rbp), %rdi
leaq 0x1c4df0(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x20(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x68(%rbp)
movq $-0x1, -0x88(%rbp)
movq $-0x1, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1d477d
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movzwl 0x10(%rax), %eax
cmpl $0x1, %eax
jne 0x1d4753
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movzwl 0x12(%rax), %eax
cmpl $0x1, %eax
jne 0x1d4753
jmp 0x1d4678
movq -0x78(%rbp), %rax
cmpq -0x70(%rbp), %rax
jne 0x1d46c7
cmpq $0x0, -0x70(%rbp)
je 0x1d4699
movq -0x70(%rbp), %rax
shlq %rax
movq %rax, -0xa0(%rbp)
jmp 0x1d46a7
movl $0x2, %eax
movq %rax, -0xa0(%rbp)
jmp 0x1d46a7
movq -0xa0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
shlq $0x5, %rsi
callq 0x2360
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x78(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x78(%rbp)
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x98(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq 0x8(%rax), %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x1d476a
cmpq $-0x1, -0x90(%rbp)
jne 0x1d4768
movq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x1d476a
jmp 0x1d476c
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1d462c
movq 0x1ef85c(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %r8
leaq 0x1b7ccc(%rip), %rsi    # 0x38c470
movb $0x0, %al
callq 0x22a0
leaq -0x78(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x68(%rbp), %rdi
movq -0x78(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x20, %esi
callq 0x2400
movq -0x68(%rbp), %rdi
callq 0x2210
movq -0x20(%rbp), %rdi
callq 0x21a0
movq -0x18(%rbp), %rdi
callq 0x2210
movl $0x1, %edi
callq 0x2240
nopl (%rax)