// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %r8, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r13
leaq 0x50(%rsp), %r14
movq %rdx, -0x38(%r14)
movq 0x10(%rdx), %rax
movq %rax, 0x58(%r14)
movq $0x1312d00, -0x20(%r14) # imm = 0x1312D00
leaq 0x26e9b1(%rip), %rbp    # 0x28a758
movslq 0x7c(%rbp), %rax
movq %rax, -0x18(%r14)
xorps %xmm0, %xmm0
movups %xmm0, -0x10(%r14)
movslq 0x1b8(%rbp), %rax
movq %rax, 0x48(%rdx)
movups %xmm0, 0x30(%r14)
movups %xmm0, 0x20(%r14)
andq $0x0, 0x40(%r14)
movups %xmm0, 0x10(%r14)
movups %xmm0, (%r14)
movq (%rdx), %rsi
movq 0x10(%rbp), %rdx
movq %r14, %rdi
callq 0x14107b
testl %eax, %eax
jne 0x1be47
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x156cbb
movq 0x26e1dc(%rip), %r13    # 0x289fe0
movq (%r13), %rcx
leaq 0x21499b(%rip), %rdi    # 0x2307aa
pushq $0x6
popq %rbx
pushq $0x1
popq %r15
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2410
movq (%r12), %rsi
movq 0x10(%rbp), %rdx
movq %r14, %rdi
callq 0x14050c
movq (%r13), %rcx
leaq 0x214975(%rip), %rdi    # 0x2307b1
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2410
movq 0x18(%r12), %rax
movq %rax, 0x98(%rsp)
movq 0x30(%r12), %rax
movq %rax, 0xa0(%rsp)
leaq 0xb0(%rsp), %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
leaq 0xe8(%rsp), %rbx
movl $0x110, %edx            # imm = 0x110
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
movl 0x1e0(%rbp), %eax
movl %eax, 0xc(%rbx)
movq 0x26e13f(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21490d(%rip), %rdi    # 0x2307b8
pushq $0x6
popq %r13
pushq $0x1
popq %rbp
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2410
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x15983d
movq 0x26e10b(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x2148e0(%rip), %rdi    # 0x2307bf
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2410
movq 0x18(%r12), %rsi
movq 0x30(%r12), %rdx
movq (%r12), %r8
movq 0x8(%r12), %rcx
movq 0x8(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %rdi
movq %rbx, %r9
callq 0x22405
movq %rax, %r15
movq 0x26e0c5(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x2148a1(%rip), %rdi    # 0x2307c6
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2410
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0x1bf69
pushq $0x1
popq %rdi
pushq $0x58
popq %rsi
callq 0x2120
movq %rax, (%rbx)
pushq $0xb
popq %rcx
movq %rax, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
andq $0x0, 0x60(%rsp)
andq $0x0, 0x78(%rsp)
andq $0x0, 0x90(%rsp)
movq 0x60(%rsp), %rdi
callq 0x2220
movq 0x78(%rsp), %rdi
callq 0x2220
movq 0x90(%rsp), %rdi
callq 0x2220
movq 0xc0(%rsp), %rdi
callq 0x2220
movq 0xd8(%rsp), %rdi
callq 0x2220
leaq 0xe8(%rsp), %rdi
callq 0x1380d4
movq %r15, %rax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq