// File: /workspace/github_cpp_makefile_star2_O1/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 0x17109a
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 0x17108c
movq %r9, %r12
movq %rsi, 0x10(%rsp)
movq 0x8(%rbp), %rax
cmpq %rax, (%rbp)
jne 0x170f7d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x8(%rbp)
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
movq %rdi, 0x8(%rsp)
movq %r13, %rdi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rbp)
movq 0x50(%rsp), %rax
movq (%rbp), %rdx
movq 0x10(%rbp), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbp)
leaq (%rdx,%rdx,4), %rdx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rcx,%rdx,8)
movups %xmm0, (%rcx,%rdx,8)
movq $0x0, 0x20(%rcx,%rdx,8)
testq %r12, %r12
je 0x170fb4
movq %r14, (%r12)
leaq 0x18(%r13,%rdi,8), %r13
leaq (%rcx,%rdx,8), %r12
testq %rax, %rax
je 0x170fc5
movq %r15, (%rax)
movl %ebx, 0x10(%r12)
movl %ebx, 0xc(%r12)
movl %ebx, %r15d
shlq $0x3, %r15
movq %r15, %rdi
callq 0x2280
movq %rax, 0x18(%r12)
shlq $0x3, %r14
addq (%r13), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2160
movq 0x18(%r12), %rax
movl 0x4(%rax), %ecx
movl %ecx, 0x4(%r12)
movl 0x10(%r12), %ecx
leal -0x1(%rcx), %edx
movq (%rax,%rdx,8), %rsi
movq %rsi, %rdi
shrq $0x20, %rdi
xorl $0x1, %edi
movl %edi, 0x8(%r12)
movabsq $-0x100000000, %rdi     # imm = 0xFFFFFFFF00000000
andq %rsi, %rdi
movq %rdi, (%rax,%rdx,8)
movq 0x10(%rsp), %r8
movq 0x20(%r8), %r8
shrq $0x21, %rsi
movl (%r8,%rsi,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orq %rdi, %rsi
movq %rsi, (%rax,%rdx,8)
andb $0x7f, 0x3(%r12)
xorl %edx, %edx
cmpl $0x1, %ecx
jb 0x171083
xorl %edx, %edx
movl $0x64, %esi
xorl %edi, %edi
movq (%rax,%rdi,8), %r8
cmpq $-0x1, %r8
cmoveq %rsi, %r8
addq %r8, %rdx
incq %rdi
cmpq %rdi, %rcx
jne 0x171066
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %edx, (%r12)
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq