// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]yahs/sdict.c
// Function: write_segs_to_agp
void write_segs_to_agp(sd_seg_t *segs, uint32_t n, sd_aseq_t *aseq, sdict_t *sd, char *name, FILE *fo)
{
    uint64_t len;
    sd_seg_t seg;
    uint32_t i, j, t;
    len = 0;
    t = 0;
    if (!name) name = aseq? aseq->name : 0;
    if (!name) {
        fprintf(stderr, "[E::%s] sequence name required\n", __func__);
        exit(EXIT_FAILURE);
    } 
    if (aseq) {
        // with gap information
        for (i = 0, j = 0; i < n; ++i) {
            seg = segs[i];
            while (j < aseq->gn && aseq->gs[j] <= i) {
                // print gap
                write_agp_gap(fo, name, len + 1, len + aseq->gsize[j], ++t, aseq->gcomp[j], aseq->gsize[j], 
                        aseq->gtype[j], aseq->glink[j], aseq->gevid[j]);
                len += aseq->gsize[j];
                ++j;
            }
            write_agp_seq(fo, name, seg.b + 1, seg.b + seg.y, ++t, seg.t, sd->s[seg.c >> 1].name, 
                    seg.x + 1, seg.x + seg.y, seg.r);
            len += seg.y;
        }
        while (j < aseq->gn) {
            // print trailing gap
            write_agp_gap(fo, name, len + 1, len + aseq->gsize[j], ++t, aseq->gcomp[j], aseq->gsize[j], 
                    aseq->gtype[j], aseq->glink[j], aseq->gevid[j]);
            len += aseq->gsize[j];
            ++j;
        }
        if (len != aseq->len + aseq->gap) {
            fprintf(stderr, "[E::%s] sequence length conflict: %lu %lu\n", __func__, len, aseq->len + aseq->gap);
            //exit(EXIT_FAILURE);
        }
    } else {
        // no gap information provided
        // using default settings
        for (i = 0; i < n; ++i) {
            seg = segs[i];
            write_agp_seq(fo, name, len + 1, len + seg.y, ++t, seg.t, sd->s[seg.c >> 1].name, seg.x + 1, seg.x + seg.y, seg.r);
            /***
            fprintf(fo, "%s\t%lu\t%lu\t%d\t%s\t%s\t%u\t%u\t%s\n", 
                    name, len + 1, len + seg.y, ++t,
                    agp_component_type_val(DEFAULT_AGP_SEQ_COMPONENT_TYPE),
                    sd->s[seg.c >> 1].name, seg.x + 1, seg.x + seg.y,
                    seg.c & 1? agp_orientation_val(AGP_OT_MINUS) : agp_orientation_val(AGP_OT_PLUS));
            **/
            len += seg.y;
            if (i != n - 1) {
                write_agp_gap(fo, name, len + 1, len + DEFAULT_AGP_GAP_SIZE, ++t, DEFAULT_AGP_GAP_COMPONENT_TYPE, 
                        DEFAULT_AGP_GAP_SIZE, DEFAULT_AGP_GAP_TYPE, AGP_LG_YES, DEFAULT_AGP_LINKAGE_EVIDENCE);
                /***
                fprintf(fo, "%s\t%lu\t%lu\t%d\t%s\t%d\t%s\t%s\t%s\n", 
                        name, len + 1, len + DEFAULT_AGP_GAP_SIZE, ++t,
                        agp_component_type_val(DEFAULT_AGP_GAP_COMPONENT_TYPE), 
                        DEFAULT_AGP_GAP_SIZE,
                        agp_gap_type_val(DEFAULT_AGP_GAP_TYPE),
                        agp_linkage_val(AGP_LG_YES),
                        agp_linkage_evidence_val(DEFAULT_AGP_LINKAGE_EVIDENCE));
                **/
                len += DEFAULT_AGP_GAP_SIZE;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, 0x20(%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, %r13
movq %rdi, 0x50(%rsp)
testq %r8, %r8
jne 0x742a
testq %r13, %r13
je 0x7427
movq (%r13), %r8
jmp 0x742a
xorl %r8d, %r8d
testq %r8, %r8
je 0x7a2b
testq %r13, %r13
movq %r8, 0x10(%rsp)
je 0x770b
testl %esi, %esi
je 0x790a
movl %esi, %edi
xorl %edx, %edx
movl $0x0, 0x8(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %rdi, 0x60(%rsp)
leaq (%rdx,%rdx,2), %rax
shlq $0x4, %rax
movq 0x50(%rsp), %rcx
movq 0x10(%rcx,%rax), %rsi
movq %rsi, 0x68(%rsp)
movl 0x18(%rcx,%rax), %r10d
movl 0x1c(%rcx,%rax), %esi
movq %rsi, 0x70(%rsp)
movl 0x20(%rcx,%rax), %esi
movq %rsi, 0x38(%rsp)
movl 0x24(%rcx,%rax), %r9d
movl 0x28(%rcx,%rax), %r8d
cmpl 0x20(%r13), %r15d
movq %rdx, 0x30(%rsp)
jae 0x7592
movq %r10, 0x40(%rsp)
movq %r9, 0x48(%rsp)
movl %r8d, 0x28(%rsp)
movl 0x8(%rsp), %eax
movq %rax, 0x18(%rsp)
movl %r15d, 0x2c(%rsp)
movl %r15d, %r15d
leaq (,%r15,4), %r14
xorl %r12d, %r12d
movq 0x28(%r13), %rax
addq %r14, %rax
movl (%rax,%r12,4), %eax
cmpq %rax, %rdx
jb 0x756f
leaq 0x1(%rbp), %rdx
movq 0x30(%r13), %rax
addq %r14, %rax
movl (%rax,%r12,4), %eax
movq %rax, %rcx
addq %rbp, %rcx
movq 0x18(%rsp), %rsi
leal (%rsi,%r12), %r8d
incl %r8d
movq 0x38(%r13), %rsi
addq %r14, %rsi
movl (%rsi,%r12,4), %r9d
movq 0x40(%r13), %rsi
addq %r14, %rsi
movl (%rsi,%r12,4), %r10d
movq 0x48(%r13), %rsi
addq %r14, %rsi
movl (%rsi,%r12,4), %r11d
movq 0x50(%r13), %rsi
addq %r14, %rsi
movl (%rsi,%r12,4), %ebx
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0x7a30
movq 0x50(%rsp), %rdx
addq $0x20, %rsp
movq 0x30(%r13), %rax
addq %r14, %rax
movl (%rax,%r12,4), %eax
addq %rax, %rbp
incq %r12
leal (%r12,%r15), %eax
cmpl 0x20(%r13), %eax
jb 0x74d1
addl %r12d, 0x8(%rsp)
movl 0x2c(%rsp), %r15d
addl %r12d, %r15d
movq 0x10(%rsp), %rdx
movl 0x28(%rsp), %r8d
movq 0x48(%rsp), %r9
movq 0x40(%rsp), %r10
jmp 0x7597
movq 0x10(%rsp), %rdx
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
shrl %r10d
leaq (%r10,%r10,2), %rcx
movq (%rax,%rcx,8), %rsi
leal -0x2b609(%r9), %eax
cmpl $0x13, %eax
ja 0x75d0
leaq 0x2cee(%rip), %rcx      # 0xa2ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x339d(%rip), %rax      # 0xa96b
jmp 0x7622
leaq 0x3392(%rip), %rax      # 0xa969
cmpl $0x2b606, %r9d          # imm = 0x2B606
je 0x7622
jmp 0x79f1
leaq 0x3131(%rip), %rax      # 0xa71d
jmp 0x7622
leaq 0x3380(%rip), %rax      # 0xa975
jmp 0x7622
leaq 0x336f(%rip), %rax      # 0xa96d
jmp 0x7622
leaq 0x3114(%rip), %rax      # 0xa71b
jmp 0x7622
leaq 0x3363(%rip), %rax      # 0xa973
jmp 0x7622
leaq 0x3358(%rip), %rax      # 0xa971
jmp 0x7622
leaq 0x334d(%rip), %rax      # 0xa96f
cmpl $0x2b5e3, %r8d          # imm = 0x2B5E3
jg 0x7657
leaq 0x3199(%rip), %rbx      # 0xa7cb
cmpl $0x2b5d0, %r8d          # imm = 0x2B5D0
movl 0x8(%rsp), %r9d
je 0x7694
cmpl $0x2b5d2, %r8d          # imm = 0x2B5D2
je 0x7684
cmpl $0x2b5d5, %r8d          # imm = 0x2B5D5
je 0x767b
jmp 0x79de
cmpl $0x2b5e4, %r8d          # imm = 0x2B5E4
movl 0x8(%rsp), %r9d
je 0x767b
cmpl $0x5978d4, %r8d         # imm = 0x5978D4
je 0x768d
cmpl $0x7ca1b285, %r8d       # imm = 0x7CA1B285
jne 0x79de
leaq 0x314b(%rip), %rbx      # 0xa7cd
jmp 0x7694
leaq 0x2b11(%rip), %rbx      # 0xa19c
jmp 0x7694
leaq 0x313b(%rip), %rbx      # 0xa7cf
movq %rbx, 0x18(%rsp)
movq 0x68(%rsp), %r8
leaq 0x1(%r8), %rcx
movq 0x38(%rsp), %r12
addq %r12, %r8
incl %r9d
movq 0x70(%rsp), %r10
leal (%r12,%r10), %r14d
incl %r10d
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
movq %rsi, %r11
leaq 0x368b(%rip), %rsi      # 0xad57
movl %r9d, 0x10(%rsp)
movq %rax, %rbx
xorl %eax, %eax
pushq 0x20(%rsp)
pushq %r14
pushq %r10
pushq %r11
pushq %rbx
callq 0x2200
movq 0x90(%rsp), %rdi
movq 0x60(%rsp), %rdx
addq $0x30, %rsp
addq %r12, %rbp
incq %rdx
cmpq %rdi, %rdx
jne 0x745f
jmp 0x7917
testl %esi, %esi
je 0x799f
leal -0x1(%rsi), %eax
movl %esi, %ecx
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x8(%rsp)
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rax
movq %rax, 0x38(%rsp)
xorl %ebx, %ebx
xorl %r8d, %r8d
xorl %r12d, %r12d
movq 0x10(%rsp), %r15
movq 0x50(%rsp), %rdx
movl 0x18(%rdx,%rbx), %ecx
movl 0x1c(%rdx,%rbx), %r10d
movl 0x20(%rdx,%rbx), %esi
movl 0x24(%rdx,%rbx), %eax
movl 0x28(%rdx,%rbx), %edx
movq 0x58(%rsp), %rdi
movq 0x8(%rdi), %rdi
shrl %ecx
leaq (%rcx,%rcx,2), %rcx
movq (%rdi,%rcx,8), %r9
leal -0x2b609(%rax), %ecx
cmpl $0x13, %ecx
ja 0x7790
leaq 0x2b7e(%rip), %rdi      # 0xa2fc
movslq (%rdi,%rcx,4), %rcx
addq %rdi, %rcx
jmpq *%rcx
leaq 0x31dd(%rip), %rcx      # 0xa96b
jmp 0x77e0
leaq 0x31d2(%rip), %rcx      # 0xa969
cmpl $0x2b606, %eax          # imm = 0x2B606
je 0x77e0
jmp 0x7a14
leaq 0x2f73(%rip), %rcx      # 0xa71d
jmp 0x77e0
leaq 0x31c2(%rip), %rcx      # 0xa975
jmp 0x77e0
leaq 0x31b1(%rip), %rcx      # 0xa96d
jmp 0x77e0
leaq 0x2f56(%rip), %rcx      # 0xa71b
jmp 0x77e0
leaq 0x31a5(%rip), %rcx      # 0xa973
jmp 0x77e0
leaq 0x319a(%rip), %rcx      # 0xa971
jmp 0x77e0
leaq 0x318f(%rip), %rcx      # 0xa96f
cmpl $0x2b5e3, %edx          # imm = 0x2B5E3
jg 0x780c
leaq 0x2fdc(%rip), %r14      # 0xa7cb
cmpl $0x2b5d0, %edx          # imm = 0x2B5D0
je 0x7841
cmpl $0x2b5d2, %edx          # imm = 0x2B5D2
je 0x7831
cmpl $0x2b5d5, %edx          # imm = 0x2B5D5
je 0x7828
jmp 0x7a04
cmpl $0x2b5e4, %edx          # imm = 0x2B5E4
je 0x7828
cmpl $0x5978d4, %edx         # imm = 0x5978D4
je 0x783a
cmpl $0x7ca1b285, %edx       # imm = 0x7CA1B285
jne 0x7a04
leaq 0x2f9e(%rip), %r14      # 0xa7cd
jmp 0x7841
leaq 0x2964(%rip), %r14      # 0xa19c
jmp 0x7841
leaq 0x2f8e(%rip), %r14      # 0xa7cf
movq %rcx, 0x30(%rsp)
leaq 0x1(%r12), %rcx
addq %rsi, %r12
leal 0x1(%r8), %ebp
leal (%rsi,%r10), %r11d
incl %r10d
subq $0x8, %rsp
movq %r8, 0x20(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x34e9(%rip), %rsi      # 0xad57
movq %r15, %rdx
movq %r12, %r8
movq %r9, %r13
movl %ebp, %r9d
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
pushq %r13
pushq 0x58(%rsp)
callq 0x2200
addq $0x30, %rsp
cmpq %rbx, 0x8(%rsp)
je 0x78f3
leaq 0x1(%r12), %rdx
movslq 0x698c(%rip), %rax      # 0xe230
movq %rax, %rcx
addq %r12, %rcx
movq 0x18(%rsp), %r13
addl $0x2, %r13d
movl 0x696a(%rip), %r9d      # 0xe224
movl 0x6967(%rip), %r10d     # 0xe228
movl 0x6964(%rip), %r11d     # 0xe22c
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %r8d
pushq %r11
pushq $0xb88c316              # imm = 0xB88C316
pushq %r10
pushq %rax
callq 0x7a30
addq $0x20, %rsp
movslq 0x6943(%rip), %rax      # 0xe230
addq %rax, %r12
movl %r13d, %ebp
addq $0x30, %rbx
movl %ebp, %r8d
cmpq %rbx, 0x38(%rsp)
jne 0x773f
jmp 0x799f
xorl %ebp, %ebp
xorl %r15d, %r15d
movl $0x0, 0x8(%rsp)
cmpl 0x20(%r13), %r15d
jae 0x7992
movl %r15d, %ebx
movl 0x8(%rsp), %r15d
incl %r15d
movq 0x10(%rsp), %r12
leaq 0x1(%rbp), %rdx
movq 0x30(%r13), %rax
movq 0x38(%r13), %rsi
movl (%rax,%rbx,4), %eax
movq %rax, %rcx
addq %rbp, %rcx
movl (%rsi,%rbx,4), %r9d
movq 0x40(%r13), %rsi
movl (%rsi,%rbx,4), %r10d
movq 0x48(%r13), %rsi
movl (%rsi,%rbx,4), %r11d
movq 0x50(%r13), %rsi
movl (%rsi,%rbx,4), %r14d
movq 0x20(%rsp), %rdi
movq %r12, %rsi
movl %r15d, %r8d
pushq %r14
pushq %r11
pushq %r10
pushq %rax
callq 0x7a30
addq $0x20, %rsp
movq 0x30(%r13), %rax
movl (%rax,%rbx,4), %eax
addq %rax, %rbp
incq %rbx
movl 0x20(%r13), %eax
incl %r15d
cmpq %rax, %rbx
jb 0x792d
movq 0x10(%r13), %r8
addq 0x8(%r13), %r8
cmpq %r8, %rbp
jne 0x79ae
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x663b(%rip), %rax      # 0xdff0
movq (%rax), %rdi
leaq 0x2ec9(%rip), %rsi      # 0xa888
leaq 0x2eb0(%rip), %rdx      # 0xa876
movq %rbp, %rcx
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2200
leaq 0x3390(%rip), %rdi      # 0xad75
leaq 0x33b0(%rip), %rsi      # 0xad9c
movl %r8d, %edx
jmp 0x7a24
leaq 0x33b8(%rip), %rdi      # 0xadb0
leaq 0x33db(%rip), %rsi      # 0xadda
movl %r9d, %edx
jmp 0x7a24
leaq 0x336a(%rip), %rdi      # 0xad75
leaq 0x338a(%rip), %rsi      # 0xad9c
jmp 0x7a24
leaq 0x3395(%rip), %rdi      # 0xadb0
leaq 0x33b8(%rip), %rsi      # 0xadda
movl %eax, %edx
xorl %eax, %eax
callq 0x8da6
callq 0x2780