// File: /workspace/github_cpp_makefile_star2_O3/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 $0x98, %rsp
movl %r9d, 0x18(%rsp)
movq %r8, 0x8(%rsp)
movq %rcx, 0x38(%rsp)
movq %rsi, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
cmpq $0x0, (%rdi)
je 0x20b353
movq %rdi, %r12
leaq 0x299ef(%rip), %r15     # 0x23473b
leaq 0x70(%rsp), %r13
movq $0x0, 0x40(%rsp)
xorl %ebp, %ebp
xorl %ebx, %ebx
movq %rdi, 0x28(%rsp)
movq 0x10(%r12), %rax
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
je 0x20b030
movq 0x18(%r12), %rdx
testq %rdx, %rdx
je 0x20ad96
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%rbp,8)
js 0x20b030
leaq (%rax,%rcx,8), %r14
leal 0x1(%rbx), %ecx
movl (%r14), %eax
shrl $0x1f, %eax
movsbl (%rax,%r15), %r8d
movq %r13, %rdi
leaq 0x2b628(%rip), %rsi     # 0x2363da
movq 0x38(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
cmpl $0x0, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %rbp, 0x30(%rsp)
je 0x20ae1d
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x50(%rsp), %rdx
callq 0x20aa25
movq 0x60(%rsp), %rcx
movl (%r14), %r8d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r8d
movq 0x248(%r12), %rax
movl (%rax,%rbp,4), %r9d
movq 0x8(%rsp), %rdi
leaq 0x3ce25(%rip), %rsi     # 0x247c31
movq %r13, %rdx
movq %rcx, 0x40(%rsp)
xorl %eax, %eax
callq 0x22b0
jmp 0x20ae4e
movl (%r14), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movq 0x10(%rsp), %r12
movq 0x248(%r12), %rax
movl (%rax,%rbp,4), %r8d
movq 0x8(%rsp), %rdi
leaq 0x3ce07(%rip), %rsi     # 0x247c4b
movq %r13, %rdx
xorl %eax, %eax
callq 0x22b0
cmpl $0x0, 0x10(%r14)
je 0x20af74
movq 0x18(%r14), %rax
xorl %ebp, %ebp
xorl %r15d, %r15d
movq (%rax,%rbp,8), %rax
cmpq $-0x1, %rax
je 0x20aed9
movq %rax, %r11
shrq $0x21, %r11
movq %r11, %r10
subq 0x208(%r12), %r10
jae 0x20aef4
btq $0x20, %rax
leaq 0x27447(%rip), %rax     # 0x2322d3
adcq $0x0, %rax
movsbl (%rax), %r8d
movq 0x30(%r12), %rax
imulq $0x58, %r11, %rcx
movq %r11, %r10
shlq $0x4, %r10
movq 0x10(%rax), %r12
movq 0x48(%rax), %rax
movl 0x8(%r12,%r10), %r9d
movl 0x18(%rax,%rcx), %ebx
movq 0x8(%rsp), %rdi
leaq 0x3cda3(%rip), %rsi     # 0x247c64
movq %r13, %rdx
movl %r15d, %ecx
xorl %eax, %eax
pushq %r11
pushq %rbx
pushq $0x0
pushq (%r12,%r10)
movq 0x30(%rsp), %r12
jmp 0x20af53
movq 0x8(%rsp), %rdi
leaq 0x2b589(%rip), %rsi     # 0x23646e
movq %r13, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
jmp 0x20af5c
movq 0x8(%r12), %rcx
movq 0x10(%rcx), %rcx
movl %r10d, %edx
btq $0x20, %rax
leaq 0x273c7(%rip), %rax     # 0x2322d3
adcq $0x0, %rax
leaq (%rdx,%rdx,4), %rdx
movsbl (%rax), %r8d
leal 0x1(%r10), %r9d
movl (%rcx,%rdx,8), %r11d
movl %r11d, %eax
shrl $0x1f, %eax
leaq 0x2980e(%rip), %rcx     # 0x23473b
movsbl (%rax,%rcx), %ebx
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rdi
leaq 0x3cd46(%rip), %rsi     # 0x247c8a
movq %r13, %rdx
movl %r15d, %ecx
xorl %eax, %eax
pushq %r10
pushq %r11
pushq $0x0
pushq %rbx
callq 0x22b0
addq $0x20, %rsp
movq 0x18(%r14), %rax
addl (%rax,%rbp,8), %r15d
incq %rbp
movl 0x10(%r14), %ecx
cmpq %rcx, %rbp
jb 0x20ae62
movq 0x260(%r12), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x20b01f
leaq (%rax,%rcx,8), %r14
movl $0x1, %ebp
xorl %eax, %eax
leaq 0x29799(%rip), %r15     # 0x23473b
movq %r12, %rbx
leaq 0x3cd09(%rip), %r12     # 0x247cb5
movq 0x10(%r14), %rdx
shlq $0x4, %rax
movl (%rdx,%rax), %ecx
movl 0x4(%rdx,%rax), %r10d
movl %ecx, %r8d
shrl %r8d
movq 0x8(%rbx), %rsi
movq 0x10(%rsi), %rsi
leaq (%r8,%r8,4), %rdi
andl $0x1, %ecx
leaq 0x272fb(%rip), %r9      # 0x2322d3
movsbl (%rcx,%r9), %ecx
incl %r8d
movl (%rsi,%rdi,8), %esi
shrl $0x1f, %esi
movsbl (%rsi,%r15), %r9d
movl 0x8(%rdx,%rax), %r11d
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x22b0
addq $0x10, %rsp
movl %ebp, %eax
incl %ebp
cmpq %rax, (%r14)
ja 0x20afac
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r12
jmp 0x20b030
movq 0x28(%rsp), %r12
leaq 0x29710(%rip), %r15     # 0x23473b
movq 0x20(%rsp), %rbx
incl %ebx
movq (%r12), %rax
movq %rbx, %rbp
cmpq %rbx, %rax
ja 0x20ad63
testq %rax, %rax
sete %al
cmpq $0x0, 0x18(%r12)
sete %cl
orb %al, %cl
jne 0x20b34c
xorl %eax, %eax
xorl %ecx, %ecx
movq %rcx, 0x18(%rsp)
movq 0x10(%r12), %rcx
leaq (%rax,%rax,4), %r14
cmpl $0x0, 0xc(%rcx,%r14,8)
je 0x20b338
leaq (%rcx,%r14,8), %rax
movl (%rax), %r10d
testl %r10d, %r10d
jns 0x20b10b
movq 0x18(%rsp), %rax
leal 0x1(%rax), %r15d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
andl %ebp, %r10d
movq 0x8(%rsp), %r12
movq %r12, %rdi
leaq 0x3132f(%rip), %rsi     # 0x23c3d6
movq 0x38(%rsp), %rbx
movq %rbx, %rdx
movl %r15d, %ecx
movq %rbx, %r8
movl %r15d, %r9d
xorl %eax, %eax
pushq %r10
xorl %r13d, %r13d
pushq %r13
callq 0x22b0
addq $0x10, %rsp
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%r14,8), %r10d
andl %ebp, %r10d
movq %r12, %rdi
leaq 0x31315(%rip), %rsi     # 0x23c3f9
movq %rbx, %rdx
movl %r15d, %ecx
movq %rbx, %r8
movl %r15d, %r9d
leaq 0x29644(%rip), %r15     # 0x23473b
movq 0x28(%rsp), %r12
xorl %eax, %eax
pushq %r10
pushq %r13
callq 0x22b0
addq $0x10, %rsp
movq 0x18(%rsp), %rsi
leal (%rsi,%rsi), %edi
movq 0x18(%r12), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%rdi,8), %rdx
testl %edx, %edx
je 0x20b233
movq %rdi, 0x48(%rsp)
movq %rdx, %rcx
shrq $0x20, %rcx
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %rsi, 0x20(%rsp)
incl %esi
movl %esi, 0x30(%rsp)
movl %edx, %edx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r14
addq $0x10, %r14
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
movl -0x4(%r14,%rbp), %r10d
testl %r10d, %r10d
js 0x20b212
movl -0x10(%r14,%rbp), %r11d
movl -0x8(%r14,%rbp), %eax
movq 0x10(%r12), %rcx
movq 0x20(%rsp), %rdx
leaq (%rdx,%rdx,4), %rdx
movl (%rcx,%rdx,8), %edx
shrl $0x1f, %edx
movsbl (%rdx,%r15), %r8d
movl %eax, %r15d
shrl %r15d
leaq (%r15,%r15,4), %rdx
incl %r15d
movl (%rcx,%rdx,8), %ecx
shrl $0x1f, %ecx
leaq 0x2958a(%rip), %rdx     # 0x23473b
movsbl (%rcx,%rdx), %ebx
andl $0x1, %eax
leaq 0x27114(%rip), %rcx     # 0x2322d3
movsbl (%rax,%rcx), %r13d
movzwl (%r14,%rbp), %r12d
andl $0x3fff, %r12d          # imm = 0x3FFF
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
leaq 0x2b303(%rip), %rsi     # 0x2364e3
movq 0x40(%rsp), %rdx
movl 0x38(%rsp), %ecx
movl $0x2b, %r9d
xorl %eax, %eax
pushq %r12
pushq %r11
pushq %r10
pushq %r13
pushq %rbx
pushq %r15
leaq 0x29538(%rip), %r15     # 0x23473b
movq 0x60(%rsp), %r12
pushq %rdx
callq 0x22b0
addq $0x40, %rsp
addq $0x18, %rbp
cmpq %rbp, 0x10(%rsp)
jne 0x20b166
movq 0x18(%r12), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq 0x48(%rsp), %rdi
movl %edi, %edx
movq 0x8(%rcx,%rdx,8), %rcx
testl %ecx, %ecx
je 0x20b338
movq %rcx, %rdx
shrq $0x20, %rdx
movq 0x18(%rsp), %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leal 0x1(%rsi), %edi
movl %edi, 0x20(%rsp)
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r14
addq $0x10, %r14
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rax
movq %rax, 0x10(%rsp)
leaq (%rsi,%rsi,4), %rax
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
movl -0x4(%r14,%rbp), %r10d
testl %r10d, %r10d
js 0x20b329
movl -0x10(%r14,%rbp), %r11d
movl -0x8(%r14,%rbp), %eax
movq 0x10(%r12), %rcx
movq 0x30(%rsp), %rdx
movl (%rcx,%rdx,8), %edx
shrl $0x1f, %edx
movsbl (%rdx,%r15), %r8d
movl %eax, %r15d
shrl %r15d
leaq (%r15,%r15,4), %rdx
incl %r15d
movl (%rcx,%rdx,8), %ecx
shrl $0x1f, %ecx
leaq 0x29473(%rip), %rdx     # 0x23473b
movsbl (%rcx,%rdx), %ebx
andl $0x1, %eax
leaq 0x26ffd(%rip), %rcx     # 0x2322d3
movsbl (%rax,%rcx), %r13d
movzwl (%r14,%rbp), %r12d
andl $0x3fff, %r12d          # imm = 0x3FFF
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
leaq 0x2b1ec(%rip), %rsi     # 0x2364e3
movq 0x40(%rsp), %rdx
movl 0x28(%rsp), %ecx
movl $0x2d, %r9d
xorl %eax, %eax
pushq %r12
pushq %r11
pushq %r10
pushq %r13
pushq %rbx
pushq %r15
leaq 0x29421(%rip), %r15     # 0x23473b
movq 0x60(%rsp), %r12
pushq %rdx
callq 0x22b0
addq $0x40, %rsp
addq $0x18, %rbp
cmpq %rbp, 0x10(%rsp)
jne 0x20b281
movq 0x18(%rsp), %rcx
incl %ecx
movq %rcx, %rax
cmpq %rcx, (%r12)
ja 0x20b05d
movq 0x40(%rsp), %rdi
jmp 0x20b355
xorl %edi, %edi
callq 0x2220
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq