// File: chhylp123[P]hifiasm/hic.cpp
// Function: hic_short_pre_align(enzyme const*, enzyme const*, ha_ug_index*, ug_opt_t*, kvec_pe_hit**)
spg_t *hic_short_pre_align(const enzyme *fn1, const enzyme *fn2, ha_ug_index* idx, ug_opt_t *opt, kvec_pe_hit **rhits)
{
    // double index_time = yak_realtime();
    sldat_t sl;
    sl.idx = idx;
    sl.t_ch = idx->t_ch;
    sl.chunk_size = 20000000;
    sl.n_thread = asm_opt.thread_num;
    sl.total_base = sl.total_pair = 0;
    idx->hap_cnt = asm_opt.hap_occ;
    kv_init(sl.hits.a); kv_init(sl.hits.idx); kv_init(sl.hits.occ);

    if(!load_hc_hits(&sl.hits, idx->ug, asm_opt.output_file_name))
    {
        alignment_worker_pipeline(&sl, fn1, fn2);
        fprintf(stderr, "sb0sb\n");
        write_hc_hits(&sl.hits, idx->ug, asm_opt.output_file_name);
        fprintf(stderr, "sb1sb\n");
    }
    sl.hits.uID_bits = idx->uID_bits; sl.hits.pos_mode = idx->pos_mode;
    kv_u_trans_t k_trans; 
    kv_init(k_trans); kv_init(k_trans.idx);
    bubble_type bub; 
    memset(&bub, 0, sizeof(bubble_type));
    bub.round_id = 0; bub.n_round = asm_opt.n_weight;
    fprintf(stderr, "sb2sb\n");
    resolve_tangles_hic(idx, &bub, &sl.hits, &k_trans);
    fprintf(stderr, "sb3sb\n");
    spg_t *scg = horder_utg(&sl.hits, idx->uID_bits, idx->pos_mode, idx->read_g, idx->ug, &bub, opt);
    fprintf(stderr, "sb4sb\n");
    if(rhits){
        CALLOC(*rhits, 1);
        (**rhits) = sl.hits;
        sl.hits.a.a = NULL;
        sl.hits.idx.a = NULL;
        sl.hits.occ.a = NULL;
    }
    kv_destroy(sl.hits.a); kv_destroy(sl.hits.idx); kv_destroy(sl.hits.occ);
    kv_destroy(k_trans); kv_destroy(k_trans.idx);
    destory_bubbles(&bub);
    return scg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x1312d00, -0xa8(%rbp) # imm = 0x1312D00
leaq 0x1b9d20(%rip), %rax    # 0x3c47f8
movslq 0x7c(%rax), %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
leaq 0x1b9cf8(%rip), %rax    # 0x3c47f8
movslq 0x1b8(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x48(%rbp)
leaq -0xc0(%rbp), %rdi
addq $0x38, %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
leaq 0x1b9c85(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rdx
callq 0x1d5990
cmpl $0x0, %eax
jne 0x20abe7
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x200e50
movq 0x1b9444(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x182a71(%rip), %rsi    # 0x38d617
movb $0x0, %al
callq 0x22a0
leaq -0xc0(%rbp), %rdi
addq $0x38, %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
leaq 0x1b9c32(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rdx
callq 0x1d44d0
movq 0x1b940a(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x182a3e(%rip), %rsi    # 0x38d61e
movb $0x0, %al
callq 0x22a0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0xe8(%rbp)
movq $0x0, -0xf0(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xd8(%rbp)
movq $0x0, -0xc8(%rbp)
leaq -0x200(%rbp), %rdi
xorl %esi, %esi
movl $0x110, %edx            # imm = 0x110
callq 0x2100
movl $0x0, -0x1f8(%rbp)
leaq 0x1b9b93(%rip), %rax    # 0x3c47f8
movl 0x1e0(%rax), %eax
movl %eax, -0x1f4(%rbp)
movq 0x1b9368(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1829a3(%rip), %rsi    # 0x38d625
movb $0x0, %al
callq 0x22a0
movq -0x18(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
addq $0x38, %rdx
leaq -0x200(%rbp), %rsi
leaq -0xf0(%rbp), %rcx
callq 0x205720
movq 0x1b932e(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x182970(%rip), %rsi    # 0x38d62c
movb $0x0, %al
callq 0x22a0
leaq -0xc0(%rbp), %rdi
addq $0x38, %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %r8
movq -0x20(%rbp), %rax
leaq -0x200(%rbp), %r9
movq %rax, (%rsp)
callq 0x249020
movq %rax, -0x208(%rbp)
movq 0x1b92d1(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x18291a(%rip), %rsi    # 0x38d633
movb $0x0, %al
callq 0x22a0
cmpq $0x0, -0x28(%rbp)
je 0x20ad74
movl $0x1, %edi
movl $0x58, %esi
callq 0x2140
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
leaq -0xc0(%rbp), %rsi
addq $0x38, %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x58, %edx
callq 0x2180
movq $0x0, -0x78(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x78(%rbp), %rdi
callq 0x2210
movq -0x60(%rbp), %rdi
callq 0x2210
movq -0x48(%rbp), %rdi
callq 0x2210
movq -0xe0(%rbp), %rdi
callq 0x2210
movq -0xc8(%rbp), %rdi
callq 0x2210
leaq -0x200(%rbp), %rdi
callq 0x1c4a90
movq -0x208(%rbp), %rax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nopw %cs:(%rax,%rax)