// File: /workspace/github_c_makefile_star2_O1/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, 0x78(%rsp)
movq %r8, %rbx
movq %rcx, %r14
movq %rsi, %r13
movq %rdi, %r15
leaq 0x301e(%rip), %r12      # 0xf010
movq %rdx, %rdi
movq %r12, %rsi
callq 0x2330
movq %rax, 0x48(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2330
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2330
movq %rax, 0x40(%rsp)
movq %r13, 0x60(%rsp)
movq %r13, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x6814
movq %rax, %r14
movl 0x18(%rax), %ebx
movl (%rax), %edi
addl %ebx, %edi
movl $0x4, %esi
movq %rdi, 0x70(%rsp)
callq 0x2200
testl %ebx, %ebx
movq %rax, 0x20(%rsp)
je 0xc387
movl $0x1, 0xc(%rsp)
movq 0x8(%r14), %rax
movl 0x18(%rax), %edi
movl $0x28, %ebp
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r8d, %r8d
movq %r14, 0x38(%rsp)
movq 0x20(%r14), %rcx
movl -0x10(%rcx,%rbp), %eax
movl -0xc(%rcx,%rbp), %r10d
movl -0x8(%rcx,%rbp), %edx
movq %rdx, 0x68(%rsp)
movl -0x4(%rcx,%rbp), %r13d
movl (%rcx,%rbp), %edx
leal -0x2b609(%r13), %ebx
cmpl $0x13, %ebx
ja 0xc0d0
leaq 0x3ef3(%rip), %rcx      # 0xffa8
movl %edi, %r9d
movq %rcx, %rdi
movslq (%rcx,%rbx,4), %rcx
addq %rdi, %rcx
movl %r9d, %edi
jmpq *%rcx
leaq 0x417e(%rip), %r9       # 0x1024c
jmp 0xc122
leaq 0x3990(%rip), %r9       # 0xfa67
cmpl $0x2b606, %r13d         # imm = 0x2B606
je 0xc122
jmp 0xc462
leaq 0x3983(%rip), %r9       # 0xfa6f
jmp 0xc122
leaq 0x3726(%rip), %r9       # 0xf81b
jmp 0xc122
leaq 0x396b(%rip), %r9       # 0xfa69
jmp 0xc122
leaq 0x414d(%rip), %r9       # 0x10254
jmp 0xc122
leaq 0x395d(%rip), %r9       # 0xfa6d
jmp 0xc122
leaq 0x300c(%rip), %r9       # 0xf125
jmp 0xc122
leaq 0x3949(%rip), %r9       # 0xfa6b
movq 0x60(%rsp), %rcx
movq 0x8(%rcx), %rcx
shrl %eax
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %r14
cmpl $0x2b5e3, %edx          # imm = 0x2B5E3
jg 0xc161
leaq 0x3785(%rip), %r11      # 0xf8c9
cmpl $0x2b5d0, %edx          # imm = 0x2B5D0
je 0xc196
cmpl $0x2b5d2, %edx          # imm = 0x2B5D2
je 0xc186
cmpl $0x2b5d5, %edx          # imm = 0x2B5D5
je 0xc17d
jmp 0xc452
cmpl $0x2b5e4, %edx          # imm = 0x2B5E4
je 0xc17d
cmpl $0x5978d4, %edx         # imm = 0x5978D4
je 0xc18f
cmpl $0x7ca1b285, %edx       # imm = 0x7CA1B285
jne 0xc452
leaq 0x3747(%rip), %r11      # 0xf8cb
jmp 0xc196
leaq 0x2fb8(%rip), %r11      # 0xf145
jmp 0xc196
leaq 0x3737(%rip), %r11      # 0xf8cd
movq %rbp, 0x58(%rsp)
movq %rax, 0x90(%rsp)
movq %r13, 0x50(%rsp)
movl %r15d, 0x14(%rsp)
movl %edx, 0x30(%rsp)
movl %esi, 0x10(%rsp)
movl %edi, 0x34(%rsp)
leaq 0x1(%r8), %rdx
movq 0x68(%rsp), %r15
addq %r15, %r8
movq %rbx, %rbp
leal (%r15,%r10), %ebx
incl %r10d
leal 0x1(%r12), %r13d
movq 0x48(%rsp), %rdi
leaq 0x46f5(%rip), %rsi      # 0x108d5
movq %r8, 0x18(%rsp)
movq %r8, %rcx
movl %r13d, %r8d
xorl %eax, %eax
pushq %r11
movq %rbx, 0x90(%rsp)
pushq %rbx
movq %r10, 0x90(%rsp)
pushq %r10
pushq %r14
callq 0x2230
addq $0x20, %rsp
movq 0x28(%rsp), %rdi
leaq 0x46e0(%rip), %rsi      # 0x108f9
movl %r13d, %edx
movl %r13d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x2230
cmpl $0x13, %ebp
ja 0xc256
leaq 0x3dc3(%rip), %rcx      # 0xfff8
movslq (%rcx,%rbp,4), %rax
addq %rcx, %rax
movq 0x20(%rsp), %r13
movl 0x14(%rsp), %r15d
movq 0x58(%rsp), %rbp
jmpq *%rax
leaq 0x3ff8(%rip), %r10      # 0x1024c
jmp 0xc2b8
leaq 0x380a(%rip), %r10      # 0xfa67
cmpl $0x2b606, 0x50(%rsp)    # imm = 0x2B606
movq 0x20(%rsp), %r13
movl 0x14(%rsp), %r15d
movq 0x58(%rsp), %rbp
je 0xc2b8
jmp 0xc475
leaq 0x37ed(%rip), %r10      # 0xfa6f
jmp 0xc2b8
leaq 0x3590(%rip), %r10      # 0xf81b
jmp 0xc2b8
leaq 0x37d5(%rip), %r10      # 0xfa69
jmp 0xc2b8
leaq 0x3fb7(%rip), %r10      # 0x10254
jmp 0xc2b8
leaq 0x37c7(%rip), %r10      # 0xfa6d
jmp 0xc2b8
leaq 0x2e76(%rip), %r10      # 0xf125
jmp 0xc2b8
leaq 0x37b3(%rip), %r10      # 0xfa6b
movq 0x60(%rsp), %rax
movq 0x8(%rax), %r11
leal 0x1(%r12), %edx
subq $0x8, %rsp
movq 0x48(%rsp), %rdi
leaq 0x4635(%rip), %rsi      # 0x1090b
movl $0x1, %ecx
movq 0x70(%rsp), %r8
movl $0x1, %r9d
xorl %eax, %eax
leaq 0x35da(%rip), %rbx      # 0xf8c9
pushq %rbx
pushq 0x98(%rsp)
pushq 0x98(%rsp)
movq 0xb0(%rsp), %rbx
pushq (%r11,%rbx,8)
pushq %r10
callq 0x2230
addq $0x30, %rsp
movl 0x34(%rsp), %edi
movl %edi, %eax
cmpq %rax, %r12
jne 0xc342
movq 0x38(%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), %edi
incl %r15d
jmp 0xc347
movq 0x38(%rsp), %r14
movq 0x18(%rsp), %r8
movl 0x10(%rsp), %esi
leaq 0x1(%r12), %rax
incl %r12d
cmpl $0x2b5d2, 0x30(%rsp)    # imm = 0x2B5D2
cmovel %esi, %r12d
movl %r15d, %ecx
incl %r15d
movl %r12d, (%r13,%rcx,4)
movl 0x18(%r14), %ecx
addq $0x30, %rbp
decl %esi
movq %rax, %r12
cmpq %rcx, %rax
jb 0xc084
jmp 0xc38d
movq %rax, %r13
xorl %r8d, %r8d
movq %r8, 0x18(%rsp)
movq 0x70(%rsp), %rax
testl %eax, %eax
je 0xc3f0
movl %eax, %r15d
leaq 0x2f9a(%rip), %rbx      # 0xf33f
movl $0xa, %ebp
xorl %r12d, %r12d
movl (%r13,%r12,4), %edx
testl %edx, %edx
je 0xc3e8
movq 0x28(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2230
movq 0x20(%rsp), %rax
cmpl $0x0, 0x4(%rax,%r12,4)
movl $0x20, %edi
cmovel %ebp, %edi
movq %r13, %rsi
movq 0x20(%rsp), %r13
callq 0x21e0
incq %r12
cmpq %r12, %r15
jne 0xc3ad
movq 0x48(%rsp), %rdi
callq 0x2120
movq 0x28(%rsp), %rdi
callq 0x2120
movq 0x40(%rsp), %rdi
callq 0x2120
movq %r13, %rdi
callq 0x2060
movq %r14, %rdi
callq 0x5398
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq 0x78(%rsp), %rsi
callq 0x3540
movq 0xd0(%rsp), %rcx
movq %rbx, (%rcx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a16(%rip), %rdi      # 0xfe6f
leaq 0x3a36(%rip), %rsi      # 0xfe96
jmp 0xc488
leaq 0x3a41(%rip), %rdi      # 0xfeaa
leaq 0x3a64(%rip), %rsi      # 0xfed4
movl %r13d, %edx
jmp 0xc488
leaq 0x3a2e(%rip), %rdi      # 0xfeaa
leaq 0x3a51(%rip), %rsi      # 0xfed4
movq 0x50(%rsp), %rdx
xorl %eax, %eax
callq 0xda1c