// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/juicer.c
// Function: assembly_to_agp
static int assembly_to_agp(char *assembly, char *lift, sdict_t *sdict, FILE *fo)
{
    asm_dict_t *dict;
    iostream_t *fp;
    char *line;
    char cname[1024], c0[1024], c1[1024], *cstr;
    int32_t cid, sid, fid, sign;
    uint32_t i, clen, mlen, s, p, *coords;
    int64_t slen;
    size_t m;
    kvec_t(int) segs;

    dict = make_asm_dict_from_agp(sdict, lift, 1);

    m = 4;
    coords = (uint32_t *) malloc(sizeof(uint32_t) * m * 3);
    c0[0] = c1[0] = '\0';
    mlen = 0;
    sid = 0;
    kv_init(segs);

    fp = iostream_open(assembly);
    if (fp == NULL) {
        fprintf(stderr, "[E::%s] cannot open file %s for reading\n", __func__, assembly);
        exit(EXIT_FAILURE);
    }
    while ((line = iostream_getline(fp)) != NULL) {
        if (is_empty_line(line) || line[0] != '>')
            continue;
        
        sscanf(line, "%s %d %u", cname, &cid, &clen);
        cstr = strstr(cname, ":::");
        if (cstr != NULL) {
            cname[cstr - cname] = '\0';
        }
        strcpy(c1, cname + 1);

        if (!strcmp(c0, c1)) {
            mlen += clen;
        } else {
            mlen = clen;
            strcpy(c0, c1);
        }

        if (sd_coordinate_rev_conversion(dict, asm_sd_get(dict, c1), mlen - clen, &s, &p, 0) != CC_SUCCESS) {
            fprintf(stderr, "[E::%s] coordinates conversion error %s %u\n", __func__, c1, mlen - clen);
            exit(EXIT_FAILURE);
        }

        if (clen == 0)
            fprintf(stderr, "[W::%s] segment of length zero in line: %s\n", __func__, line);

        if (cid > m) {
            m <<= 1;
            coords = (uint32_t *) realloc(coords, sizeof(uint32_t) * m * 3);
        }

        cid -= 1;
        coords[cid * 3] = s;
        coords[cid * 3 + 1] = p + 1; // 0-based to 1-based coordinates
        coords[cid * 3 + 2] = clen;
    }
    iostream_close(fp);

    fp = iostream_open(assembly);
    if (fp == NULL) {
        fprintf(stderr, "[E::%s] cannot open file %s for reading\n", __func__, assembly);
        exit(EXIT_FAILURE);
    }
    while ((line = iostream_getline(fp)) != NULL) {
        if (is_empty_line(line) || line[0] == '>')
            continue;

        segs.n = 0;
        char *eptr, *fptr;
        cid = strtol(line, &eptr, 10);
        if (coords[(abs(cid) - 1) * 3 + 2] > 0)
            kv_push(int, segs, cid);
        while (*eptr && *eptr != '\n') {
            cid = strtol(eptr + 1, &fptr, 10);
            if (coords[(abs(cid) - 1) * 3 + 2] > 0)
                kv_push(int, segs, cid);
            eptr = fptr;
        }

        if (segs.n == 0) continue;

        ++sid;
        fid = 0;
        slen = 0;
        for (i = 0; i < segs.n; ++i) {
            cid = segs.a[i];
            sign = cid > 0;
            cid = abs(cid) - 1;
            fprintf(fo, "scaffold_%d\t%ld\t%ld\t%d\t%s\t%s\t%d\t%d\t%s\n", sid, slen + 1, 
                    slen + coords[cid * 3 + 2], ++fid, agp_component_type_val(DEFAULT_AGP_SEQ_COMPONENT_TYPE), 
                    sdict->s[coords[cid * 3]].name, coords[cid * 3 + 1], coords[cid * 3 + 1] + coords[cid * 3 + 2] - 1,
                    sign? agp_orientation_val(AGP_OT_PLUS) : agp_orientation_val(AGP_OT_MINUS));
            slen += coords[cid * 3 + 2];
            if (i != segs.n - 1) {
                fprintf(fo, "scaffold_%d\t%ld\t%ld\t%d\t%s\t%d\t%s\t%s\t%s\n", sid, slen + 1, 
                        slen + DEFAULT_AGP_GAP_SIZE, ++fid, 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));
                slen += DEFAULT_AGP_GAP_SIZE;
            }
        }
    }
    iostream_close(fp);

    free(coords);
    kv_destroy(segs);
    asm_destroy(dict);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xd80, %rsp            # imm = 0xD80
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x1, %edx
callq 0x81b0
movq %rax, -0x38(%rbp)
movq $0x4, -0xc98(%rbp)
movq -0xc98(%rbp), %rax
shlq $0x2, %rax
imulq $0x3, %rax, %rdi
callq 0x22a0
movq %rax, -0xc88(%rbp)
movb $0x0, -0xc50(%rbp)
movb $0x0, -0x850(%rbp)
movl $0x0, -0xc74(%rbp)
movl $0x0, -0xc60(%rbp)
movq $0x0, -0xca8(%rbp)
movq $0x0, -0xcb0(%rbp)
movq $0x0, -0xca0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2c80
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x120ee
movq 0x5f30(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rcx
leaq 0x135a(%rip), %rsi      # 0x13430
leaq 0x2b7d(%rip), %rdx      # 0x14c5a
movb $0x0, %al
callq 0x2230
movl $0x1, %edi
callq 0x23e0
jmp 0x120f0
movq -0x40(%rbp), %rdi
callq 0x2f00
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x12350
movq -0x48(%rbp), %rdi
callq 0x2c20
cmpl $0x0, %eax
jne 0x12121
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
je 0x12123
jmp 0x120f0
movq -0x48(%rbp), %rdi
leaq -0x450(%rbp), %rdx
leaq 0x2b35(%rip), %rsi      # 0x14c6a
leaq -0xc5c(%rbp), %rcx
leaq -0xc70(%rbp), %r8
movb $0x0, %al
callq 0x22c0
leaq -0x450(%rbp), %rdi
leaq 0x2b1b(%rip), %rsi      # 0x14c73
callq 0x2460
movq %rax, -0xc58(%rbp)
cmpq $0x0, -0xc58(%rbp)
je 0x12187
movq -0xc58(%rbp), %rax
leaq -0x450(%rbp), %rcx
subq %rcx, %rax
movb $0x0, -0x450(%rbp,%rax)
leaq -0xc50(%rbp), %rdi
leaq -0x450(%rbp), %rsi
addq $0x1, %rsi
callq 0x20a0
leaq -0x850(%rbp), %rdi
leaq -0xc50(%rbp), %rsi
callq 0x2210
cmpl $0x0, %eax
jne 0x121ca
movl -0xc70(%rbp), %eax
addl -0xc74(%rbp), %eax
movl %eax, -0xc74(%rbp)
jmp 0x121e9
movl -0xc70(%rbp), %eax
movl %eax, -0xc74(%rbp)
leaq -0x850(%rbp), %rdi
leaq -0xc50(%rbp), %rsi
callq 0x20a0
movq -0x38(%rbp), %rax
movq %rax, -0xcc8(%rbp)
movq -0x38(%rbp), %rdi
leaq -0xc50(%rbp), %rsi
callq 0x77f0
movq -0xcc8(%rbp), %rdi
movl %eax, %esi
movl -0xc74(%rbp), %eax
subl -0xc70(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
leaq -0xc78(%rbp), %rcx
leaq -0xc7c(%rbp), %r8
xorl %r9d, %r9d
callq 0x9790
cmpl $0x0, %eax
je 0x12276
movq 0x5db9(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq -0xc50(%rbp), %rcx
movl -0xc74(%rbp), %r8d
subl -0xc70(%rbp), %r8d
leaq 0x2a19(%rip), %rsi      # 0x14c77
leaq 0x29f5(%rip), %rdx      # 0x14c5a
movb $0x0, %al
callq 0x2230
movl $0x1, %edi
callq 0x23e0
cmpl $0x0, -0xc70(%rbp)
jne 0x122a2
movq 0x5d72(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
movq -0x48(%rbp), %rcx
leaq 0x2a0f(%rip), %rsi      # 0x14ca3
leaq 0x29bf(%rip), %rdx      # 0x14c5a
movb $0x0, %al
callq 0x2230
movslq -0xc5c(%rbp), %rax
cmpq -0xc98(%rbp), %rax
jbe 0x122e5
movq -0xc98(%rbp), %rax
shlq %rax
movq %rax, -0xc98(%rbp)
movq -0xc88(%rbp), %rdi
movq -0xc98(%rbp), %rax
shlq $0x2, %rax
imulq $0x3, %rax, %rsi
callq 0x2300
movq %rax, -0xc88(%rbp)
movl -0xc5c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xc5c(%rbp)
movl -0xc78(%rbp), %edx
movq -0xc88(%rbp), %rax
imull $0x3, -0xc5c(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0xc7c(%rbp), %edx
addl $0x1, %edx
movq -0xc88(%rbp), %rax
imull $0x3, -0xc5c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0xc70(%rbp), %edx
movq -0xc88(%rbp), %rax
imull $0x3, -0xc5c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x120f0
movq -0x40(%rbp), %rdi
callq 0x2e20
movq -0x18(%rbp), %rdi
callq 0x2c80
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x1239a
movq 0x5c84(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rcx
leaq 0x10ae(%rip), %rsi      # 0x13430
leaq 0x28d1(%rip), %rdx      # 0x14c5a
movb $0x0, %al
callq 0x2230
movl $0x1, %edi
callq 0x23e0
jmp 0x1239c
movq -0x40(%rbp), %rdi
callq 0x2f00
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x1296f
movq -0x48(%rbp), %rdi
callq 0x2c20
cmpl $0x0, %eax
jne 0x123cd
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x123cf
jmp 0x1239c
movq $0x0, -0xcb0(%rbp)
movq -0x48(%rbp), %rdi
leaq -0xcb8(%rbp), %rsi
movl $0xa, %edx
callq 0x2240
movl %eax, -0xc5c(%rbp)
movq -0xc88(%rbp), %rax
movl -0xc5c(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
subl $0x1, %ecx
imull $0x3, %ecx, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jbe 0x124af
jmp 0x12421
movq -0xcb0(%rbp), %rax
cmpq -0xca8(%rbp), %rax
jne 0x12488
cmpq $0x0, -0xca8(%rbp)
je 0x1244e
movq -0xca8(%rbp), %rax
shlq %rax
movq %rax, -0xcd0(%rbp)
jmp 0x1245c
movl $0x2, %eax
movq %rax, -0xcd0(%rbp)
jmp 0x1245c
movq -0xcd0(%rbp), %rax
movq %rax, -0xca8(%rbp)
movq -0xca0(%rbp), %rdi
movq -0xca8(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2300
movq %rax, -0xca0(%rbp)
movl -0xc5c(%rbp), %edx
movq -0xca0(%rbp), %rax
movq -0xcb0(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0xcb0(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x124af
jmp 0x124b1
movq -0xcb8(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xcd1(%rbp)
je 0x124de
movq -0xcb8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
setne %al
movb %al, -0xcd1(%rbp)
movb -0xcd1(%rbp), %al
testb $0x1, %al
jne 0x124ed
jmp 0x125dc
movq -0xcb8(%rbp), %rdi
addq $0x1, %rdi
leaq -0xcc0(%rbp), %rsi
movl $0xa, %edx
callq 0x2240
movl %eax, -0xc5c(%rbp)
movq -0xc88(%rbp), %rax
movl -0xc5c(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
subl $0x1, %ecx
imull $0x3, %ecx, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jbe 0x125c9
jmp 0x1253b
movq -0xcb0(%rbp), %rax
cmpq -0xca8(%rbp), %rax
jne 0x125a2
cmpq $0x0, -0xca8(%rbp)
je 0x12568
movq -0xca8(%rbp), %rax
shlq %rax
movq %rax, -0xce0(%rbp)
jmp 0x12576
movl $0x2, %eax
movq %rax, -0xce0(%rbp)
jmp 0x12576
movq -0xce0(%rbp), %rax
movq %rax, -0xca8(%rbp)
movq -0xca0(%rbp), %rdi
movq -0xca8(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2300
movq %rax, -0xca0(%rbp)
movl -0xc5c(%rbp), %edx
movq -0xca0(%rbp), %rax
movq -0xcb0(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0xcb0(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x125c9
movq -0xcc0(%rbp), %rax
movq %rax, -0xcb8(%rbp)
jmp 0x124b1
cmpq $0x0, -0xcb0(%rbp)
jne 0x125eb
jmp 0x1239c
movl -0xc60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc60(%rbp)
movl $0x0, -0xc64(%rbp)
movq $0x0, -0xc90(%rbp)
movl $0x0, -0xc6c(%rbp)
movl -0xc6c(%rbp), %eax
cmpq -0xcb0(%rbp), %rax
jae 0x1296a
movq -0xca0(%rbp), %rax
movl -0xc6c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0xc5c(%rbp)
cmpl $0x0, -0xc5c(%rbp)
setg %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xc68(%rbp)
movl -0xc5c(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
subl $0x1, %eax
movl %eax, -0xc5c(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xd20(%rbp)
movl -0xc60(%rbp), %eax
movl %eax, -0xd14(%rbp)
movq -0xc90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd10(%rbp)
movq -0xc90(%rbp), %rax
movq -0xc88(%rbp), %rcx
imull $0x3, -0xc5c(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
addq %rcx, %rax
movq %rax, -0xd08(%rbp)
movl -0xc64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcfc(%rbp)
movl %eax, -0xc64(%rbp)
leaq 0x5b86(%rip), %rax      # 0x18260
movl (%rax), %edi
callq 0x10f50
movq %rax, -0xcf8(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0xc88(%rbp), %rcx
imull $0x3, -0xc5c(%rbp), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0xcf0(%rbp)
movq -0xc88(%rbp), %rax
imull $0x3, -0xc5c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xce8(%rbp)
movq -0xc88(%rbp), %rax
imull $0x3, -0xc5c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0xc88(%rbp), %rcx
imull $0x3, -0xc5c(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
addl (%rcx,%rdx,4), %eax
subl $0x1, %eax
movl %eax, -0xce4(%rbp)
cmpl $0x0, -0xc68(%rbp)
je 0x12785
movl $0x2b5d0, %edi          # imm = 0x2B5D0
callq 0x11030
movq %rax, -0xd28(%rbp)
jmp 0x12796
movl $0x2b5d2, %edi          # imm = 0x2B5D2
callq 0x11030
movq %rax, -0xd28(%rbp)
movl -0xce4(%rbp), %r10d
movl -0xce8(%rbp), %r11d
movq -0xcf0(%rbp), %rbx
movq -0xcf8(%rbp), %r14
movl -0xcfc(%rbp), %r9d
movq -0xd08(%rbp), %r8
movq -0xd10(%rbp), %rcx
movl -0xd14(%rbp), %edx
movq -0xd20(%rbp), %rdi
movq -0xd28(%rbp), %rax
leaq 0x24ed(%rip), %rsi      # 0x14ccf
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, %al
callq 0x2230
movq -0xc88(%rbp), %rax
imull $0x3, -0xc5c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
addq -0xc90(%rbp), %rax
movq %rax, -0xc90(%rbp)
movl -0xc6c(%rbp), %eax
movq -0xcb0(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x12954
movq -0x30(%rbp), %rax
movq %rax, -0xd60(%rbp)
movl -0xc60(%rbp), %eax
movl %eax, -0xd54(%rbp)
movq -0xc90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd50(%rbp)
movq -0xc90(%rbp), %rax
leaq 0x59f9(%rip), %rcx      # 0x18270
movslq (%rcx), %rcx
addq %rcx, %rax
movq %rax, -0xd48(%rbp)
movl -0xc64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd3c(%rbp)
movl %eax, -0xc64(%rbp)
leaq 0x59c4(%rip), %rax      # 0x18264
movl (%rax), %edi
callq 0x10f50
movq %rax, %r14
leaq 0x59bf(%rip), %rax      # 0x18270
movl (%rax), %ebx
leaq 0x59ae(%rip), %rax      # 0x18268
movl (%rax), %edi
callq 0x12c40
movq %rax, -0xd38(%rbp)
movl $0xb88c316, %edi        # imm = 0xB88C316
callq 0x12d50
movq %rax, -0xd30(%rbp)
leaq 0x598c(%rip), %rax      # 0x1826c
movl (%rax), %edi
callq 0x12aa0
movq -0xd60(%rbp), %rdi
movl -0xd54(%rbp), %edx
movq -0xd50(%rbp), %rcx
movq -0xd48(%rbp), %r8
movl -0xd3c(%rbp), %r9d
movq -0xd38(%rbp), %r11
movq -0xd30(%rbp), %r10
leaq 0x23d8(%rip), %rsi      # 0x14cf6
movq %r14, (%rsp)
movl %ebx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, %al
callq 0x2230
leaq 0x592d(%rip), %rax      # 0x18270
movslq (%rax), %rax
addq -0xc90(%rbp), %rax
movq %rax, -0xc90(%rbp)
jmp 0x12956
movl -0xc6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc6c(%rbp)
jmp 0x12619
jmp 0x1239c
movq -0x40(%rbp), %rdi
callq 0x2e20
movq -0xc88(%rbp), %rdi
callq 0x2050
movq -0xca0(%rbp), %rdi
callq 0x2050
movq -0x38(%rbp), %rdi
callq 0x63d0
xorl %eax, %eax
addq $0xd80, %rsp            # imm = 0xD80
popq %rbx
popq %r14
popq %rbp
retq
nopw (%rax,%rax)