// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: get_arc_support_chain(ul_resolve_t*, unsigned long*, unsigned long, usg_t*)
uint64_t get_arc_support_chain(ul_resolve_t *uidx, uint64_t *a, uint64_t a_n, usg_t *ng)
{
    if(a_n <= 0) return 0;
    uint64_t *hid_a, hid_n; ul_str_idx_t *str_idx = &(uidx->pstr);
    uint64_t z, vz, occ = 0, v, w, ai; ul_str_t *str; int64_t s, s_n;
    v = (ng->a[a[0]>>1].mm<<1)|(a[0]&1);
    hid_a = str_idx->occ.a + str_idx->idx.a[v>>1];
    hid_n = str_idx->idx.a[(v>>1)+1] - str_idx->idx.a[v>>1];

    for (z = occ = 0; z < hid_n; z++) {
        str = &(str_idx->str.a[hid_a[z]>>32]); s_n = str->cn;
        if(s_n < 2) continue;
        vz = (uint32_t)(str->a[(uint32_t)hid_a[z]]);
        assert((v>>1) == (vz>>1)); 

        if(v == vz) {
            for(s = ((uint32_t)hid_a[z]) + 1, ai = 1; s < s_n && ai < a_n; s++, ai++) {
                w = (ng->a[a[ai]>>1].mm<<1)|(a[ai]&1);
                if(((uint32_t)(str->a[s])) != w) break;
            }
            if(ai >= a_n) occ++;
        } else {
            for(s = ((int32_t)((uint32_t)hid_a[z]))-1, ai = 1; s >= 0 && ai < a_n; s--, ai++) {
                w = (ng->a[a[ai]>>1].mm<<1)|(a[ai]&1);
                if(((uint32_t)(str->a[s])) != (w^1)) break;
            }
            if(ai >= a_n) occ++;
        }
    }
    return occ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
ja 0x35c14f
movq $0x0, -0x8(%rbp)
jmp 0x35c480
movq -0x10(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
shrq %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movl %eax, %eax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
andq $0x1, %rcx
orq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x60(%rbp), %rdx
shrq %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
shrq %rcx
movq 0x8(%rax,%rcx,8), %rax
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x60(%rbp), %rdx
shrq %rdx
subq (%rcx,%rdx,8), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x35c478
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x88(%rbp)
cmpq $0x2, -0x88(%rbp)
jge 0x35c24b
jmp 0x35c467
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rax
shrq %rax
movq -0x50(%rbp), %rcx
shrq %rcx
cmpq %rcx, %rax
jne 0x35c280
jmp 0x35c29f
leaq 0x3cab8(%rip), %rdi     # 0x398d3f
leaq 0x39f2b(%rip), %rsi     # 0x3961b9
movl $0x334f, %edx           # imm = 0x334F
leaq 0x3d904(%rip), %rcx     # 0x399b9e
callq 0x2130
movq -0x60(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x35c38a
movq -0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq $0x1, -0x70(%rbp)
movq -0x80(%rbp), %rcx
xorl %eax, %eax
cmpq -0x88(%rbp), %rcx
movb %al, -0x89(%rbp)
jge 0x35c2f0
movq -0x70(%rbp), %rax
cmpq -0x20(%rbp), %rax
setb %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x35c2fc
jmp 0x35c36f
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movl %eax, %eax
movq -0x18(%rbp), %rcx
movq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
andq $0x1, %rcx
orq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
cmpq -0x68(%rbp), %rax
je 0x35c350
jmp 0x35c36f
jmp 0x35c352
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x35c2ca
movq -0x70(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x35c385
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x35c465
movq -0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
subl $0x1, %eax
cltq
movq %rax, -0x80(%rbp)
movq $0x1, -0x70(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x80(%rbp)
movb %al, -0x8a(%rbp)
jl 0x35c3c7
movq -0x70(%rbp), %rax
cmpq -0x20(%rbp), %rax
setb %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0x35c3d3
jmp 0x35c44d
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movl %eax, %eax
movq -0x18(%rbp), %rcx
movq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
andq $0x1, %rcx
orq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq -0x68(%rbp), %rcx
xorq $0x1, %rcx
cmpq %rcx, %rax
je 0x35c42e
jmp 0x35c44d
jmp 0x35c430
movq -0x80(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x35c3a7
movq -0x70(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x35c463
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x35c465
jmp 0x35c467
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x35c1f6
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)