// File: chhylp123[P]hifiasm/anchor.cpp
// Function: h_ec_lchain_re_gen_srt(ha_abuf_s*, ha_pt_s*, overlap_region_alloc*, Candidates_list*)
void h_ec_lchain_re_gen_srt(ha_abuf_t *ab, ha_pt_t *ha_idx, overlap_region_alloc *olst, Candidates_list *cl)
{
	uint64_t i, k; int j, n; ha_mz1_t *z; seed1_t *s; 
    
    clear_Candidates_list(cl); ab->n_a = 0;

	// minimizer of queried read
    if (ab->mz.m > ab->old_mz_m) {
        ab->old_mz_m = ab->mz.m;
        REALLOC(ab->seed, ab->old_mz_m);
    }

    for (i = 0, ab->n_a = 0; i < ab->mz.n; ++i) {
        ab->seed[i].a = ha_pt_get(ha_idx, ab->mz.a[i].x, &n);
        ab->seed[i].n = n;
        ab->n_a += n;
    }

	if (ab->n_a > ab->m_a) {
        ab->m_a = ab->n_a;
        REALLOC(ab->a, ab->m_a);
    }

	for (i = 0, k = 0; i < ab->mz.n; ++i) {
        ///z is one of the minimizer
        z = &ab->mz.a[i]; s = &ab->seed[i];

        for (j = 0; j < s->n; ++j) {
            const ha_idxpos_t *y = &s->a[j];
            anchor1_t *an = &ab->a[k++];
            uint8_t rev = z->rev == y->rev? 0 : 1;

			an->other_off = y->span;
			an->self_off = i;
            ///an->cnt: cnt<<8|span
            an->cnt = s->n; if(an->cnt > ((uint32_t)(0xffffffu))) an->cnt = 0xffffffu;
            an->cnt <<= 8; an->cnt |= ((z->span <= ((uint32_t)(0xffu)))?z->span:((uint32_t)(0xffu)));
			an->srt = (uint64_t)y->rid<<33 | (uint64_t)rev<<32 | y->pos;
        }
    }

	// copy over to _cl_
    if (ab->m_a >= (uint64_t)cl->size) {
        cl->size = ab->m_a;
        REALLOC(cl->list, cl->size);
    }
	clear_overlap_region_alloc(olst);
	radix_sort_ha_an1(ab->a, ab->a + ab->n_a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x23090
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jbe 0x1b2d2f
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
shlq $0x4, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x28(%rax)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
cmpq %rcx, %rax
jae 0x1b2dc6
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
leaq -0x38(%rbp), %rdx
callq 0x1877b0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x38(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movslq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1b2d42
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x1b2e07
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
imulq $0x18, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
cmpq %rcx, %rax
jae 0x1b2fc1
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1b2fae
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x37, %rax
andq $0x1, %rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movq (%rax), %rax
shrq $0x37, %rax
andq $0x1, %rax
movl %eax, %esi
movl $0x1, %eax
xorl %ecx, %ecx
cmpl %esi, %edx
cmovel %ecx, %eax
movb %al, -0x59(%rbp)
movq -0x50(%rbp), %rax
movq (%rax), %rax
shrq $0x38, %rax
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rax
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
movl (%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x58(%rbp), %rax
cmpl $0xffffff, 0x10(%rax)   # imm = 0xFFFFFF
jbe 0x1b2f20
movq -0x58(%rbp), %rax
movl $0xffffff, 0x10(%rax)   # imm = 0xFFFFFF
movq -0x58(%rbp), %rax
movl 0x10(%rax), %ecx
shll $0x8, %ecx
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x38, %rax
cmpl $0xff, %eax
ja 0x1b2f51
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x38, %rax
movl %eax, -0x60(%rbp)
jmp 0x1b2f5b
movl $0xff, %eax
movl %eax, -0x60(%rbp)
jmp 0x1b2f5b
movl -0x60(%rbp), %ecx
movq -0x58(%rbp), %rax
orl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq (%rax), %rcx
andq $0xfffffff, %rcx        # imm = 0xFFFFFFF
shlq $0x21, %rcx
movzbl -0x59(%rbp), %eax
shlq $0x20, %rax
orq %rax, %rcx
movq -0x50(%rbp), %rax
movq (%rax), %rax
shrq $0x1c, %rax
andq $0x7ffffff, %rax        # imm = 0x7FFFFFF
orq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1b2e60
jmp 0x1b2fb0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1b2e17
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jb 0x1b3005
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x4, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rdi
callq 0x1e120
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x8(%rbp), %rax
imulq $0x18, (%rax), %rax
addq %rax, %rsi
callq 0x19c150
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)