// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/horder.cpp
// Function: append_sub_utg(ma_ug_t*, asg_t*, unsigned long, unsigned long, unsigned long, unsigned long*, unsigned long*)
int append_sub_utg(ma_ug_t *ug, asg_t *rg, uint64_t uid, uint64_t sidx, uint64_t eidx, uint64_t *rsidx, uint64_t *reidx)
{
    if(eidx <= sidx) return 0;
    uint64_t i, offset;
    ma_utg_t *u = &(ug->u.a[uid]), *p = NULL;
    if(u->a[sidx] == (uint64_t)-1) sidx++;
    if(u->a[eidx-1] == (uint64_t)-1) eidx--;
    if(eidx <= sidx) return 0 ;
    kv_pushp(ma_utg_t, ug->u, &p);
    memset(p, 0, sizeof(*p));
    if(rsidx) (*rsidx) = sidx;
    if(reidx) (*reidx) = eidx;
    p->m = p->n = eidx - sidx;
    MALLOC(p->a, p->m);
    memcpy(p->a, u->a + sidx, p->n*sizeof(uint64_t));
    p->start = p->a[0]>>32;
    p->end = (p->a[p->n-1]>>32)^1;
    p->a[p->n-1] >>= 32; p->a[p->n-1] <<= 32; 
    p->a[p->n-1] += rg->seq[(p->a[p->n-1]>>33)].len;

    p->circ = 0;
    for (i = offset = 0; i < p->n; i++)
    {
        offset += (p->a[i] != (uint64_t)-1? (uint32_t)p->a[i]:GAP_LEN);
    }
    p->len = offset;
    return 1;
}

// Assembly:
xorl %eax, %eax
cmpq %rcx, %r8
jbe 0x177c8e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r15
movq %rdi, %rbp
movq 0x10(%rdi), %r13
leaq (%rdx,%rdx,4), %rdi
movq 0x18(%r13,%rdi,8), %rdx
xorl %r14d, %r14d
cmpq $-0x1, (%rdx,%rcx,8)
sete %r14b
addq %rcx, %r14
xorl %ecx, %ecx
cmpq $-0x1, -0x8(%rdx,%r8,8)
sete %cl
subq %rcx, %r15
movq %r15, %rbx
subq %r14, %rbx
jbe 0x177c80
movq %r9, %r12
movq (%rbp), %rdx
cmpq 0x8(%rbp), %rdx
movq %rsi, 0x10(%rsp)
jne 0x177b7a
leaq (%rdx,%rdx), %rax
testq %rdx, %rdx
movl $0x2, %ecx
cmovneq %rax, %rcx
movq %rcx, 0x8(%rbp)
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
movq %rdi, 0x8(%rsp)
movq %r13, %rdi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rbp)
movq (%rbp), %rdx
jmp 0x177b7d
movq %r13, %rax
movq 0x50(%rsp), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbp)
leaq (%rdx,%rdx,4), %rdx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax,%rdx,8)
movups %xmm0, (%rax,%rdx,8)
movq $0x0, 0x20(%rax,%rdx,8)
testq %r12, %r12
je 0x177bac
movq %r14, (%r12)
leaq 0x18(,%rdi,8), %rsi
addq %r13, %rsi
movq %rsi, 0x8(%rsp)
leaq (%rax,%rdx,8), %r13
testq %rcx, %rcx
je 0x177bc8
movq %r15, (%rcx)
movl %ebx, 0x10(%r13)
movl %ebx, 0xc(%r13)
movl %ebx, %ebp
leaq (,%rbp,8), %r12
movq %r12, %rdi
callq 0x2280
movq %rax, %r15
movq %rax, 0x18(%r13)
shlq $0x3, %r14
movq 0x8(%rsp), %rax
addq (%rax), %r14
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2160
movl 0x4(%r15), %eax
movl %eax, 0x4(%r13)
leal -0x1(%rbx), %eax
movq (%r15,%rax,8), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
xorl $0x1, %edx
movl %edx, 0x8(%r13)
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rdx
movq %rdx, (%r15,%rax,8)
movq 0x10(%rsp), %rsi
movq 0x20(%rsi), %rsi
shrq $0x21, %rcx
movl (%rsi,%rcx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orq %rdx, %rcx
movq %rcx, (%r15,%rax,8)
xorl %eax, %eax
testl %ebx, %ebx
je 0x177c77
movl $0x64, %ecx
xorl %edx, %edx
movq (%r15,%rdx,8), %rsi
cmpq $-0x1, %rsi
cmoveq %rcx, %rsi
addq %rsi, %rax
incq %rdx
cmpq %rdx, %rbp
jne 0x177c5b
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, (%r13)
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq