// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, %r13
movq %rdi, 0x50(%rsp)
movq %r8, 0x20(%rsp)
testq %r8, %r8
je 0x77b0
testq %r13, %r13
jne 0x77cb
testl %esi, %esi
je 0x7b1d
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, 0x30(%rsp)
xorl %ebx, %ebx
xorl %r8d, %r8d
xorl %r12d, %r12d
movq 0x20(%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 0x7636
leaq 0x2c88(%rip), %rdi      # 0xa2ac
movslq (%rdi,%rcx,4), %rcx
addq %rdi, %rcx
jmpq *%rcx
leaq 0x3339(%rip), %rcx      # 0xa96d
jmp 0x7686
leaq 0x332e(%rip), %rcx      # 0xa96b
cmpl $0x2b606, %eax          # imm = 0x2B606
je 0x7686
jmp 0x7b7f
leaq 0x30cd(%rip), %rcx      # 0xa71d
jmp 0x7686
leaq 0x331e(%rip), %rcx      # 0xa977
jmp 0x7686
leaq 0x330d(%rip), %rcx      # 0xa96f
jmp 0x7686
leaq 0x30b0(%rip), %rcx      # 0xa71b
jmp 0x7686
leaq 0x3301(%rip), %rcx      # 0xa975
jmp 0x7686
leaq 0x32f6(%rip), %rcx      # 0xa973
jmp 0x7686
leaq 0x32eb(%rip), %rcx      # 0xa971
cmpl $0x2b5e3, %edx          # imm = 0x2B5E3
jg 0x76b2
leaq 0x3136(%rip), %r14      # 0xa7cb
cmpl $0x2b5d0, %edx          # imm = 0x2B5D0
je 0x76e7
cmpl $0x2b5d2, %edx          # imm = 0x2B5D2
je 0x76d7
cmpl $0x2b5d5, %edx          # imm = 0x2B5D5
je 0x76ce
jmp 0x7b5c
cmpl $0x2b5e4, %edx          # imm = 0x2B5E4
je 0x76ce
cmpl $0x5978d4, %edx         # imm = 0x5978D4
je 0x76e0
cmpl $0x7ca1b285, %edx       # imm = 0x7CA1B285
jne 0x7b5c
leaq 0x30f8(%rip), %r14      # 0xa7cd
jmp 0x76e7
leaq 0x30f4(%rip), %r14      # 0xa7d2
jmp 0x76e7
leaq 0x30e8(%rip), %r14      # 0xa7cf
movq %rcx, 0x28(%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 0x18(%rsp), %rdi
leaq 0x3645(%rip), %rsi      # 0xad59
movq %r15, %rdx
movq %r12, %r8
movq %r9, %r13
movl %ebp, %r9d
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
pushq %r13
pushq 0x50(%rsp)
callq 0x2200
addq $0x30, %rsp
cmpq %rbx, 0x8(%rsp)
je 0x7799
leaq 0x1(%r12), %rdx
movslq 0x6ae6(%rip), %rax      # 0xe230
movq %rax, %rcx
addq %r12, %rcx
movq 0x18(%rsp), %r13
addl $0x2, %r13d
movl 0x6ac4(%rip), %r9d      # 0xe224
movl 0x6ac1(%rip), %r10d     # 0xe228
movl 0x6abe(%rip), %r11d     # 0xe22c
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %r8d
pushq %r11
pushq $0xb88c316              # imm = 0xB88C316
pushq %r10
pushq %rax
callq 0x7b9b
addq $0x20, %rsp
movslq 0x6a9d(%rip), %rax      # 0xe230
addq %rax, %r12
movl %r13d, %ebp
addq $0x30, %rbx
movl %ebp, %r8d
cmpq %rbx, 0x30(%rsp)
jne 0x75e5
jmp 0x7b1d
testq %r13, %r13
je 0x7b96
movq (%r13), %rax
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x7b96
testl %esi, %esi
je 0x7a88
movl %esi, %r8d
xorl %esi, %esi
movl $0x0, 0x8(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %r8, 0x60(%rsp)
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
movq 0x50(%rsp), %rcx
movq 0x10(%rcx,%rax), %rdi
movq %rdi, 0x68(%rsp)
movl 0x18(%rcx,%rax), %r10d
movl 0x1c(%rcx,%rax), %edi
movq %rdi, 0x70(%rsp)
movl 0x20(%rcx,%rax), %edi
movq %rdi, 0x30(%rsp)
movl 0x24(%rcx,%rax), %r9d
movl 0x28(%rcx,%rax), %edx
cmpl 0x20(%r13), %r15d
movq %rsi, 0x28(%rsp)
jae 0x7916
movq %r10, 0x40(%rsp)
movq %r9, 0x48(%rsp)
movl %edx, 0x3c(%rsp)
movl %r15d, %r15d
leaq (,%r15,4), %r14
movl 0x8(%rsp), %eax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movq 0x28(%r13), %rax
addq %r14, %rax
movl (%rax,%r12,4), %eax
cmpq %rax, %rsi
jb 0x78f9
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 0x10(%rsp), %rdi
movq 0x20(%rsp), %rsi
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0x7b9b
movq 0x48(%rsp), %rsi
addq $0x20, %rsp
movq 0x30(%r13), %rax
addq %r14, %rax
movl (%rax,%r12,4), %eax
addq %rax, %rbp
movl 0x20(%r13), %eax
leaq (%r15,%r12), %rcx
incq %rcx
incq %r12
cmpq %rax, %rcx
jb 0x7855
addq %r12, %r15
addl %r12d, 0x8(%rsp)
movq 0x48(%rsp), %r9
movq 0x40(%rsp), %r10
movq 0x10(%rsp), %rdi
movl 0x3c(%rsp), %edx
jmp 0x791b
movq 0x10(%rsp), %rdi
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
shrl %r10d
leaq (%r10,%r10,2), %rcx
movq (%rax,%rcx,8), %r10
leal -0x2b609(%r9), %eax
cmpl $0x13, %eax
ja 0x7954
leaq 0x29ba(%rip), %rcx      # 0xa2fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x301b(%rip), %rax      # 0xa96d
jmp 0x79a6
leaq 0x3010(%rip), %rax      # 0xa96b
cmpl $0x2b606, %r9d          # imm = 0x2B606
je 0x79a6
jmp 0x7b6c
leaq 0x2dad(%rip), %rax      # 0xa71d
jmp 0x79a6
leaq 0x2ffe(%rip), %rax      # 0xa977
jmp 0x79a6
leaq 0x2fed(%rip), %rax      # 0xa96f
jmp 0x79a6
leaq 0x2d90(%rip), %rax      # 0xa71b
jmp 0x79a6
leaq 0x2fe1(%rip), %rax      # 0xa975
jmp 0x79a6
leaq 0x2fd6(%rip), %rax      # 0xa973
jmp 0x79a6
leaq 0x2fcb(%rip), %rax      # 0xa971
cmpl $0x2b5e3, %edx          # imm = 0x2B5E3
jg 0x79d7
leaq 0x2e16(%rip), %r14      # 0xa7cb
cmpl $0x2b5d0, %edx          # imm = 0x2B5D0
movl 0x8(%rsp), %r9d
je 0x7a11
cmpl $0x2b5d2, %edx          # imm = 0x2B5D2
je 0x7a01
cmpl $0x2b5d5, %edx          # imm = 0x2B5D5
je 0x79f8
jmp 0x7b5c
cmpl $0x2b5e4, %edx          # imm = 0x2B5E4
movl 0x8(%rsp), %r9d
je 0x79f8
cmpl $0x5978d4, %edx         # imm = 0x5978D4
je 0x7a0a
cmpl $0x7ca1b285, %edx       # imm = 0x7CA1B285
jne 0x7b5c
leaq 0x2dce(%rip), %r14      # 0xa7cd
jmp 0x7a11
leaq 0x2dca(%rip), %r14      # 0xa7d2
jmp 0x7a11
leaq 0x2dbe(%rip), %r14      # 0xa7cf
movq %r14, 0x18(%rsp)
movq 0x68(%rsp), %r8
leaq 0x1(%r8), %rcx
movq 0x30(%rsp), %r14
addq %r14, %r8
incl %r9d
movq 0x70(%rsp), %r11
leal (%r14,%r11), %ebx
incl %r11d
subq $0x8, %rsp
leaq 0x3318(%rip), %rsi      # 0xad59
movq %r15, %r12
movq 0x28(%rsp), %rdx
movl %r9d, 0x10(%rsp)
movq %rax, %r15
xorl %eax, %eax
pushq 0x20(%rsp)
pushq %rbx
pushq %r11
pushq %r10
pushq %r15
callq 0x2200
movq 0x90(%rsp), %r8
movq 0x58(%rsp), %rsi
movq %r12, %r15
addq $0x30, %rsp
addq %r14, %rbp
incq %rsi
cmpq %r8, %rsi
jne 0x77ea
jmp 0x7a95
xorl %ebp, %ebp
xorl %r15d, %r15d
movl $0x0, 0x8(%rsp)
cmpl 0x20(%r13), %r15d
jae 0x7b10
movl %r15d, %ebx
movq 0x30(%r13), %rax
movl 0x8(%rsp), %r15d
incl %r15d
movq 0x10(%rsp), %r12
leaq 0x1(%rbp), %rdx
movl (%rax,%rbx,4), %eax
movq %rax, %rcx
addq %rbp, %rcx
movq 0x38(%r13), %rsi
movq 0x40(%r13), %rdi
movl (%rsi,%rbx,4), %r9d
movl (%rdi,%rbx,4), %r10d
movq 0x48(%r13), %rsi
movl (%rsi,%rbx,4), %r11d
movq 0x50(%r13), %rsi
movl (%rsi,%rbx,4), %r14d
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movl %r15d, %r8d
pushq %r14
pushq %r11
pushq %r10
pushq %rax
callq 0x7b9b
addq $0x20, %rsp
movq 0x30(%r13), %rax
movl (%rax,%rbx,4), %ecx
addq %rcx, %rbp
incq %rbx
movl 0x20(%r13), %ecx
incl %r15d
cmpq %rcx, %rbx
jb 0x7aaf
movq 0x10(%r13), %r8
addq 0x8(%r13), %r8
cmpq %r8, %rbp
jne 0x7b2c
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x64bd(%rip), %rax      # 0xdff0
movq (%rax), %rdi
leaq 0x2d4d(%rip), %rsi      # 0xa88a
leaq 0x2d34(%rip), %rdx      # 0xa878
movq %rbp, %rcx
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2200
leaq 0x3214(%rip), %rdi      # 0xad77
leaq 0x3234(%rip), %rsi      # 0xad9e
jmp 0x7b8f
leaq 0x323f(%rip), %rdi      # 0xadb2
leaq 0x3262(%rip), %rsi      # 0xaddc
movl %r9d, %edx
jmp 0x7b8f
leaq 0x322c(%rip), %rdi      # 0xadb2
leaq 0x324f(%rip), %rsi      # 0xaddc
movl %eax, %edx
xorl %eax, %eax
callq 0x8f28
callq 0x2736