// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xb0, %rsp
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x84(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x93eb
cmpq $0x0, -0x28(%rbp)
je 0x93d5
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x90(%rbp)
jmp 0x93e0
xorl %eax, %eax
movq %rax, -0x90(%rbp)
jmp 0x93e0
movq -0x90(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x941b
movq 0x7bff(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x437d(%rip), %rsi      # 0xd780
leaq 0x4396(%rip), %rdx      # 0xd7a0
movb $0x0, %al
callq 0x2200
movl $0x1, %edi
callq 0x2370
cmpq $0x0, -0x28(%rbp)
je 0x9711
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x95eb
movq -0x18(%rbp), %rsi
movl -0x7c(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
leaq -0x78(%rbp), %rdi
movl $0x30, %edx
callq 0x2220
movl -0x80(%rbp), %ecx
movq -0x28(%rbp), %rdx
xorl %eax, %eax
cmpl 0x20(%rdx), %ecx
movb %al, -0x91(%rbp)
jae 0x948a
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x80(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x7c(%rbp), %eax
setbe %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x9499
jmp 0x955c
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x1, %rdx
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x80(%rbp), %r8d
movl (%rax,%r8,4), %eax
addq %rax, %rcx
movl -0x84(%rbp), %r8d
addl $0x1, %r8d
movl %r8d, -0x84(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x80(%rbp), %r9d
movl (%rax,%r9,4), %r9d
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x80(%rbp), %r10d
movl (%rax,%r10,4), %ebx
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x80(%rbp), %r10d
movl (%rax,%r10,4), %r11d
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x80(%rbp), %r10d
movl (%rax,%r10,4), %r10d
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x80(%rbp), %r14d
movl (%rax,%r14,4), %eax
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x9860
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x80(%rbp), %ecx
movl (%rax,%rcx,4), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x945c
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq $0x1, %rdx
movq -0x68(%rbp), %rcx
movl -0x58(%rbp), %eax
addq %rax, %rcx
movl -0x84(%rbp), %r8d
addl $0x1, %r8d
movl %r8d, -0x84(%rbp)
movl -0x54(%rbp), %r9d
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x60(%rbp), %r10d
shrl %r10d
movl %r10d, %r10d
imulq $0x18, %r10, %r10
addq %r10, %rax
movq (%rax), %rbx
movl -0x5c(%rbp), %r11d
addl $0x1, %r11d
movl -0x5c(%rbp), %r10d
addl -0x58(%rbp), %r10d
movl -0x50(%rbp), %eax
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x9940
movl -0x58(%rbp), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x9434
jmp 0x95ed
movl -0x80(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jae 0x96c0
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x1, %rdx
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x80(%rbp), %r8d
movl (%rax,%r8,4), %eax
addq %rax, %rcx
movl -0x84(%rbp), %r8d
addl $0x1, %r8d
movl %r8d, -0x84(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x80(%rbp), %r9d
movl (%rax,%r9,4), %r9d
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x80(%rbp), %r10d
movl (%rax,%r10,4), %ebx
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x80(%rbp), %r10d
movl (%rax,%r10,4), %r11d
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x80(%rbp), %r10d
movl (%rax,%r10,4), %r10d
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x80(%rbp), %r14d
movl (%rax,%r14,4), %eax
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x9860
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x80(%rbp), %ecx
movl (%rax,%rcx,4), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x95ed
movq -0x48(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x28(%rbp), %rdx
addq 0x10(%rdx), %rcx
cmpq %rcx, %rax
je 0x970c
movq 0x7918(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x28(%rbp), %rax
addq 0x10(%rax), %r8
leaq 0x40b4(%rip), %rsi      # 0xd7b2
leaq 0x409b(%rip), %rdx      # 0xd7a0
movb $0x0, %al
callq 0x2200
jmp 0x9854
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x9852
movq -0x18(%rbp), %rsi
movl -0x7c(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
leaq -0x78(%rbp), %rdi
movl $0x30, %edx
callq 0x2220
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x1, %rdx
movq -0x48(%rbp), %rcx
movl -0x58(%rbp), %eax
addq %rax, %rcx
movl -0x84(%rbp), %r8d
addl $0x1, %r8d
movl %r8d, -0x84(%rbp)
movl -0x54(%rbp), %r9d
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x60(%rbp), %r10d
shrl %r10d
movl %r10d, %r10d
imulq $0x18, %r10, %r10
addq %r10, %rax
movq (%rax), %rbx
movl -0x5c(%rbp), %r11d
addl $0x1, %r11d
movl -0x5c(%rbp), %r10d
addl -0x58(%rbp), %r10d
movl -0x50(%rbp), %eax
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x9940
movl -0x58(%rbp), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x7c(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x9842
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x1, %rdx
movq -0x48(%rbp), %rcx
movslq 0x7a47(%rip), %rax      # 0x11230
addq %rax, %rcx
movl -0x84(%rbp), %r8d
addl $0x1, %r8d
movl %r8d, -0x84(%rbp)
movl 0x7a1f(%rip), %r9d      # 0x11224
movl 0x7a24(%rip), %r11d     # 0x11230
movl 0x7a15(%rip), %r10d     # 0x11228
movl 0x7a13(%rip), %eax      # 0x1122c
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl $0xb88c316, 0x10(%rsp)  # imm = 0xB88C316
movl %eax, 0x18(%rsp)
callq 0x9860
movslq 0x79f6(%rip), %rax      # 0x11230
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x9844
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x9718
jmp 0x9854
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %rbp
retq