// File: /workspace/github_cpp_makefile_star2_O2/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 $0xb8, %rsp
movq %r8, 0x40(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x48(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movq 0xc0(%rsi), %rbp
movq 0x10(%rsi), %rax
movq (%rax), %rdi
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, %rbx
leaq 0x70(%rsp), %r13
leaq 0x90(%rsp), %r12
xorl %edx, %edx
movq %rbp, 0x38(%rsp)
movq %rax, 0x68(%rsp)
movq %r15, 0x60(%rsp)
movl %edx, %edx
movq (%rbp), %rax
cmpq %rdx, %rax
jbe 0x11bd91
movq 0x10(%rbp), %rsi
imulq $0x28, %rdx, %rcx
movl 0x10(%rsi,%rcx), %eax
testl %eax, %eax
je 0x11bd8a
movq %rdx, 0x28(%rsp)
addq %rcx, %rsi
xorl %edi, %edi
xorl %ebp, %ebp
movq %rsi, 0x10(%rsp)
movl %eax, %eax
cmpq %rax, %rdi
jae 0x11baba
movq 0x18(%rsi), %rax
movq %rdi, 0x8(%rsp)
movq (%rax,%rdi,8), %rsi
shrq $0x21, %rsi
subq $0x8, %rsp
movq %r14, %rdi
leaq 0x28(%rsp), %rdx
leaq 0x24(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x2c(%rsp), %r9
pushq $0x0
callq 0xf6ab5
addq $0x10, %rsp
movl 0x24(%rsp), %eax
movq 0x50(%rsp), %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x11ba3f
movq 0x10(%r14), %rsi
movq 0x10(%rsi), %rsi
movl (%rcx,%rdx,4), %edi
shrl %edi
imulq $0x28, %rdi, %r8
movl 0x10(%rsi,%r8), %esi
addq %rsi, %rbp
movb $0x1, (%rbx,%rdi)
incq %rdx
jmp 0x11ba18
movl 0x20(%rsp), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x11ba78
shrl %eax
cmpb $0x0, (%rbx,%rax)
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
jne 0x11ba82
movq 0x10(%r14), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rax, %rdx
movl 0x10(%rcx,%rdx), %ecx
addq %rcx, %rbp
movb $0x1, (%rbx,%rax)
jmp 0x11ba82
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x11baaf
shrl %eax
cmpb $0x0, (%rbx,%rax)
jne 0x11baaf
movq 0x10(%r14), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rax, %rdx
movl 0x10(%rcx,%rdx), %ecx
addq %rcx, %rbp
movb $0x1, (%rbx,%rax)
incq %rdi
movl 0x10(%rsi), %eax
jmp 0x11b9cb
movq 0x28(%rsp), %r9
incl %r9d
movl (%rsi), %eax
shrl $0x1f, %eax
leaq 0xcabbd(%rip), %rcx     # 0x1e668b
movsbl (%rax,%rcx), %r8d
movq %r13, %rdi
leaq 0xcc7fd(%rip), %rsi     # 0x1e82da
movq 0x40(%rsp), %rdx
movq %r9, 0x28(%rsp)
movl %r9d, %ecx
xorl %eax, %eax
callq 0x2050
movq %r15, %rdi
leaq 0xd2c7b(%rip), %rsi     # 0x1ee776
leaq 0x70(%rsp), %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x22b0
xorl %ecx, %ecx
movq 0x10(%rsp), %rdx
movl 0x10(%rdx), %eax
cmpq %rax, %rcx
jae 0x11bd7b
movq 0x18(%rdx), %rax
movq (%rax,%rcx,8), %rbp
shrq $0x21, %rbp
movq %rcx, %r15
leal 0x1(%rbp), %ecx
movq %r12, %rbx
movq %r12, %rdi
leaq 0xd2c4b(%rip), %rsi     # 0x1ee787
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %r15, 0x8(%rsp)
btq $0x20, (%rax,%r15,8)
movq 0x60(%rsp), %r15
leaq 0xc86bb(%rip), %rax     # 0x1e4223
adcq $0x0, %rax
movsbl (%rax), %ecx
cmpq 0x80(%r14), %rbp
leaq 0xd1d42(%rip), %rax     # 0x1ed8bf
adcq $0x0, %rax
movsbl (%rax), %r9d
movq %r15, %rdi
leaq 0xd2bff(%rip), %rsi     # 0x1ee78e
movq %r12, %rdx
movq %r13, %r8
xorl %eax, %eax
callq 0x22b0
subq $0x8, %rsp
movq %r14, %rdi
movq %rbp, %rsi
leaq 0xc8676(%rip), %rbp     # 0x1e4223
leaq 0x28(%rsp), %rdx
leaq 0x24(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x2c(%rsp), %r9
pushq $0x0
callq 0xf6ab5
popq %rax
popq %rcx
movl 0x20(%rsp), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x11bc51
movl %eax, %ecx
shrl %ecx
movq (%r14), %rdx
imulq $0x28, %rcx, %rsi
movl (%rdx,%rcx,4), %edx
incl %ecx
movq 0x10(%r14), %rdi
movq 0x10(%rdi), %rdi
movl (%rdi,%rsi), %esi
shrl $0x1f, %esi
leaq 0xcaa8e(%rip), %rdi     # 0x1e668b
movsbl (%rsi,%rdi), %r8d
andl $0x1, %eax
movsbl (%rax,%rbp), %r9d
movq 0x80(%r14), %rax
incq %rax
cmpq %rdx, %rax
leaq 0xd2bb0(%rip), %rax     # 0x1ee7ce
adcq $0x0, %rax
movsbl (%rax), %r10d
subq $0x8, %rsp
movq %r15, %rdi
leaq 0xd2b72(%rip), %rsi     # 0x1ee7a6
movq 0x50(%rsp), %rdx
xorl %eax, %eax
pushq %r10
pushq %rbx
leaq 0x88(%rsp), %r10
pushq %r10
callq 0x22b0
addq $0x20, %rsp
movl 0x1c(%rsp), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x11bcd1
movl %eax, %ecx
shrl %ecx
movq (%r14), %rdx
imulq $0x28, %rcx, %rsi
movl (%rdx,%rcx,4), %edx
incl %ecx
movq 0x10(%r14), %rdi
movq 0x10(%rdi), %rdi
movl (%rdi,%rsi), %esi
shrl $0x1f, %esi
leaq 0xcaa07(%rip), %rdi     # 0x1e668b
movsbl (%rsi,%rdi), %r8d
andl $0x1, %eax
movsbl (%rax,%rbp), %r9d
movq 0x80(%r14), %rax
incq %rax
cmpq %rdx, %rax
leaq 0xd2b29(%rip), %rax     # 0x1ee7ce
adcq $0x0, %rax
movsbl (%rax), %r10d
subq $0x8, %rsp
movq %r15, %rdi
leaq 0xd2b16(%rip), %rsi     # 0x1ee7d1
movq 0x50(%rsp), %rdx
xorl %eax, %eax
pushq %r10
pushq %r12
pushq %r13
callq 0x22b0
addq $0x20, %rsp
xorl %ebp, %ebp
movq 0x68(%rsp), %rbx
movl 0x24(%rsp), %eax
cmpq %rax, %rbp
jae 0x11bd6e
movq (%r14), %rax
movq 0x10(%r14), %rcx
movq 0x10(%rcx), %rdx
movq 0x50(%rsp), %rcx
movl (%rcx,%rbp,4), %esi
movl %esi, %ecx
shrl %ecx
imulq $0x28, %rcx, %rdi
movl (%rax,%rcx,4), %eax
incl %ecx
movl (%rdx,%rdi), %edx
shrl $0x1f, %edx
leaq 0xca979(%rip), %rdi     # 0x1e668b
movsbl (%rdx,%rdi), %r8d
andl $0x1, %esi
leaq 0xc8502(%rip), %rdx     # 0x1e4223
movsbl (%rsi,%rdx), %r9d
movq 0x80(%r14), %rdx
incq %rdx
cmpq %rax, %rdx
leaq 0xd2a94(%rip), %rax     # 0x1ee7ce
adcq $0x0, %rax
movsbl (%rax), %r10d
subq $0x8, %rsp
movq %r15, %rdi
leaq 0xd2aa9(%rip), %rsi     # 0x1ee7f9
movq 0x50(%rsp), %rdx
xorl %eax, %eax
pushq %r10
pushq %r12
pushq %r13
callq 0x22b0
addq $0x20, %rsp
incq %rbp
jmp 0x11bcd8
movq 0x8(%rsp), %rcx
incq %rcx
jmp 0x11bb0c
movq 0x38(%rsp), %rbp
movq 0x28(%rsp), %rdx
jmp 0x11b997
incl %edx
jmp 0x11b997
xorl %r13d, %r13d
movl %r13d, %r13d
cmpq %r13, %rax
jbe 0x11bfda
movq 0x10(%rbp), %rcx
imulq $0x28, %r13, %rdx
cmpl $0x0, 0xc(%rcx,%rdx)
je 0x11bfd2
addq %rdx, %rcx
cmpl $0x0, (%rcx)
movq %r13, 0x28(%rsp)
jns 0x11be17
leal 0x1(%r13), %ebp
movq %r15, %rdi
leaq 0xd24f8(%rip), %rsi     # 0x1ee2c6
movq 0x40(%rsp), %r13
movq %r13, %rdx
movl %ebp, %ecx
movq %r13, %r8
movl %ebp, %r9d
xorl %eax, %eax
pushq $0x0
pushq $0x0
callq 0x22b0
popq %rcx
popq %rdx
movq %r15, %rdi
leaq 0xd24f4(%rip), %rsi     # 0x1ee2e9
movq %r13, %rdx
movl %ebp, %ecx
movq %r13, %r8
movq 0x28(%rsp), %r13
movl %ebp, %r9d
movq 0x38(%rsp), %rbp
xorl %eax, %eax
pushq $0x0
pushq $0x0
callq 0x22b0
popq %rcx
popq %rdx
leal (,%r13,2), %edx
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movq %rdx, 0x58(%rsp)
movq (%rax,%rdx,8), %rax
movl %eax, %edx
shrq $0x20, %rax
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq %r13, 0x30(%rsp)
leal 0x1(%r13), %esi
movl %esi, 0x10(%rsp)
imulq $0x18, %rdx, %rdx
movq %rdx, 0x8(%rsp)
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %r12
addq $0xc, %r12
xorl %r13d, %r13d
cmpq %r13, 0x8(%rsp)
je 0x11bef9
cmpl $0x0, (%r12,%r13)
js 0x11bef0
movl -0x4(%r12,%r13), %eax
movq 0x10(%rbp), %rcx
imulq $0x28, 0x30(%rsp), %rdx
movl (%rcx,%rdx), %edx
shrl $0x1f, %edx
leaq 0xca7f7(%rip), %rsi     # 0x1e668b
movsbl (%rdx,%rsi), %r8d
movl %eax, %r10d
shrl %r10d
imulq $0x28, %r10, %rdx
incl %r10d
movl (%rcx,%rdx), %ecx
shrl $0x1f, %ecx
movsbl (%rcx,%rsi), %r11d
andl $0x1, %eax
leaq 0xc8368(%rip), %rcx     # 0x1e4223
movsbl (%rax,%rcx), %ebp
movq %r15, %rdi
leaq 0xd2385(%rip), %rsi     # 0x1ee24e
movq 0x40(%rsp), %rdx
movl 0x10(%rsp), %ecx
pushq $0x2b
popq %r9
xorl %eax, %eax
pushq $0x0
pushq $0x0
pushq %rbp
movq 0x50(%rsp), %rbp
pushq %r11
pushq %r10
pushq %rdx
callq 0x22b0
addq $0x30, %rsp
addq $0x18, %r13
jmp 0x11be66
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movl 0x58(%rsp), %edx
movq 0x8(%rax,%rdx,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %rdx
movq %rdx, 0x8(%rsp)
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %r12
addq $0xc, %r12
imulq $0x28, 0x30(%rsp), %rax
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
cmpq %r13, 0x8(%rsp)
je 0x11bfc9
cmpl $0x0, (%r12,%r13)
js 0x11bfc0
movl -0x4(%r12,%r13), %eax
movq 0x10(%rbp), %rcx
movq 0x30(%rsp), %rdx
movl (%rcx,%rdx), %edx
shrl $0x1f, %edx
leaq 0xca727(%rip), %rsi     # 0x1e668b
movsbl (%rdx,%rsi), %r8d
movl %eax, %r10d
shrl %r10d
imulq $0x28, %r10, %rdx
incl %r10d
movl (%rcx,%rdx), %ecx
shrl $0x1f, %ecx
movsbl (%rcx,%rsi), %r11d
andl $0x1, %eax
leaq 0xc8298(%rip), %rcx     # 0x1e4223
movsbl (%rax,%rcx), %ebp
movq %r15, %rdi
leaq 0xd22b5(%rip), %rsi     # 0x1ee24e
movq 0x40(%rsp), %rdx
movl 0x10(%rsp), %ecx
pushq $0x2d
popq %r9
xorl %eax, %eax
pushq $0x0
pushq $0x0
pushq %rbp
movq 0x50(%rsp), %rbp
pushq %r11
pushq %r10
pushq %rdx
callq 0x22b0
addq $0x30, %rsp
addq $0x18, %r13
jmp 0x11bf37
movq (%rbp), %rax
movq 0x28(%rsp), %r13
incl %r13d
jmp 0x11bd94
pushq $0x1
popq %r13
leaq 0xd283c(%rip), %rbp     # 0x1ee821
leal -0x1(%r13), %eax
movq 0x10(%r14), %rcx
cmpq %rax, (%rcx)
jbe 0x11c04e
cmpb $0x0, (%rbx,%rax)
jne 0x11c049
movq 0x10(%rcx), %rcx
imulq $0x28, %rax, %rdx
movl (%rcx,%rdx), %ecx
shrl $0x1f, %ecx
leaq 0xca67e(%rip), %rdx     # 0x1e668b
movsbl (%rcx,%rdx), %r8d
movq (%r14), %rcx
movq 0x80(%r14), %rdx
movl (%rcx,%rax,4), %eax
incq %rdx
cmpq %rax, %rdx
leaq 0xd27a2(%rip), %rax     # 0x1ee7ce
adcq $0x0, %rax
movsbl (%rax), %r9d
movq %r15, %rdi
movq %rbp, %rsi
movq 0x48(%rsp), %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x22b0
incl %r13d
jmp 0x11bfe5
movq %rbx, %rdi
callq 0x2220
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq