// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]yahs/juicer.c
// Function: assembly_annotation
static uint64_t assembly_annotation(const char *f, sdict_t *sdict, const char *out_agp, const char *out_annot, 
        const char *out_lift, int *scale, uint64_t max_s, uint64_t *g)
{
    uint32_t i, j, c, n, m;
    int *seqs;
    FILE *fo_agp, *fo_annot, *fo_lift;
    uint64_t genome_size, scaled_gs;
    asm_dict_t *dict;
    sd_seg_t seg;

    fo_agp = fopen(out_agp, "w");
    fo_annot = fopen(out_annot, "w");
    fo_lift = fopen(out_lift, "w");
    
    dict = make_asm_dict_from_agp(sdict, f, 1);
    n = dict->u + dict->n;
    seqs = (int *) calloc(n, sizeof(int));
    genome_size = 0;
    c = j = 0;
    m = dict->s[j++].n;
    for (i = 0; i < dict->u; ++i) {
        seg = dict->seg[i];
        fprintf(fo_agp, "assembly\t%lu\t%lu\t%u\t%s\t%s\t%u\t%u\t%s\n", 
                genome_size + 1, genome_size + seg.y, i + 1, agp_component_type_val(seg.t),
                sdict->s[seg.c>>1].name, seg.x + 1, seg.x + seg.y, agp_orientation_val(seg.r));
        fprintf(fo_annot, ">ctg%08u.1 %u %u\n", i + 1, i + 1, seg.y);
        fprintf(fo_lift, "ctg%08u.1\t%u\t%u\t%u\t%s\t%s\t%u\t%u\t%s\n",
                i + 1, 1, seg.y, 1, agp_component_type_val(seg.t), sdict->s[seg.c>>1].name, 
                seg.x + 1, seg.x + seg.y, agp_orientation_val(AGP_OT_PLUS));
        if (i == m) {
            m += dict->s[j++].n;
            ++c;
        }
        seqs[c++] = (int) (i + 1) * (seg.r == AGP_OT_MINUS? -1 : 1);
        genome_size += seg.y;
    }

    for (i = 0; i < n; ++i) {
        // seqs[n - 1] is always 0
        if (seqs[i]) {
            fprintf(fo_annot, "%d", seqs[i]);
            fputc(seqs[i + 1]? ' ' : '\n', fo_annot);
        }
    }
    
    fclose(fo_agp);
    fclose(fo_annot);
    fclose(fo_lift);
    free(seqs);

    asm_destroy(dict);

    scaled_gs = linear_scale(genome_size, scale, max_s);
    *g = genome_size;
    
    return scaled_gs;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, 0x70(%rsp)
movq %r8, %rbx
movq %rcx, %r14
movq %rsi, %r13
movq %rdi, %r15
leaq 0x2e25(%rip), %r12      # 0xf010
movq %rdx, %rdi
movq %r12, %rsi
callq 0x2330
movq %rax, 0x50(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2330
movq %rax, 0x30(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2330
movq %rax, 0x48(%rsp)
movq %r13, 0x60(%rsp)
movq %r13, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x6768
movq %rax, %r14
movl 0x18(%rax), %ebx
movl (%rax), %edi
addl %ebx, %edi
movl $0x4, %esi
movq %rdi, 0x58(%rsp)
callq 0x2200
testl %ebx, %ebx
movq %rax, 0x20(%rsp)
je 0xc567
movl $0x1, 0xc(%rsp)
movq 0x8(%r14), %rax
movl 0x18(%rax), %esi
movl $0x28, %ebp
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
xorl %ebx, %ebx
xorl %ecx, %ecx
movq %r14, 0x40(%rsp)
movq 0x20(%r14), %rdx
movl -0x10(%rdx,%rbp), %eax
movl -0xc(%rdx,%rbp), %r10d
movl -0x8(%rdx,%rbp), %r8d
movq %r8, 0x68(%rsp)
movl -0x4(%rdx,%rbp), %r8d
movl (%rdx,%rbp), %r13d
leal -0x2b609(%r8), %r12d
cmpl $0x13, %r12d
movq %r8, 0x28(%rsp)
ja 0xc2c6
leaq 0x3ce4(%rip), %r8       # 0xff98
movslq (%r8,%r12,4), %rdx
addq %r8, %rdx
jmpq *%rdx
leaq 0x3f72(%rip), %r9       # 0x10236
jmp 0xc318
leaq 0x378c(%rip), %r9       # 0xfa59
cmpl $0x2b606, %r8d          # imm = 0x2B606
je 0xc318
jmp 0xc637
leaq 0x3781(%rip), %r9       # 0xfa63
jmp 0xc318
leaq 0x3520(%rip), %r9       # 0xf80b
jmp 0xc318
leaq 0x3767(%rip), %r9       # 0xfa5b
jmp 0xc318
leaq 0x3f41(%rip), %r9       # 0x1023e
jmp 0xc318
leaq 0x375b(%rip), %r9       # 0xfa61
jmp 0xc318
leaq 0x3750(%rip), %r9       # 0xfa5f
jmp 0xc318
leaq 0x3745(%rip), %r9       # 0xfa5d
movq 0x60(%rsp), %rdx
movq 0x8(%rdx), %rdx
shrl %eax
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %rdx
cmpl $0x2b5e3, %r13d         # imm = 0x2B5E3
jg 0xc35b
leaq 0x357e(%rip), %r11      # 0xf8b9
cmpl $0x2b5d0, %r13d         # imm = 0x2B5D0
je 0xc393
cmpl $0x2b5d2, %r13d         # imm = 0x2B5D2
je 0xc383
cmpl $0x2b5d5, %r13d         # imm = 0x2B5D5
je 0xc37a
jmp 0xc64c
cmpl $0x2b5e4, %r13d         # imm = 0x2B5E4
je 0xc37a
cmpl $0x5978d4, %r13d        # imm = 0x5978D4
je 0xc38c
cmpl $0x7ca1b285, %r13d      # imm = 0x7CA1B285
jne 0xc64c
leaq 0x353a(%rip), %r11      # 0xf8bb
jmp 0xc393
leaq 0x3536(%rip), %r11      # 0xf8c0
jmp 0xc393
leaq 0x352a(%rip), %r11      # 0xf8bd
movq %rax, 0x90(%rsp)
movl %ebx, 0x14(%rsp)
movl %r13d, 0x38(%rsp)
movl %edi, 0x10(%rsp)
movl %esi, 0x3c(%rsp)
movq %rdx, %r14
leaq 0x1(%rcx), %rdx
movq 0x68(%rsp), %rbx
addq %rbx, %rcx
movq %r15, %rax
leal (%rbx,%r10), %r15d
incl %r10d
movq %rax, 0x78(%rsp)
leaq 0x1(%rax), %r13
movq 0x50(%rsp), %rdi
leaq 0x44e5(%rip), %rsi      # 0x108bf
movq %rcx, 0x18(%rsp)
movl %r13d, %r8d
xorl %eax, %eax
pushq %r11
movq %r15, 0x90(%rsp)
pushq %r15
movq %r10, 0x90(%rsp)
pushq %r10
pushq %r14
callq 0x2230
addq $0x20, %rsp
movq 0x30(%rsp), %rdi
leaq 0x44d2(%rip), %rsi      # 0x108e3
movl %r13d, %edx
movl %r13d, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2230
cmpl $0x13, %r12d
ja 0xc444
leaq 0x3bba(%rip), %rcx      # 0xffe8
movslq (%rcx,%r12,4), %rax
addq %rcx, %rax
movl 0x14(%rsp), %ebx
jmpq *%rax
leaq 0x3df4(%rip), %r10      # 0x10236
jmp 0xc49b
leaq 0x360e(%rip), %r10      # 0xfa59
cmpl $0x2b606, 0x28(%rsp)    # imm = 0x2B606
movl 0x14(%rsp), %ebx
je 0xc49b
jmp 0xc637
leaq 0x35fe(%rip), %r10      # 0xfa63
jmp 0xc49b
leaq 0x339d(%rip), %r10      # 0xf80b
jmp 0xc49b
leaq 0x35e4(%rip), %r10      # 0xfa5b
jmp 0xc49b
leaq 0x3dbe(%rip), %r10      # 0x1023e
jmp 0xc49b
leaq 0x35d8(%rip), %r10      # 0xfa61
jmp 0xc49b
leaq 0x35cd(%rip), %r10      # 0xfa5f
jmp 0xc49b
leaq 0x35c2(%rip), %r10      # 0xfa5d
movq 0x60(%rsp), %rax
movq 0x8(%rax), %r11
subq $0x8, %rsp
movq 0x50(%rsp), %rdi
leaq 0x4441(%rip), %rsi      # 0x108f5
movl %r13d, %edx
movl $0x1, %ecx
movq 0x70(%rsp), %r8
movl $0x1, %r9d
xorl %eax, %eax
leaq 0x33e9(%rip), %r15      # 0xf8b9
pushq %r15
pushq 0x98(%rsp)
pushq 0x98(%rsp)
movq 0xb0(%rsp), %r14
pushq (%r11,%r14,8)
pushq %r10
callq 0x2230
addq $0x30, %rsp
movl 0x3c(%rsp), %esi
movl %esi, %eax
movq 0x78(%rsp), %r15
cmpq %rax, %r15
jne 0xc528
movq 0x40(%rsp), %r14
movq 0x8(%r14), %rax
movl 0xc(%rsp), %edx
movl %edx, %ecx
incl %edx
movl %edx, 0xc(%rsp)
imulq $0x58, %rcx, %rcx
addl 0x18(%rax,%rcx), %esi
incl %ebx
jmp 0xc52d
movq 0x40(%rsp), %r14
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
movl 0x10(%rsp), %edi
incq %r15
cmpl $0x2b5d2, 0x38(%rsp)    # imm = 0x2B5D2
cmovel %edi, %r13d
movl %ebx, %edx
incl %ebx
movl %r13d, (%rax,%rdx,4)
movl 0x18(%r14), %edx
addq $0x30, %rbp
decl %edi
cmpq %rdx, %r15
jb 0xc27b
jmp 0xc569
xorl %ecx, %ecx
movq %rcx, 0x18(%rsp)
movq %r14, %r13
movq 0xd0(%rsp), %r14
cmpq $0x0, 0x58(%rsp)
je 0xc5da
leaq 0x2dae(%rip), %rbx      # 0xf336
movl $0xa, %ebp
xorl %r15d, %r15d
movq 0x30(%rsp), %r12
movl (%rax,%r15,4), %edx
testl %edx, %edx
je 0xc5d0
movq %r12, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2230
movq 0x20(%rsp), %rax
cmpl $0x0, 0x4(%rax,%r15,4)
leaq 0x1(%r15), %r15
movl $0x20, %edi
cmovel %ebp, %edi
movq %r12, %rsi
callq 0x21e0
movq 0x20(%rsp), %rax
jmp 0xc5d3
incq %r15
cmpq 0x58(%rsp), %r15
jne 0xc595
movq %rax, %rbx
movq 0x50(%rsp), %rdi
callq 0x2120
movq 0x30(%rsp), %rdi
callq 0x2120
movq 0x48(%rsp), %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x2060
movq %r13, %rdi
callq 0x52fd
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq 0x70(%rsp), %rsi
callq 0x34f0
movq %rbx, (%r14)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3860(%rip), %rdi      # 0xfe9e
leaq 0x3883(%rip), %rsi      # 0xfec8
movq 0x28(%rsp), %rdx
jmp 0xc65d
leaq 0x3810(%rip), %rdi      # 0xfe63
leaq 0x3830(%rip), %rsi      # 0xfe8a
movl %r13d, %edx
xorl %eax, %eax
callq 0xdbf6