// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]yahs/juicer.c
// Function: make_juicer_pre_file_from_pa5
static int make_juicer_pre_file_from_pa5(char *f, char *agp, char *fai, int8_t mq, int scale, int count_gap, FILE *fo)
{
    iostream_t *fp;
    char *line;
    char cname0[4096], cname1[4096];
    uint32_t x0, x1, i0, i1;
    uint64_t p0, p1, rec_c, pair_c;
    uint8_t q0, q1;
    CC_ERR_t err0, err1;

    khash_t(str) *hmseq; // for absent sequences
    khint_t k;
    int absent;
    hmseq = kh_init(str);

    sdict_t *sdict = make_sdict_from_index(fai, 0);
    asm_dict_t *dict = agp? make_asm_dict_from_agp(sdict, agp, 1) : make_asm_dict_from_sdict(sdict);

    fp = iostream_open(f);
    if (fp == NULL) {
        fprintf(stderr, "[E::%s] cannot open file %s for reading\n", __func__, f);
        exit(EXIT_FAILURE);
    }

    rec_c = pair_c = 0;
    while ((line = iostream_getline(fp)) != NULL) {
        if (is_empty_line(line))
            continue;
        
        if (++rec_c % 1000000 == 0)
            fprintf(stderr, "[I::%s] %lu million records processed, %lu read pairs \n", __func__, rec_c / 1000000, pair_c);

        cname0[0] = cname1[0] = '\0';
        x0 = x1 = UINT32_MAX;
        q0 = q1 = 255;
        sscanf(line, "%*s %s %u %s %u %hhu %hhu", cname0, &x0, cname1, &x1, &q0, &q1);

        if (q0 < mq || q1 < mq)
            continue;

        err0 = sd_coordinate_conversion(dict, sd_get(sdict, cname0), x0, &i0, &p0, count_gap);
        err1 = sd_coordinate_conversion(dict, sd_get(sdict, cname1), x1, &i1, &p1, count_gap);

        if (err0 != CC_SUCCESS) {
            if (err0 == SEQ_NOT_FOUND) {
                k = kh_put(str, hmseq, cname0, &absent);
                if (absent) {
                    kh_key(hmseq, k) = strdup(cname0);
                    fprintf(stderr, "[W::%s] sequence \"%s\" not found \n", __func__, cname0);
                }
            } else if (err0 == POS_NOT_IN_RANGE) {
                fprintf(stderr, "[W::%s] sequence position \"%s:%u\" not in range \n", __func__, cname0, x0);
            }
        } else if (err1 != CC_SUCCESS) {
            if (err1 == SEQ_NOT_FOUND) {
                k = kh_put(str, hmseq, cname1, &absent);
                if (absent) {
                    kh_key(hmseq, k) = strdup(cname1);
                    fprintf(stderr, "[W::%s] sequence \"%s\" not found \n", __func__, cname1);
                }
            } else if (err1 == POS_NOT_IN_RANGE) {
                fprintf(stderr, "[W::%s] sequence position \"%s:%u\" not in range \n", __func__, cname1, x1);
            }
        } else {
            if (strcmp(dict->s[i0].name, dict->s[i1].name) <= 0)
                fprintf(fo, "0\t%s\t%lu\t0\t1\t%s\t%lu\t1\n", dict->s[i0].name, p0 >> scale, dict->s[i1].name, p1 >> scale);
            else
                fprintf(fo, "0\t%s\t%lu\t1\t1\t%s\t%lu\t0\n", dict->s[i1].name, p1 >> scale, dict->s[i0].name, p0 >> scale);

            ++pair_c;
        }
    }

    fprintf(stderr, "[I::%s] %ld read pairs processed\n", __func__, pair_c);

    for (k = 0; k < kh_end(hmseq); ++k)
        if (kh_exist(hmseq, k))
            free((char *) kh_key(hmseq, k));
    kh_destroy(str, hmseq);

    iostream_close(fp);
    asm_destroy(dict);
    sd_destroy(sdict);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2068, %rsp           # imm = 0x2068
movl %r9d, 0x1c(%rsp)
movl %r8d, %ebx
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r15
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0x4040
movq %rax, %r14
movq %r13, %rdi
xorl %esi, %esi
callq 0x5d57
movq %rax, %r13
movq %rax, %rdi
testq %r12, %r12
jne 0xd4f7
callq 0x62db
jmp 0xd504
movq %r12, %rsi
movl $0x1, %edx
callq 0x6768
movq %rax, 0x10(%rsp)
movq %r13, 0x48(%rsp)
movq %r15, %rdi
callq 0x35d7
testq %rax, %rax
je 0xd907
movq %rax, %r12
movsbl %bpl, %r13d
movq %r14, %rax
addq $0x18, %rax
movq %rax, 0x38(%rsp)
movl %ebx, %eax
movq %rax, 0x40(%rsp)
movb $-0x1, %r15b
movq $0x0, 0x28(%rsp)
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x3707
testq %rax, %rax
je 0xd844
movq %rax, %rbp
movq %rax, %rdi
callq 0x35b4
testl %eax, %eax
jne 0xd547
incq %rbx
movq %rbx, %rax
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
mulq %rcx
movq %rdx, %rcx
movq %rbx, %rax
movabsq $0x790fb65668c26139, %rdx # imm = 0x790FB65668C26139
imulq %rdx, %rax
rorq $0x6, %rax
movabsq $0x10c6f7a0b5ed, %rdx   # imm = 0x10C6F7A0B5ED
cmpq %rdx, %rax
jbe 0xd6c4
xorl %eax, %eax
movb %al, 0x60(%rsp)
movb %al, 0x1060(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x8(%rsp)
movl %eax, 0xc(%rsp)
movb %r15b, 0x2(%rsp)
movb %r15b, 0x3(%rsp)
movq %rbp, %rdi
leaq 0x3509(%rip), %rsi      # 0x10adc
leaq 0x1060(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x60(%rsp), %r8
leaq 0x8(%rsp), %r9
xorl %eax, %eax
leaq 0x2(%rsp), %r10
pushq %r10
leaq 0xb(%rsp), %r10
pushq %r10
callq 0x22b0
addq $0x10, %rsp
movzbl 0x3(%rsp), %eax
cmpl %r13d, %eax
jl 0xd547
movzbl 0x2(%rsp), %eax
cmpl %r13d, %eax
jl 0xd547
movq 0x48(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1060(%rsp), %rsi
callq 0x5733
movl 0xc(%rsp), %edx
movq 0x10(%rsp), %rdi
movl %eax, %esi
leaq 0x34(%rsp), %rcx
leaq 0x58(%rsp), %r8
movl 0x1c(%rsp), %r9d
callq 0x7bb9
movl %eax, 0x20(%rsp)
movq %rbp, %rdi
leaq 0x60(%rsp), %rsi
callq 0x5733
movl 0x8(%rsp), %edx
movq 0x10(%rsp), %rdi
movl %eax, %esi
leaq 0x30(%rsp), %rcx
leaq 0x50(%rsp), %r8
movl 0x1c(%rsp), %r9d
callq 0x7bb9
movl 0x20(%rsp), %ecx
testl %ecx, %ecx
je 0xd6f1
cmpl $0x1, %ecx
je 0xd735
cmpl $0x2, %ecx
jne 0xd547
movq 0x7954(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r8d
leaq 0x32dd(%rip), %rsi      # 0x10990
leaq 0x3404(%rip), %rdx      # 0x10abe
leaq 0x1060(%rsp), %rcx
jmp 0xd729
shrq $0x12, %rcx
movq 0x7929(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
leaq 0x325d(%rip), %rsi      # 0x10936
leaq 0x33de(%rip), %rdx      # 0x10abe
movq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0x2230
jmp 0xd5a5
testl %eax, %eax
je 0xd76e
cmpl $0x1, %eax
je 0xd7d1
cmpl $0x2, %eax
jne 0xd547
movq 0x78ea(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
movl 0x8(%rsp), %r8d
leaq 0x3273(%rip), %rsi      # 0x10990
leaq 0x339a(%rip), %rdx      # 0x10abe
leaq 0x60(%rsp), %rcx
xorl %eax, %eax
callq 0x2230
jmp 0xd547
movq %r14, %rdi
leaq 0x1060(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0xdd00
cmpl $0x0, 0x4(%rsp)
je 0xd547
leaq 0x1060(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl %eax, %edx
callq 0x2fb2
jmp 0xd547
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x34(%rsp), %ecx
imulq $0x58, %rcx, %rcx
movq (%rax,%rcx), %rdi
movl 0x30(%rsp), %ecx
imulq $0x58, %rcx, %rcx
movq (%rax,%rcx), %rbp
movq %rdi, 0x20(%rsp)
movq %rbp, %rsi
callq 0x2210
testl %eax, %eax
jg 0xd804
movq 0x58(%rsp), %rax
movq 0x40(%rsp), %rcx
shrq %cl, %rax
movq 0x50(%rsp), %r9
shrq %cl, %r9
movq 0x20a0(%rsp), %rdi
leaq 0x31fd(%rip), %rsi      # 0x109c1
movq 0x20(%rsp), %rdx
movq %rax, %rcx
movq %rbp, %r8
jmp 0xd833
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0xdd00
cmpl $0x0, 0x4(%rsp)
je 0xd547
leaq 0x60(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl %eax, %edx
callq 0x2ff3
jmp 0xd547
movq 0x50(%rsp), %rax
movq 0x40(%rsp), %rcx
shrq %cl, %rax
movq 0x58(%rsp), %r9
shrq %cl, %r9
movq 0x20a0(%rsp), %rdi
leaq 0x31b0(%rip), %rsi      # 0x109d8
movq %rbp, %rdx
movq %rax, %rcx
movq 0x20(%rsp), %r8
xorl %eax, %eax
callq 0x2230
incq 0x28(%rsp)
jmp 0xd547
movq 0x77ad(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
leaq 0x3247(%rip), %rsi      # 0x10a9c
leaq 0x3262(%rip), %rdx      # 0x10abe
xorl %ebx, %ebx
movq 0x28(%rsp), %rcx
xorl %eax, %eax
callq 0x2230
movl (%r14), %eax
testl %eax, %eax
movq 0x48(%rsp), %r13
je 0xd8b0
xorl %r15d, %r15d
movq 0x10(%r14), %rcx
movq %r15, %rdx
shrq $0x4, %rdx
movl (%rcx,%rdx,4), %edx
movl %ebx, %ecx
andb $0x1e, %cl
shrl %cl, %edx
testb $0x3, %dl
jne 0xd8a3
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %rdi
callq 0x2060
movl (%r14), %eax
incq %r15
movl %eax, %ecx
addl $0x2, %ebx
cmpq %rcx, %r15
jb 0xd879
movq 0x18(%r14), %rsi
xorl %edi, %edi
callq 0x40db
movq 0x10(%r14), %rsi
xorl %edi, %edi
callq 0x40db
movq 0x20(%r14), %rsi
xorl %edi, %edi
callq 0x40db
xorl %edi, %edi
movq %r14, %rsi
callq 0x40db
movq %r12, %rdi
callq 0x36a5
movq 0x10(%rsp), %rdi
callq 0x52fd
movq %r13, %rdi
callq 0x525f
addq $0x2068, %rsp           # imm = 0x2068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x3034