// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ma_integer_ug_print0(ma_ug_t const*, ul_resolve_t*, int, char const*, _IO_FILE*, unsigned int)
void ma_integer_ug_print0(const ma_ug_t *ug, ul_resolve_t *uidx, int print_seq, const char* prefix, FILE *fp, uint32_t is_seq)
{
    uint32_t i, j, l, x; ma_utg_t *p, *s; ul2ul_idx_t *idx = &(uidx->uovl);
    char name[32]; uinfo_srt_warp_t *seq; asgc8_v t; kv_init(t); //uint64_t tot = 0;
    for (i = 0; i < ug->u.n; ++i) { // the Segment lines in GFA
        p = &ug->u.a[i];
        if(p->m == 0) continue;
        if(ug->g && ug->g->seq[i].del) continue;
        sprintf(name, "%s%.6d%c", prefix, i + 1, "lc"[p->circ]);
        if(is_seq) {
            gen_ul_seq(uidx, i, &t);
            fprintf(fp, "S\t%s\t%s\tLN:i:%d\trd:i:%lu\n", name, t.a, p->len, get_ul_occ(uidx, i));
        } else {
            fprintf(fp, "S\t%s\t*\tLN:i:%d\trd:i:%lu\n", name, p->len, get_ul_occ(uidx, i));
        }
        // tot += p->len;
        
        for (j = l = 0; j < p->n; j++) {
            if(p->a[j] != (uint64_t)-1) {
                x = p->a[j]>>33;
                if(ulg_type(uidx->uovl, x)) {//read
                    x = ulg_id(uidx->uovl, x);
                    fprintf(fp, "A\t%s\t%d\t%c\t%.*s\t%d\t%d\tid:i:%d\tHG:A:*\n", name, l, "+-"[p->a[j]>>32&1],
                    (int32_t)uidx->idx->nid.a[x].n, uidx->idx->nid.a[x].a, 0, uidx->idx->a[x].rlen, x);
                } else { ///node
                    x = ulg_id(uidx->uovl, x); s = &(uidx->init_ug->u.a[x]);
                    fprintf(fp, "A\t%s\t%d\t%c\tutg%.6d%c\t%d\t%d\tid:i:%d\tHG:A:*\n", name, l, "+-"[p->a[j]>>32&1],
                    x + 1, "lc"[s->circ], 0, s->len, x);
                }
            }
            else
            {
                fprintf(fp, "A\t%s\t%d\t*\t*\t*\t*\tid:i:*\tHG:A:*\n", name, l);
            }
            l += (uint32_t)p->a[j];
        }

        seq = &(idx->cc.iug_a[i]);
        for (j = 0; j < seq->n; j++) {
            x = seq->a[j].v>>1; s = &(uidx->init_ug->u.a[x]);
            fprintf(fp, "U\t%s\t%c\tutg%.6d%c\t%d\t%d\tHG:A:*\n", 
            name, "+-"[seq->a[j].v&1], x + 1, "lc"[s->circ], seq->a[j].s, seq->a[j].e);
        }
        
    }

    if(ug->g)
    {
        asg_arc_t* au = NULL;
        uint32_t nu, u, v;
        for (i = 0; i < ug->u.n; ++i) {
            if(ug->u.a[i].m == 0) continue;
            if(ug->u.a[i].circ)
            {
                fprintf(fp, "L\t%s%.6dc\t+\t%s%.6dc\t+\t%dM\tL1:i:%d\n", 
                prefix, i+1, prefix, i+1, 0, ug->u.a[i].len);
                fprintf(fp, "L\t%s%.6dc\t-\t%s%.6dc\t-\t%dM\tL1:i:%d\n", 
                prefix, i+1, prefix, i+1, 0, ug->u.a[i].len);
            } 
            u = i<<1;
            au = asg_arc_a(ug->g, u);
            nu = asg_arc_n(ug->g, u);
            for (j = 0; j < nu; j++)
            {
                if(au[j].del) continue;
                v = au[j].v;
                fprintf(fp, "L\t%s%.6d%c\t%c\t%s%.6d%c\t%c\t%dM\tL1:i:%d\tL2:i:%u\n", 
                prefix, (u>>1)+1, "lc"[ug->u.a[u>>1].circ], "+-"[u&1],
                prefix, (v>>1)+1, "lc"[ug->u.a[v>>1].circ], "+-"[v&1], au[j].ol, asg_arc_len(au[j]), au[j].ou);
            }


            u = (i<<1) + 1;
            au = asg_arc_a(ug->g, u);
            nu = asg_arc_n(ug->g, u);
            for (j = 0; j < nu; j++)
            {
                if(au[j].del) continue;
                v = au[j].v;
                fprintf(fp, "L\t%s%.6d%c\t%c\t%s%.6d%c\t%c\t%dM\tL1:i:%d\tL2:i:%u\n", 
                prefix, (u>>1)+1, "lc"[ug->u.a[u>>1].circ], "+-"[u&1],
                prefix, (v>>1)+1, "lc"[ug->u.a[v>>1].circ], "+-"[v&1], au[j].ol, asg_arc_len(au[j]), au[j].ou);
            }
        }
    }
    kv_destroy(t);
    // fprintf(stderr, "[M::%s::] tot::%lu\n", __func__, tot);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %r9d, 0x20(%rsp)
movq %r8, 0x8(%rsp)
movq %rcx, 0x30(%rsp)
movq %rsi, (%rsp)
movq %rdi, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
cmpq $0x0, (%rdi)
movq %rdi, 0x18(%rsp)
je 0x1ff94a
leaq 0x28fb5(%rip), %r9      # 0x22862b
xorl %ebx, %ebx
movq $0x0, 0x10(%rsp)
movq 0x10(%r13), %rax
leaq (%rbx,%rbx,4), %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
leaq 0x60(%rsp), %r14
je 0x1ff92c
movq 0x18(%rsp), %rdx
movq 0x18(%rdx), %rdx
testq %rdx, %rdx
je 0x1ff6b5
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%rbx,8)
js 0x1ff92c
leaq (%rax,%rcx,8), %r15
movq 0x10(%rsp), %rax
leal 0x1(%rax), %ecx
movl (%r15), %eax
shrl $0x1f, %eax
movsbl (%rax,%r9), %r8d
movq %r14, %rdi
leaq 0x2ab14(%rip), %rsi     # 0x22a1ea
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
cmpl $0x0, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
je 0x1ff736
movq (%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
leaq 0x40(%rsp), %rdx
callq 0x1ff34b
movq 0x50(%rsp), %rcx
movl (%r15), %r8d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r8d
movq 0x248(%r12), %rax
movl (%rax,%rbx,4), %r9d
movq 0x8(%rsp), %rdi
leaq 0x3c223(%rip), %rsi     # 0x23b94d
movq %r14, %rdx
xorl %eax, %eax
callq 0x22b0
jmp 0x1ff766
movl (%r15), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movq (%rsp), %r12
movq 0x248(%r12), %rax
movl (%rax,%rbx,4), %r8d
movq 0x8(%rsp), %rdi
leaq 0x3c20b(%rip), %rsi     # 0x23b967
movq %r14, %rdx
xorl %eax, %eax
callq 0x22b0
leaq 0x26a56(%rip), %rbx     # 0x2261c3
cmpl $0x0, 0x10(%r15)
je 0x1ff895
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rax
cmpq $-0x1, %rax
je 0x1ff7fc
movq %rax, %r11
shrq $0x21, %r11
movq %r11, %r10
subq 0x208(%r12), %r10
jae 0x1ff816
btq $0x20, %rax
adcq $0x0, %rbx
movsbl (%rbx), %r8d
movq 0x30(%r12), %rax
imulq $0x58, %r11, %rcx
movq %r11, %r10
shlq $0x4, %r10
movq 0x10(%rax), %r14
movq 0x48(%rax), %rax
movl 0x8(%r14,%r10), %r9d
movl 0x18(%rax,%rcx), %ebx
movq 0x8(%rsp), %rdi
leaq 0x3c1a7(%rip), %rsi     # 0x23b980
leaq 0x60(%rsp), %rdx
movl %ebp, %ecx
xorl %eax, %eax
pushq %r11
pushq %rbx
leaq 0x269d7(%rip), %rbx     # 0x2261c3
pushq $0x0
pushq (%r14,%r10)
leaq 0x80(%rsp), %r14
jmp 0x1ff874
movq 0x8(%rsp), %rdi
leaq 0x2aa76(%rip), %rsi     # 0x22a27e
movq %r14, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x22b0
jmp 0x1ff87d
movq 0x8(%r12), %rcx
movq 0x10(%rcx), %rcx
movl %r10d, %edx
btq $0x20, %rax
adcq $0x0, %rbx
leaq (%rdx,%rdx,4), %rdx
movsbl (%rbx), %r8d
leal 0x1(%r10), %r9d
movl (%rcx,%rdx,8), %r11d
movl %r11d, %eax
shrl $0x1f, %eax
leaq 0x28de3(%rip), %rcx     # 0x22862b
movsbl (%rax,%rcx), %ebx
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rdi
leaq 0x3c147(%rip), %rsi     # 0x23b9a6
movq %r14, %rdx
movl %ebp, %ecx
xorl %eax, %eax
pushq %r10
pushq %r11
pushq $0x0
pushq %rbx
leaq 0x2694f(%rip), %rbx     # 0x2261c3
callq 0x22b0
addq $0x20, %rsp
movq 0x18(%r15), %rax
addl (%rax,%r13,8), %ebp
incq %r13
movl 0x10(%r15), %eax
cmpq %rax, %r13
jb 0x1ff77d
movq 0x260(%r12), %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
cmpq $0x0, (%rax,%rcx,8)
leaq 0x28d79(%rip), %r9      # 0x22862b
je 0x1ff92c
movq %r14, %r15
leaq (%rax,%rcx,8), %r14
movl $0x1, %ebp
xorl %eax, %eax
movq 0x10(%r14), %rdx
shlq $0x4, %rax
movl (%rdx,%rax), %ecx
movl 0x4(%rdx,%rax), %r10d
movl %ecx, %r8d
shrl %r8d
movq 0x8(%r12), %rsi
movq 0x10(%rsi), %rsi
leaq (%r8,%r8,4), %rdi
andl $0x1, %ecx
movsbl (%rcx,%rbx), %ecx
incl %r8d
movl (%rsi,%rdi,8), %esi
shrl $0x1f, %esi
movq %r9, %r13
movsbl (%rsi,%r9), %r9d
movl 0x8(%rdx,%rax), %r11d
movq 0x8(%rsp), %rdi
leaq 0x3c0c3(%rip), %rsi     # 0x23b9d1
movq %r15, %rdx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x22b0
movq %r13, %r9
addq $0x10, %rsp
movl %ebp, %eax
incl %ebp
cmpq %rax, (%r14)
ja 0x1ff8c2
movq 0x10(%rsp), %rax
incl %eax
movq %rax, %rbx
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %r13
cmpq %rax, (%r13)
ja 0x1ff681
cmpq $0x0, 0x18(%r13)
je 0x1ffc43
cmpq $0x0, (%r13)
je 0x1ffc43
xorl %eax, %eax
movq $0x0, (%rsp)
movq 0x10(%r13), %rcx
leaq (%rax,%rax,4), %r14
cmpl $0x0, 0xc(%rcx,%r14,8)
je 0x1ffc2c
leaq (%rcx,%r14,8), %rax
movl (%rax), %r10d
testl %r10d, %r10d
movq 0x8(%rsp), %rbx
jns 0x1ffa06
movq (%rsp), %rax
leal 0x1(%rax), %r13d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
andl %ebp, %r10d
movq %rbx, %rdi
leaq 0x30821(%rip), %rsi     # 0x2301ca
movq 0x30(%rsp), %r15
movq %r15, %rdx
movl %r13d, %ecx
movq %r15, %r8
movl %r13d, %r9d
xorl %eax, %eax
pushq %r10
xorl %r12d, %r12d
pushq %r12
callq 0x22b0
addq $0x10, %rsp
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%r14,8), %r10d
andl %ebp, %r10d
movq %rbx, %rdi
leaq 0x30807(%rip), %rsi     # 0x2301ed
movq %r15, %rdx
movl %r13d, %ecx
movq %r15, %r8
movl %r13d, %r9d
movq 0x18(%rsp), %r13
xorl %eax, %eax
pushq %r10
pushq %r12
callq 0x22b0
addq $0x10, %rsp
movq (%rsp), %rax
leal (%rax,%rax), %edx
movq 0x18(%r13), %rcx
movq 0x28(%rcx), %rax
movq %rdx, 0x38(%rsp)
movq (%rax,%rdx,8), %rax
testl %eax, %eax
je 0x1ffb1c
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movq (%rsp), %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %rsi, 0x28(%rsp)
incl %esi
movl %esi, 0x20(%rsp)
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r12
addq $0x10, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
movl -0x4(%r12,%r14), %r10d
testl %r10d, %r10d
js 0x1ffb0d
movl -0x10(%r12,%r14), %r11d
movl -0x8(%r12,%r14), %eax
movq 0x10(%r13), %rcx
movq 0x28(%rsp), %rdx
leaq (%rdx,%rdx,4), %rdx
movl (%rcx,%rdx,8), %edx
shrl $0x1f, %edx
leaq 0x28b95(%rip), %rsi     # 0x22862b
movsbl (%rdx,%rsi), %r8d
movl %eax, %r13d
shrl %r13d
leaq (,%r13,4), %rdx
addq %r13, %rdx
incl %r13d
movl (%rcx,%rdx,8), %ecx
shrl $0x1f, %ecx
movsbl (%rcx,%rsi), %ebx
andl $0x1, %eax
leaq 0x26700(%rip), %rcx     # 0x2261c3
movsbl (%rax,%rcx), %r15d
movzwl (%r12,%r14), %ebp
andl $0x3fff, %ebp           # imm = 0x3FFF
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
leaq 0x2a810(%rip), %rsi     # 0x22a2f3
movq 0x38(%rsp), %rdx
movl 0x28(%rsp), %ecx
movl $0x2b, %r9d
xorl %eax, %eax
pushq %rbp
pushq %r11
pushq %r10
pushq %r15
pushq %rbx
pushq %r13
movq 0x50(%rsp), %r13
pushq %rdx
callq 0x22b0
addq $0x40, %rsp
addq $0x18, %r14
cmpq %r14, 0x10(%rsp)
jne 0x1ffa64
movq 0x18(%r13), %rcx
movq 0x28(%rcx), %rax
movl 0x38(%rsp), %edx
movq 0x8(%rax,%rdx,8), %rax
testl %eax, %eax
je 0x1ffc2c
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movq (%rsp), %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leal 0x1(%rsi), %edi
movl %edi, 0x28(%rsp)
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r15
addq $0x10, %r15
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x10(%rsp)
leaq (%rsi,%rsi,4), %rax
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
movl -0x4(%r15,%r14), %r10d
testl %r10d, %r10d
js 0x1ffc1d
movl -0x10(%r15,%r14), %r11d
movl -0x8(%r15,%r14), %eax
movq 0x10(%r13), %rcx
movq 0x20(%rsp), %rdx
movl (%rcx,%rdx,8), %edx
shrl $0x1f, %edx
leaq 0x28a85(%rip), %rsi     # 0x22862b
movsbl (%rdx,%rsi), %r8d
movl %eax, %r13d
shrl %r13d
leaq (,%r13,4), %rdx
addq %r13, %rdx
incl %r13d
movl (%rcx,%rdx,8), %ecx
shrl $0x1f, %ecx
movsbl (%rcx,%rsi), %ebx
andl $0x1, %eax
leaq 0x265f0(%rip), %rcx     # 0x2261c3
movsbl (%rax,%rcx), %ebp
movzwl (%r15,%r14), %r12d
andl $0x3fff, %r12d          # imm = 0x3FFF
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
leaq 0x2a700(%rip), %rsi     # 0x22a2f3
movq 0x38(%rsp), %rdx
movl 0x30(%rsp), %ecx
movl $0x2d, %r9d
xorl %eax, %eax
pushq %r12
pushq %r11
pushq %r10
pushq %rbp
pushq %rbx
pushq %r13
movq 0x50(%rsp), %r13
pushq %rdx
callq 0x22b0
addq $0x40, %rsp
addq $0x18, %r14
cmpq %r14, 0x10(%rsp)
jne 0x1ffb78
movq (%rsp), %rdx
incl %edx
movq %rdx, %rax
movq %rdx, (%rsp)
cmpq %rdx, (%r13)
ja 0x1ff96a
movq 0x50(%rsp), %rdi
callq 0x2220
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq