// File: /workspace/github_cpp_makefile_star2_O2/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, 0x10(%rsp)
movq %r8, 0x8(%rsp)
movq %rcx, 0x30(%rsp)
movq %rsi, %r13
movq %rdi, %r15
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x50(%rsp), %rbx
movq $0x0, 0x38(%rsp)
xorl %r14d, %r14d
movq %rdi, 0x20(%rsp)
movl %r14d, %r14d
movq (%r15), %rax
cmpq %r14, %rax
jbe 0x1bea54
movq 0x10(%r15), %rbp
imulq $0x28, %r14, %rax
cmpl $0x0, 0xc(%rbp,%rax)
je 0x1bea4c
movq 0x18(%r15), %rcx
testq %rcx, %rcx
je 0x1be7e1
movq 0x20(%rcx), %rcx
cmpl $0x0, (%rcx,%r14,8)
js 0x1bea4c
addq %rax, %rbp
leal 0x1(%r14), %ecx
movl (%rbp), %eax
shrl $0x1f, %eax
leaq 0x27e96(%rip), %rdx     # 0x1e668b
movsbl (%rax,%rdx), %r8d
movq %rbx, %rdi
leaq 0x29ad6(%rip), %rsi     # 0x1e82da
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
cmpl $0x0, 0x10(%rsp)
movq %r14, 0x18(%rsp)
je 0x1be868
movq %r13, %rdi
movq %r14, %rsi
leaq 0x70(%rsp), %rdx
callq 0x1be4fa
movq 0x80(%rsp), %rcx
movl (%rbp), %r8d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r8d
movq 0x248(%r13), %rax
movl (%rax,%r14,4), %r9d
movq 0x8(%rsp), %rdi
leaq 0x3b399(%rip), %rsi     # 0x1f9bf0
movq %rbx, %rdx
movq %rcx, 0x38(%rsp)
xorl %eax, %eax
callq 0x22b0
jmp 0x1be893
movl (%rbp), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movq 0x248(%r13), %rax
movl (%rax,%r14,4), %r8d
movq 0x8(%rsp), %rdi
leaq 0x3b381(%rip), %rsi     # 0x1f9c0a
movq %rbx, %rdx
xorl %eax, %eax
callq 0x22b0
xorl %r12d, %r12d
xorl %r15d, %r15d
movl 0x10(%rbp), %eax
cmpq %rax, %r12
jae 0x1be9b3
movq 0x18(%rbp), %rax
movq (%rax,%r12,8), %rax
cmpq $-0x1, %rax
je 0x1be91d
movq %rax, %r11
shrq $0x21, %r11
movq %r11, %r10
subq 0x208(%r13), %r10
jae 0x1be93a
btq $0x20, %rax
leaq 0x25951(%rip), %rax     # 0x1e4223
adcq $0x0, %rax
movsbl (%rax), %r8d
movq 0x30(%r13), %rax
imulq $0x58, %r11, %rcx
movq %r11, %r10
shlq $0x4, %r10
movq 0x10(%rax), %rbx
movq 0x48(%rax), %rax
movl 0x8(%rbx,%r10), %r9d
movl 0x18(%rax,%rcx), %r14d
movq 0x8(%rsp), %rdi
leaq 0x3b31c(%rip), %rsi     # 0x1f9c23
leaq 0x50(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
pushq %r11
pushq %r14
pushq $0x0
pushq (%rbx,%r10)
jmp 0x1be99a
movq 0x8(%rsp), %rdi
leaq 0x29a45(%rip), %rsi     # 0x1e836e
leaq 0x50(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
jmp 0x1be9a3
movq 0x8(%r13), %rcx
movl %r10d, %edx
imulq $0x28, %rdx, %rdx
btq $0x20, %rax
leaq 0x258d2(%rip), %rax     # 0x1e4223
adcq $0x0, %rax
movq 0x10(%rcx), %rcx
movsbl (%rax), %r8d
leal 0x1(%r10), %r9d
movl (%rcx,%rdx), %r11d
movl %r11d, %eax
shrl $0x1f, %eax
leaq 0x27d19(%rip), %rcx     # 0x1e668b
movsbl (%rax,%rcx), %ebx
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rdi
leaq 0x3b2c0(%rip), %rsi     # 0x1f9c49
leaq 0x50(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
pushq %r10
pushq %r11
pushq $0x0
pushq %rbx
callq 0x22b0
addq $0x20, %rsp
movq 0x18(%rbp), %rax
addl (%rax,%r12,8), %r15d
incq %r12
jmp 0x1be899
imulq $0x18, 0x18(%rsp), %r14
addq 0x260(%r13), %r14
xorl %eax, %eax
leaq 0x50(%rsp), %rbx
leaq 0x3b2a6(%rip), %r12     # 0x1f9c74
movl %eax, %r15d
cmpq %r15, (%r14)
jbe 0x1bea42
movq 0x10(%r14), %rax
movq %r15, %rdx
shlq $0x4, %rdx
movl (%rax,%rdx), %ecx
movl 0x4(%rax,%rdx), %r10d
movl %ecx, %r8d
shrl %r8d
movq 0x8(%r13), %rsi
movq 0x10(%rsi), %rsi
imulq $0x28, %r8, %rdi
andl $0x1, %ecx
leaq 0x2581e(%rip), %r9      # 0x1e4223
movsbl (%rcx,%r9), %ecx
incl %r8d
movl (%rsi,%rdi), %esi
shrl $0x1f, %esi
leaq 0x27c71(%rip), %rdi     # 0x1e668b
movsbl (%rsi,%rdi), %r9d
movl 0x8(%rax,%rdx), %r11d
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x22b0
popq %rcx
popq %rdx
leal 0x1(%r15), %eax
jmp 0x1be9ce
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %r14
incl %r14d
jmp 0x1be7a7
cmpq $0x0, 0x18(%r15)
je 0x1becfc
xorl %r14d, %r14d
movl %r14d, %r14d
cmpq %r14, %rax
jbe 0x1becfc
movq 0x10(%r15), %rcx
imulq $0x28, %r14, %rbx
cmpl $0x0, 0xc(%rcx,%rbx)
je 0x1becf4
addq %rbx, %rcx
movl (%rcx), %r10d
testl %r10d, %r10d
movq %r14, 0x40(%rsp)
jns 0x1beb06
leal 0x1(%r14), %ebp
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
andl %r12d, %r10d
movq 0x8(%rsp), %r14
movq %r14, %rdi
leaq 0x2f819(%rip), %rsi     # 0x1ee2c6
movq 0x30(%rsp), %r15
movq %r15, %rdx
movl %ebp, %ecx
movq %r15, %r8
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq $0x0
callq 0x22b0
popq %rcx
popq %rdx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%rbx), %r10d
andl %r12d, %r10d
movq %r14, %rdi
movq 0x40(%rsp), %r14
leaq 0x2f800(%rip), %rsi     # 0x1ee2e9
movq %r15, %rdx
movl %ebp, %ecx
movq %r15, %r8
movq 0x20(%rsp), %r15
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq $0x0
callq 0x22b0
popq %rcx
popq %rdx
leal (%r14,%r14), %edx
movq 0x18(%r15), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movq %rdx, 0x48(%rsp)
movq (%rax,%rdx,8), %rax
movl %eax, %edx
shrq $0x20, %rax
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq %r14, 0x28(%rsp)
leal 0x1(%r14), %esi
movl %esi, 0x18(%rsp)
imulq $0x18, %rdx, %rdx
movq %rdx, 0x10(%rsp)
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %r12
addq $0x10, %r12
xorl %r14d, %r14d
cmpq %r14, 0x10(%rsp)
je 0x1bec00
movl -0x4(%r12,%r14), %r10d
testl %r10d, %r10d
js 0x1bebf7
movl -0x10(%r12,%r14), %r11d
movl -0x8(%r12,%r14), %eax
movq 0x10(%r15), %rcx
imulq $0x28, 0x28(%rsp), %rdx
movl (%rcx,%rdx), %edx
shrl $0x1f, %edx
leaq 0x27b00(%rip), %rsi     # 0x1e668b
movsbl (%rdx,%rsi), %r8d
movl %eax, %ebx
shrl %ebx
imulq $0x28, %rbx, %rdx
incl %ebx
movl (%rcx,%rdx), %ecx
shrl $0x1f, %ecx
movsbl (%rcx,%rsi), %r15d
andl $0x1, %eax
leaq 0x25674(%rip), %rcx     # 0x1e4223
movsbl (%rax,%rcx), %ebp
movzwl (%r12,%r14), %r13d
andl $0x3fff, %r13d          # imm = 0x3FFF
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
leaq 0x29814(%rip), %rsi     # 0x1e83e3
movq 0x38(%rsp), %rdx
movl 0x20(%rsp), %ecx
pushq $0x2b
popq %r9
xorl %eax, %eax
pushq %r13
pushq %r11
pushq %r10
pushq %rbp
pushq %r15
movq 0x50(%rsp), %r15
pushq %rbx
pushq %rdx
callq 0x22b0
addq $0x40, %rsp
addq $0x18, %r14
jmp 0x1beb51
movq 0x18(%r15), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movl 0x48(%rsp), %edx
movq 0x8(%rax,%rdx,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %rdx
movq %rdx, 0x10(%rsp)
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %r12
addq $0x10, %r12
imulq $0x28, 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
cmpq %r14, 0x10(%rsp)
je 0x1becec
movl -0x4(%r12,%r14), %r10d
testl %r10d, %r10d
js 0x1bece3
movl -0x10(%r12,%r14), %r11d
movl -0x8(%r12,%r14), %eax
movq 0x10(%r15), %rcx
movq 0x28(%rsp), %rdx
movl (%rcx,%rdx), %edx
shrl $0x1f, %edx
leaq 0x27a14(%rip), %rsi     # 0x1e668b
movsbl (%rdx,%rsi), %r8d
movl %eax, %ebx
shrl %ebx
imulq $0x28, %rbx, %rdx
incl %ebx
movl (%rcx,%rdx), %ecx
shrl $0x1f, %ecx
movsbl (%rcx,%rsi), %ebp
andl $0x1, %eax
leaq 0x25589(%rip), %rcx     # 0x1e4223
movsbl (%rax,%rcx), %r15d
movzwl (%r12,%r14), %r13d
andl $0x3fff, %r13d          # imm = 0x3FFF
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
leaq 0x29728(%rip), %rsi     # 0x1e83e3
movq 0x38(%rsp), %rdx
movl 0x20(%rsp), %ecx
pushq $0x2d
popq %r9
xorl %eax, %eax
pushq %r13
pushq %r11
pushq %r10
pushq %r15
movq 0x48(%rsp), %r15
pushq %rbp
pushq %rbx
pushq %rdx
callq 0x22b0
addq $0x40, %rsp
addq $0x18, %r14
jmp 0x1bec3e
movq (%r15), %rax
movq 0x40(%rsp), %r14
incl %r14d
jmp 0x1bea62
movq 0x38(%rsp), %rdi
callq 0x2220
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq