// File: /workspace/github_c_makefile_star2_O1/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 0x40c0
movq %rax, %r14
movq %r13, %rdi
xorl %esi, %esi
callq 0x5df2
movq %rax, %r13
movq %rax, %rdi
testq %r12, %r12
jne 0xd32e
callq 0x6398
jmp 0xd33b
movq %r12, %rsi
movl $0x1, %edx
callq 0x6814
movq %rax, 0x10(%rsp)
movq %r13, 0x48(%rsp)
movq %r15, %rdi
callq 0x3627
testq %rax, %rax
je 0xd739
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 0x375f
testq %rax, %rax
je 0xd67b
movq %rax, %rbp
movq %rax, %rdi
callq 0x3604
testl %eax, %eax
jne 0xd37e
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 0xd4fb
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 0x36e8(%rip), %rsi      # 0x10af2
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 0xd37e
movzbl 0x2(%rsp), %eax
cmpl %r13d, %eax
jl 0xd37e
movq 0x48(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1060(%rsp), %rsi
callq 0x57b5
movl 0xc(%rsp), %edx
movq 0x10(%rsp), %rdi
movl %eax, %esi
leaq 0x34(%rsp), %rcx
leaq 0x58(%rsp), %r8
movl 0x1c(%rsp), %r9d
callq 0x7bc0
movl %eax, 0x20(%rsp)
movq %rbp, %rdi
leaq 0x60(%rsp), %rsi
callq 0x57b5
movl 0x8(%rsp), %edx
movq 0x10(%rsp), %rdi
movl %eax, %esi
leaq 0x30(%rsp), %rcx
leaq 0x50(%rsp), %r8
movl 0x1c(%rsp), %r9d
callq 0x7bc0
movl 0x20(%rsp), %ecx
testl %ecx, %ecx
je 0xd528
cmpl $0x1, %ecx
je 0xd56c
cmpl $0x2, %ecx
jne 0xd37e
movq 0x7b1d(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r8d
leaq 0x34bc(%rip), %rsi      # 0x109a6
leaq 0x35e3(%rip), %rdx      # 0x10ad4
leaq 0x1060(%rsp), %rcx
jmp 0xd560
shrq $0x12, %rcx
movq 0x7af2(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
leaq 0x343c(%rip), %rsi      # 0x1094c
leaq 0x35bd(%rip), %rdx      # 0x10ad4
movq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0x2230
jmp 0xd3dc
testl %eax, %eax
je 0xd5a5
cmpl $0x1, %eax
je 0xd608
cmpl $0x2, %eax
jne 0xd37e
movq 0x7ab3(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
movl 0x8(%rsp), %r8d
leaq 0x3452(%rip), %rsi      # 0x109a6
leaq 0x3579(%rip), %rdx      # 0x10ad4
leaq 0x60(%rsp), %rcx
xorl %eax, %eax
callq 0x2230
jmp 0xd37e
movq %r14, %rdi
leaq 0x1060(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0xdb26
cmpl $0x0, 0x4(%rsp)
je 0xd37e
leaq 0x1060(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl %eax, %edx
callq 0x2ffc
jmp 0xd37e
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 0xd63b
movq 0x58(%rsp), %rax
movq 0x40(%rsp), %rcx
shrq %cl, %rax
movq 0x50(%rsp), %r9
shrq %cl, %r9
movq 0x20a0(%rsp), %rdi
leaq 0x33dc(%rip), %rsi      # 0x109d7
movq 0x20(%rsp), %rdx
movq %rax, %rcx
movq %rbp, %r8
jmp 0xd66a
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0xdb26
cmpl $0x0, 0x4(%rsp)
je 0xd37e
leaq 0x60(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl %eax, %edx
callq 0x303d
jmp 0xd37e
movq 0x50(%rsp), %rax
movq 0x40(%rsp), %rcx
shrq %cl, %rax
movq 0x58(%rsp), %r9
shrq %cl, %r9
movq 0x20a0(%rsp), %rdi
leaq 0x338f(%rip), %rsi      # 0x109ee
movq %rbp, %rdx
movq %rax, %rcx
movq 0x20(%rsp), %r8
xorl %eax, %eax
callq 0x2230
incq 0x28(%rsp)
jmp 0xd37e
movq 0x7976(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
leaq 0x3426(%rip), %rsi      # 0x10ab2
leaq 0x3441(%rip), %rdx      # 0x10ad4
xorl %ebx, %ebx
movq 0x28(%rsp), %rcx
xorl %eax, %eax
callq 0x2230
cmpl $0x0, (%r14)
movq 0x48(%rsp), %r13
je 0xd6e2
xorl %r15d, %r15d
movq 0x10(%r14), %rax
movl %r15d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
movl %ebx, %ecx
andb $0x1e, %cl
shrl %cl, %eax
testb $0x3, %al
jne 0xd6d4
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %rdi
callq 0x2060
incq %r15
movl (%r14), %eax
addl $0x2, %ebx
cmpq %rax, %r15
jb 0xd6af
movq 0x18(%r14), %rsi
xorl %edi, %edi
callq 0x4162
movq 0x10(%r14), %rsi
xorl %edi, %edi
callq 0x4162
movq 0x20(%r14), %rsi
xorl %edi, %edi
callq 0x4162
xorl %edi, %edi
movq %r14, %rsi
callq 0x4162
movq %r12, %rdi
callq 0x36fd
movq 0x10(%rsp), %rdi
callq 0x5398
movq %r13, %rdi
callq 0x52fc
addq $0x2068, %rsp           # imm = 0x2068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x307e