// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: prt_bubble_gfa_adv(_IO_FILE*, bubble_type*, char const*, char const*, char const*)
void prt_bubble_gfa_adv(FILE *fp, bubble_type *bub, const char* utg_pre, const char* bub_pre, const char* chain_pre)
{
    uint32_t i, k, m, *a, n, beg, sink, x; ma_utg_t *p; uint64_t occ;
    ma_ug_t *b_ug = bub->b_ug; char name[32], bname[32]; uint8_t *f; CALLOC(f, bub->ug->u.n);
    for (i = 0; i < b_ug->u.n; i++) {
        p = &b_ug->u.a[i];
        if(p->n == 0) continue;
        for (k = occ = 0; k < p->n; k++){
            x = p->a[k]>>33;
            get_bubbles(bub, x, &beg, &sink, &a, &n, NULL);

            for (m = 0; m < n; m++) {
                occ += bub->ug->u.a[a[m]>>1].n; f[a[m]>>1] = 1;
            }
            if(beg != (uint32_t)-1 && f[beg>>1] == 0) {
                occ += bub->ug->u.a[beg>>1].n; f[beg>>1] = 1;
            }
            if(sink != (uint32_t)-1 && f[sink>>1] == 0) {
                occ += bub->ug->u.a[sink>>1].n; f[sink>>1] = 1;
            }
        }

        sprintf(name, "%s%.6d%c", chain_pre, i + 1, "lc"[p->circ]);
        fprintf(fp, "S\t%s\t*\tLN:i:%lu\n", name, occ);
        for (k = 0; k < p->n; k++) {
            x = p->a[k]>>33;
            sprintf(bname, "%s%.6d", bub_pre, x + 1);
            fprintf(fp, "B\t%s\t%c\tcid:i:%s\tsm:%c\n", bname, "+-"[(p->a[k]>>32)&1], name, "01"[x<bub->f_bub]);

            get_bubbles(bub, x, &beg, &sink, &a, &n, NULL);
            if(beg != (uint32_t)-1) {
                fprintf(fp, "U\t%s%.6d%c\t%c\tcid:i:%s\tbid:b:%s\thom:%c\n", 
                utg_pre, (beg>>1)+1, "lc"[bub->ug->u.a[(beg>>1)].circ], "+-"[beg&1], name, bname, "10"[IF_HOM((beg>>1), *bub)]);
            }

            if(sink != (uint32_t)-1) {
                fprintf(fp, "U\t%s%.6d%c\t%c\tcid:i:%s\tbid:s:%s\thom:%c\n", 
                utg_pre, (sink>>1)+1, "lc"[bub->ug->u.a[(sink>>1)].circ], "+-"[sink&1], name, bname, "10"[IF_HOM((sink>>1), *bub)]);
            }
            for (m = 0; m < n; m++) {
                occ += bub->ug->u.a[a[m]>>1].n;
                fprintf(fp, "U\t%s%.6d%c\t%c\tcid:i:%s\tbid:c:%s\thom:%c\n", 
                utg_pre, (a[m]>>1)+1, "lc"[bub->ug->u.a[(a[m]>>1)].circ], "+-"[a[m]&1], name, bname, "10"[IF_HOM((a[m]>>1), *bub)]);
            }
        }
    }

    asg_arc_t* au = NULL;
    uint32_t nu, u, v, j;
    for (i = 0; i < b_ug->u.n; ++i) {
        if(b_ug->u.a[i].m == 0) continue;
        if(b_ug->u.a[i].circ)
        {
            fprintf(fp, "L\t%s%.6dc\t+\t%s%.6dc\t+\t%dM\tL1:i:%d\n", 
            chain_pre, i+1, chain_pre, i+1, 0, 0);
            fprintf(fp, "L\t%s%.6dc\t-\t%s%.6dc\t-\t%dM\tL1:i:%d\n", 
            chain_pre, i+1, chain_pre, i+1, 0, 0);
        } 
        u = i<<1;
        au = asg_arc_a(b_ug->g, u);
        nu = asg_arc_n(b_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\n", 
            chain_pre, (u>>1)+1, "lc"[b_ug->u.a[u>>1].circ], "+-"[u&1],
            chain_pre, (v>>1)+1, "lc"[b_ug->u.a[v>>1].circ], "+-"[v&1], 0, 0);
        }


        u = (i<<1) + 1;
        au = asg_arc_a(b_ug->g, u);
        nu = asg_arc_n(b_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\n", 
            chain_pre, (u>>1)+1, "lc"[b_ug->u.a[u>>1].circ], "+-"[u&1],
            chain_pre, (v>>1)+1, "lc"[b_ug->u.a[v>>1].circ], "+-"[v&1], 0, 0);
        }
    }
    
    for (i = 0; i < bub->ug->u.n; i++) {
        if(f[i]) continue;
        fprintf(fp, "U\t%s%.6d%c\t+\tcid:i:*\tbid:c:*\thom:%c\n", 
                utg_pre, i+1, "lc"[bub->ug->u.a[i].circ], "10"[IF_HOM(i, *bub)]);
    }
    free(f);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r8, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movq 0xc0(%rsi), %rbx
movq 0x10(%rsi), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x2120
movq %rax, %r14
cmpq $0x0, (%rbx)
je 0x161d33
movq %rbx, %rdi
xorl %eax, %eax
xorl %esi, %esi
movq %rbx, 0x20(%rsp)
movq %r14, 0x50(%rsp)
movq %r12, 0x58(%rsp)
movq 0x10(%rdi), %rcx
leaq (%rax,%rax,4), %rdx
movl 0x10(%rcx,%rdx,8), %eax
testq %rax, %rax
je 0x161a88
movl %esi, 0x4(%rsp)
leaq (%rcx,%rdx,8), %rcx
movq %rcx, 0x8(%rsp)
movq 0x18(%rcx), %rcx
movq 0x28(%r12), %rdx
movq 0x40(%r12), %rsi
xorl %edi, %edi
xorl %ebp, %ebp
movq (%rcx,%rdi,8), %r9
shrq $0x21, %r9
movl (%rsi,%r9,4), %r8d
movl 0x4(%rsi,%r9,4), %r11d
subl %r8d, %r11d
addl $-0x2, %r11d
je 0x1616c3
leaq (%rdx,%r8,4), %r9
movq 0x10(%r12), %r10
movq 0x10(%r10), %r10
movl %r11d, %r11d
xorl %ebx, %ebx
movl 0x8(%r9,%rbx,4), %r15d
shrl %r15d
leaq (%r15,%r15,4), %r13
movl 0x10(%r10,%r13,8), %r13d
addq %r13, %rbp
movb $0x1, (%r14,%r15)
incq %rbx
cmpq %rbx, %r11
jne 0x1616a2
movl (%rdx,%r8,4), %r9d
cmpl $-0x1, %r9d
je 0x1616f1
shrl %r9d
cmpb $0x0, (%r14,%r9)
jne 0x1616f1
movq 0x10(%r12), %r10
movq 0x10(%r10), %r10
leaq (%r9,%r9,4), %r11
movl 0x10(%r10,%r11,8), %r10d
addq %r10, %rbp
movb $0x1, (%r14,%r9)
incl %r8d
movl (%rdx,%r8,4), %r8d
cmpl $-0x1, %r8d
je 0x161722
shrl %r8d
cmpb $0x0, (%r14,%r8)
jne 0x161722
movq 0x10(%r12), %r9
movq 0x10(%r9), %r9
leaq (%r8,%r8,4), %r10
movl 0x10(%r9,%r10,8), %r9d
addq %r9, %rbp
movb $0x1, (%r14,%r8)
incq %rdi
cmpq %rax, %rdi
jne 0x161676
movl 0x4(%rsp), %r9d
incl %r9d
movq 0x8(%rsp), %r15
movl (%r15), %eax
shrl $0x1f, %eax
leaq 0xd2ff3(%rip), %rcx     # 0x23473b
movsbl (%rax,%rcx), %r8d
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0xd4c7e(%rip), %rsi     # 0x2363da
movq 0x40(%rsp), %rdx
movl %r9d, 0x4(%rsp)
movl %r9d, %ecx
xorl %eax, %eax
callq 0x2050
movq 0x18(%rsp), %rdi
leaq 0xdb10a(%rip), %rsi     # 0x23c886
movq %rbx, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x22b0
cmpl $0x0, 0x10(%r15)
je 0x161a8c
movq %r15, %r8
xorl %ebp, %ebp
movq %r12, %r14
leaq 0xd0b30(%rip), %r12     # 0x2322d3
leaq 0x80(%rsp), %rbx
movq 0x18(%r8), %rax
movq (%rax,%rbp,8), %r15
shrq $0x21, %r15
leal 0x1(%r15), %ecx
movq %rbx, %rdi
leaq 0xdb0d2(%rip), %rsi     # 0x23c897
movq 0x48(%rsp), %rdx
xorl %eax, %eax
movq %r8, %r13
callq 0x2050
movq 0x18(%r13), %rax
movq %rbp, 0x28(%rsp)
btq $0x20, (%rax,%rbp,8)
movq %r12, %rax
adcq $0x0, %rax
movsbl (%rax), %ecx
cmpq 0x80(%r14), %r15
leaq 0xda1d4(%rip), %rax     # 0x23b9cf
adcq $0x0, %rax
movsbl (%rax), %r9d
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
leaq 0xdb08c(%rip), %rsi     # 0x23c89e
movq %rbx, %rdx
leaq 0x60(%rsp), %r12
movq %r12, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x28(%r14), %rdx
movq 0x40(%r14), %rax
movq %rbx, %r11
movl (%rax,%r15,4), %ebx
movl 0x4(%rax,%r15,4), %r13d
movl (%rdx,%rbx,4), %eax
leal 0x1(%rbx), %ecx
movq %rdx, 0x10(%rsp)
movl (%rdx,%rcx,4), %r15d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x1618ca
movl %eax, %ecx
shrl %ecx
movq (%r14), %rdx
leaq (%rcx,%rcx,4), %rsi
movl (%rdx,%rcx,4), %edx
incl %ecx
movq 0x10(%r14), %rdi
movq 0x10(%rdi), %rdi
movl (%rdi,%rsi,8), %esi
shrl $0x1f, %esi
leaq 0xd2ec5(%rip), %rdi     # 0x23473b
movsbl (%rsi,%rdi), %r8d
andl $0x1, %eax
leaq 0xd0a4e(%rip), %rsi     # 0x2322d3
movsbl (%rax,%rsi), %r9d
movq 0x80(%r14), %rax
incq %rax
cmpq %rdx, %rax
leaq 0xdb040(%rip), %rax     # 0x23c8de
adcq $0x0, %rax
movsbl (%rax), %r10d
subq $0x8, %rsp
movq %rbp, %rdi
leaq 0xdb002(%rip), %rsi     # 0x23c8b6
movq 0x40(%rsp), %rdx
xorl %eax, %eax
pushq %r10
pushq %r11
pushq %r12
callq 0x22b0
addq $0x20, %rsp
cmpl $-0x1, %r15d
je 0x16195e
movl %r15d, %eax
shrl %eax
movq (%r14), %rcx
leaq (%rax,%rax,4), %rdx
movl (%rcx,%rax,4), %esi
movl %eax, %ecx
incl %ecx
movq 0x10(%r14), %rax
movq 0x10(%rax), %rax
movl (%rax,%rdx,8), %eax
shrl $0x1f, %eax
leaq 0xd2e3f(%rip), %rdx     # 0x23473b
movsbl (%rax,%rdx), %r8d
andl $0x1, %r15d
leaq 0xd09c7(%rip), %rax     # 0x2322d3
movsbl (%r15,%rax), %r9d
movq 0x80(%r14), %rax
incq %rax
cmpq %rsi, %rax
leaq 0xdafb9(%rip), %rax     # 0x23c8de
adcq $0x0, %rax
movsbl (%rax), %r10d
subq $0x8, %rsp
movq %rbp, %rdi
leaq 0xdafa6(%rip), %rsi     # 0x23c8e1
movq 0x40(%rsp), %rdx
xorl %eax, %eax
pushq %r10
leaq 0x90(%rsp), %r10
pushq %r10
leaq 0x78(%rsp), %r10
pushq %r10
callq 0x22b0
addq $0x20, %rsp
subl %ebx, %r13d
addl $-0x2, %r13d
movq %r14, %r15
leaq 0xd2dcc(%rip), %r8      # 0x23473b
leaq 0xd095d(%rip), %r9      # 0x2322d3
leaq 0x60(%rsp), %r14
leaq 0xdaf5c(%rip), %r10     # 0x23c8de
leaq 0x80(%rsp), %r11
leaq 0xdaf78(%rip), %rsi     # 0x23c909
je 0x161a56
movq 0x10(%rsp), %rax
leaq (%rax,%rbx,4), %rax
movq %rax, 0x10(%rsp)
movl %r13d, %eax
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
movq (%r15), %rax
movq 0x10(%r15), %rcx
movq 0x10(%rcx), %rdx
movq 0x10(%rsp), %rcx
movl 0x8(%rcx,%r13,4), %r12d
movl %r12d, %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rdi
movl (%rax,%rcx,4), %eax
incl %ecx
movl (%rdx,%rdi,8), %edx
shrl $0x1f, %edx
movq %r8, %rbp
movsbl (%rdx,%r8), %r8d
andl $0x1, %r12d
movq %r9, %rbx
movsbl (%r12,%r9), %r9d
movq 0x80(%r15), %rdx
incq %rdx
cmpq %rax, %rdx
movq %r10, %rax
adcq $0x0, %rax
movsbl (%rax), %r10d
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
movq 0x40(%rsp), %rdx
xorl %eax, %eax
pushq %r10
pushq %r11
pushq %r14
movq %rsi, %r15
movq %r14, %r12
movq %r11, %r14
callq 0x22b0
movq %rbp, %r8
movq %r14, %r11
movq %r12, %r14
movq %r15, %rsi
leaq 0xdaea2(%rip), %r10     # 0x23c8de
movq 0x78(%rsp), %r15
movq %rbx, %r9
addq $0x20, %rsp
incq %r13
cmpq %r13, 0x30(%rsp)
jne 0x1619b0
movq 0x28(%rsp), %rbp
incq %rbp
movq 0x8(%rsp), %r8
movl 0x10(%r8), %eax
cmpq %rax, %rbp
movq %r15, %r14
movq %r9, %r12
movq %r11, %rbx
jb 0x1617ab
movq 0x20(%rsp), %rdi
movq %r14, %r12
movq 0x50(%rsp), %r14
jmp 0x161a91
incl %esi
jmp 0x161a95
movq 0x20(%rsp), %rdi
movl 0x4(%rsp), %esi
movl %esi, %eax
movq (%rdi), %rcx
cmpq %rax, %rcx
ja 0x161642
testq %rcx, %rcx
je 0x161d33
xorl %eax, %eax
xorl %ecx, %ecx
movq %rcx, 0x8(%rsp)
movq 0x10(%rdi), %rcx
leaq (%rax,%rax,4), %rax
cmpl $0x0, 0xc(%rcx,%rax,8)
je 0x161d20
leaq (%rcx,%rax,8), %rax
cmpl $0x0, (%rax)
jns 0x161b33
movq 0x8(%rsp), %rax
leal 0x1(%rax), %ebp
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
leaq 0xda8ee(%rip), %rsi     # 0x23c3d6
movq 0x40(%rsp), %r15
movq %r15, %rdx
movl %ebp, %ecx
movq %r15, %r8
movl %ebp, %r9d
xorl %eax, %eax
xorl %r13d, %r13d
pushq %r13
pushq %r13
callq 0x22b0
addq $0x10, %rsp
movq %rbx, %rdi
leaq 0xda8e5(%rip), %rsi     # 0x23c3f9
movq %r15, %rdx
movl %ebp, %ecx
movq %r15, %r8
movl %ebp, %r9d
xorl %eax, %eax
pushq %r13
pushq %r13
callq 0x22b0
movq 0x30(%rsp), %rdi
addq $0x10, %rsp
movq 0x8(%rsp), %rsi
leal (%rsi,%rsi), %r8d
movq 0x18(%rdi), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%r8,8), %rdx
testl %edx, %edx
je 0x161c3b
movq %r8, 0x48(%rsp)
movq %rdx, %rcx
shrq $0x20, %rcx
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %rsi, 0x30(%rsp)
incl %esi
movl %esi, 0x28(%rsp)
movl %edx, %edx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rbx
addq $0xc, %rbx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
cmpl $0x0, (%rbx,%rbp)
js 0x161c1b
movl -0x4(%rbx,%rbp), %eax
movq 0x10(%rdi), %rcx
movq 0x30(%rsp), %rdx
leaq (%rdx,%rdx,4), %rdx
movl (%rcx,%rdx,8), %edx
shrl $0x1f, %edx
leaq 0xd2b85(%rip), %rsi     # 0x23473b
movsbl (%rdx,%rsi), %r8d
movl %eax, %r10d
shrl %r10d
leaq (%r10,%r10,4), %rdx
incl %r10d
movl (%rcx,%rdx,8), %ecx
shrl $0x1f, %ecx
movsbl (%rcx,%rsi), %r11d
andl $0x1, %eax
leaq 0xd06f6(%rip), %rcx     # 0x2322d3
movsbl (%rax,%rcx), %r15d
movq 0x18(%rsp), %rdi
leaq 0xda770(%rip), %rsi     # 0x23c35e
movq 0x40(%rsp), %rdx
movl 0x28(%rsp), %ecx
movl $0x2b, %r9d
xorl %eax, %eax
xorl %r13d, %r13d
pushq %r13
pushq %r13
pushq %r15
pushq %r11
pushq %r10
pushq %rdx
callq 0x22b0
movq 0x50(%rsp), %rdi
addq $0x30, %rsp
addq $0x18, %rbp
cmpq %rbp, 0x10(%rsp)
jne 0x161b8e
movq 0x18(%rdi), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq 0x48(%rsp), %r8
movl %r8d, %edx
movq 0x8(%rcx,%rdx,8), %rcx
testl %ecx, %ecx
je 0x161d20
movq %rcx, %rdx
shrq $0x20, %rdx
movq 0x8(%rsp), %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leal 0x1(%rsi), %r8d
movl %r8d, 0x30(%rsp)
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rbx
addq $0xc, %rbx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rax
movq %rax, 0x10(%rsp)
leaq (%rsi,%rsi,4), %rax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
cmpl $0x0, (%rbx,%rbp)
js 0x161d11
movl -0x4(%rbx,%rbp), %eax
movq 0x10(%rdi), %rcx
movq 0x28(%rsp), %rdx
movl (%rcx,%rdx,8), %edx
shrl $0x1f, %edx
leaq 0xd2a8f(%rip), %rsi     # 0x23473b
movsbl (%rdx,%rsi), %r8d
movl %eax, %r10d
shrl %r10d
leaq (%r10,%r10,4), %rdx
incl %r10d
movl (%rcx,%rdx,8), %ecx
shrl $0x1f, %ecx
movsbl (%rcx,%rsi), %r11d
andl $0x1, %eax
leaq 0xd0600(%rip), %rcx     # 0x2322d3
movsbl (%rax,%rcx), %r13d
movq 0x18(%rsp), %rdi
leaq 0xda67a(%rip), %rsi     # 0x23c35e
movq 0x40(%rsp), %rdx
movl 0x30(%rsp), %ecx
movl $0x2d, %r9d
xorl %eax, %eax
xorl %r15d, %r15d
pushq %r15
pushq %r15
pushq %r13
pushq %r11
pushq %r10
pushq %rdx
callq 0x22b0
movq 0x50(%rsp), %rdi
addq $0x30, %rsp
addq $0x18, %rbp
cmpq %rbp, 0x10(%rsp)
jne 0x161c8c
movq 0x8(%rsp), %rcx
incl %ecx
movq %rcx, %rax
cmpq %rcx, (%rdi)
ja 0x161ab0
movq 0x10(%r12), %rax
movq (%rax), %rcx
testq %rcx, %rcx
movq 0x38(%rsp), %rdx
je 0x161dc2
movl $0x1, %ebp
leaq 0xd29ea(%rip), %rbx     # 0x23473b
leaq 0xdab86(%rip), %r15     # 0x23c8de
leaq 0xdabd2(%rip), %r13     # 0x23c931
xorl %esi, %esi
cmpb $0x0, (%r14,%rsi)
jne 0x161db9
movq 0x10(%rax), %rax
leaq (%rsi,%rsi,4), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
movsbl (%rax,%rbx), %r8d
movq (%r12), %rax
movq 0x80(%r12), %rcx
movl (%rax,%rsi,4), %eax
incq %rcx
cmpq %rax, %rcx
movq %r15, %rax
adcq $0x0, %rax
movsbl (%rax), %r9d
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x22b0
movq 0x38(%rsp), %rdx
movq 0x10(%r12), %rax
movq (%rax), %rcx
movl %ebp, %esi
incl %ebp
cmpq %rsi, %rcx
ja 0x161d61
movq %r14, %rdi
callq 0x2220
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq