// File: /workspace/github_cpp_makefile_star2_O2/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 0x133f9c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r12
movq %rdi, %rbx
movq 0x10(%rdi), %rbp
imulq $0x28, %rdx, %rdi
movq 0x18(%rbp,%rdi), %rdx
xorl %r15d, %r15d
cmpq $-0x1, (%rdx,%rcx,8)
sete %r15b
addq %rcx, %r15
xorl %ecx, %ecx
cmpq $-0x1, -0x8(%rdx,%r8,8)
sete %cl
subq %rcx, %r12
movq %r12, %r13
subq %r15, %r13
jbe 0x133f8e
movq (%rbx), %rcx
cmpq 0x8(%rbx), %rcx
movq %rsi, 0x10(%rsp)
jne 0x133e95
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmovneq %rax, %rcx
movq %rcx, 0x8(%rbx)
imulq $0x28, %rcx, %rsi
movq %rdi, 0x8(%rsp)
movq %rbp, %rdi
movq %r9, %r14
callq 0x2370
movq 0x8(%rsp), %rdi
movq %r14, %r9
movq %rax, %r14
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
jmp 0x133e98
movq %rbp, %r14
movq 0x50(%rsp), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
imulq $0x28, %rcx, %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14,%rcx)
movups %xmm0, (%r14,%rcx)
andq $0x0, 0x20(%r14,%rcx)
testq %r9, %r9
je 0x133ec4
movq %r15, (%r9)
leaq (%rdi,%rbp), %rdx
addq $0x18, %rdx
movq %rdx, 0x8(%rsp)
addq %rcx, %r14
testq %rax, %rax
je 0x133edc
movq %r12, (%rax)
movl %r13d, 0x10(%r14)
movl %r13d, 0xc(%r14)
movl %r13d, %ebp
leaq (,%rbp,8), %rbx
movq %rbx, %rdi
callq 0x2280
movq %rax, %r12
movq %rax, 0x18(%r14)
shlq $0x3, %r15
movq 0x8(%rsp), %rax
addq (%rax), %r15
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2160
movl 0x4(%r12), %eax
movl %eax, 0x4(%r14)
decl %r13d
movq (%r12,%r13,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
xorl $0x1, %ecx
movl %ecx, 0x8(%r14)
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rax, %rcx
movq %rcx, (%r12,%r13,8)
movq 0x10(%rsp), %rdx
movq 0x20(%rdx), %rdx
shrq $0x21, %rax
movl (%rdx,%rax,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orq %rcx, %rax
movq %rax, (%r12,%r13,8)
xorl %ecx, %ecx
pushq $0x64
popq %rdx
xorl %eax, %eax
cmpq %rcx, %rbp
je 0x133f83
movq (%r12,%rcx,8), %rsi
cmpq $-0x1, %rsi
cmoveq %rdx, %rsi
addq %rsi, %rax
incq %rcx
jmp 0x133f6a
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, (%r14)
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq