// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/juicer.c
// Function: make_juicer_pre_file_from_bed
static int make_juicer_pre_file_from_bed(char *f, char *agp, char *fai, uint8_t mq, int scale, int count_gap, FILE *fo)
{
    iostream_t *fp;
    char *line;
    char cname0[4096], cname1[4096], rname0[4096], rname1[4096];
    uint32_t s0, s1, e0, e1, i0, i1;
    uint64_t p0, p1, rec_c, pair_c;
    uint8_t q0, q1;
    int8_t buff;
    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;
    buff = 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);
    
        if (buff == 0) {
            cname0[0] = rname0[0] = '\0';
            s0 = e0 = UINT32_MAX;
            q0 = 255;
            sscanf(line, "%s %u %u %s %hhu", cname0, &s0, &e0, rname0, &q0);
            ++buff;
        } else if (buff == 1) {
            cname1[0] = rname1[0] = '\0';
            s1 = e1 = UINT32_MAX;
            q1 = 255;
            sscanf(line, "%s %u %u %s %hhu", cname1, &s1, &e1, rname1, &q1);
            if (is_read_pair(rname0, rname1)) {
                buff = 0;

                if (q0 < mq || q1 < mq)
                    continue;
                
                err0 = sd_coordinate_conversion(dict, sd_get(sdict, cname0), s0 / 2 + e0 / 2 + (s0 & 1 && e0 & 1), &i0, &p0, count_gap);
                err1 = sd_coordinate_conversion(dict, sd_get(sdict, cname1), s1 / 2 + e1 / 2 + (s1 & 1 && e1 & 1), &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, s0 / 2 + e0 / 2 + (s0 & 1 && e0 & 1));
                    }
                } 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, s1 / 2 + e1 / 2 + (s1 & 1 && e1 & 1));
                    }
                } 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;
                }
            } else {
                buff = 1;
            
                strcpy(cname0, cname1);
                s0 = s1;
                e0 = e1;
                q0 = q1;
                strcpy(rname0, rname1);
            }
        }
    }

    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
movq %rsp, %rbp
subq $0x4130, %rsp           # imm = 0x4130
movb %cl, %al
movq 0x10(%rbp), %rcx
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb %al, -0x19(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
callq 0x111a0
movq %rax, -0x4090(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x72b0
movq %rax, -0x40a0(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xfbab
movq -0x40a0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x81b0
movq %rax, -0x40b0(%rbp)
jmp 0xfbbe
movq -0x40a0(%rbp), %rdi
callq 0x7950
movq %rax, -0x40b0(%rbp)
movq -0x40b0(%rbp), %rax
movq %rax, -0x40a8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2c80
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xfc0d
movq 0x8411(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rcx
leaq 0x383b(%rip), %rsi      # 0x13430
leaq 0x4c07(%rip), %rdx      # 0x14803
movb $0x0, %al
callq 0x2230
movl $0x1, %edi
callq 0x23e0
movq $0x0, -0x4078(%rbp)
movq $0x0, -0x4070(%rbp)
movb $0x0, -0x407b(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2f00
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x10341
movq -0x38(%rbp), %rdi
callq 0x2c20
cmpl $0x0, %eax
je 0xfc51
jmp 0xfc2a
movq -0x4070(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4070(%rbp)
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0xfcad
movq 0x837e(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
movq -0x4070(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x4078(%rbp), %r8
leaq 0x4a2d(%rip), %rsi      # 0x146cc
leaq 0x4b5d(%rip), %rdx      # 0x14803
movb $0x0, %al
callq 0x2230
movsbl -0x407b(%rbp), %eax
cmpl $0x0, %eax
jne 0xfd2e
movb $0x0, -0x3040(%rbp)
movb $0x0, -0x1040(%rbp)
movl $0xffffffff, -0x404c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x4044(%rbp) # imm = 0xFFFFFFFF
movb $-0x1, -0x4079(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x1040(%rbp), %rdx
leaq -0x3040(%rbp), %r9
leaq 0x4b26(%rip), %rsi      # 0x14821
leaq -0x4044(%rbp), %rcx
leaq -0x404c(%rbp), %r8
leaq -0x4079(%rbp), %rax
movq %rax, (%rsp)
movb $0x0, %al
callq 0x22c0
movb -0x407b(%rbp), %al
addb $0x1, %al
movb %al, -0x407b(%rbp)
jmp 0x1033c
movsbl -0x407b(%rbp), %eax
cmpl $0x1, %eax
jne 0x1033a
movb $0x0, -0x4040(%rbp)
movb $0x0, -0x2040(%rbp)
movl $0xffffffff, -0x4050(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x4048(%rbp) # imm = 0xFFFFFFFF
movb $-0x1, -0x407a(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x2040(%rbp), %rdx
leaq -0x4040(%rbp), %r9
leaq 0x4aa1(%rip), %rsi      # 0x14821
leaq -0x4048(%rbp), %rcx
leaq -0x4050(%rbp), %r8
leaq -0x407a(%rbp), %rax
movq %rax, (%rsp)
movb $0x0, %al
callq 0x22c0
leaq -0x3040(%rbp), %rdi
leaq -0x4040(%rbp), %rsi
callq 0x28c0
cmpb $0x0, %al
je 0x102e7
movb $0x0, -0x407b(%rbp)
movzbl -0x4079(%rbp), %eax
movzbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jl 0xfde0
movzbl -0x407a(%rbp), %eax
movzbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0xfde5
jmp 0xfc2a
movq -0x40a8(%rbp), %rax
movq %rax, -0x40c8(%rbp)
movq -0x40a0(%rbp), %rdi
leaq -0x1040(%rbp), %rsi
callq 0x6a60
movl %eax, -0x40bc(%rbp)
movl -0x4044(%rbp), %eax
shrl %eax
movl -0x404c(%rbp), %ecx
shrl %ecx
addl %ecx, %eax
movl %eax, -0x40b8(%rbp)
movl -0x4044(%rbp), %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x40b1(%rbp)
je 0xfe4f
movl -0x404c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x40b1(%rbp)
movl -0x40bc(%rbp), %esi
movq -0x40c8(%rbp), %rdi
movl -0x40b8(%rbp), %edx
movb -0x40b1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, %edx
movl -0x24(%rbp), %r9d
leaq -0x4054(%rbp), %rcx
leaq -0x4060(%rbp), %r8
callq 0x95d0
movl %eax, -0x4080(%rbp)
movq -0x40a8(%rbp), %rax
movq %rax, -0x40e0(%rbp)
movq -0x40a0(%rbp), %rdi
leaq -0x2040(%rbp), %rsi
callq 0x6a60
movl %eax, -0x40d4(%rbp)
movl -0x4048(%rbp), %eax
shrl %eax
movl -0x4050(%rbp), %ecx
shrl %ecx
addl %ecx, %eax
movl %eax, -0x40d0(%rbp)
movl -0x4048(%rbp), %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x40c9(%rbp)
je 0xfef6
movl -0x4050(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x40c9(%rbp)
movl -0x40d4(%rbp), %esi
movq -0x40e0(%rbp), %rdi
movl -0x40d0(%rbp), %edx
movb -0x40c9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, %edx
movl -0x24(%rbp), %r9d
leaq -0x4058(%rbp), %rcx
leaq -0x4068(%rbp), %r8
callq 0x95d0
movl %eax, -0x4084(%rbp)
cmpl $0x0, -0x4080(%rbp)
je 0x1006f
cmpl $0x1, -0x4080(%rbp)
jne 0xffc1
movq -0x4090(%rbp), %rdi
leaq -0x1040(%rbp), %rsi
leaq -0x4098(%rbp), %rdx
callq 0x11290
movl %eax, -0x4094(%rbp)
cmpl $0x0, -0x4098(%rbp)
je 0xffbc
leaq -0x1040(%rbp), %rdi
callq 0x2430
movq %rax, %rdx
movq -0x4090(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4094(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq 0x805b(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq -0x1040(%rbp), %rcx
leaq 0x4756(%rip), %rsi      # 0x14704
leaq 0x484e(%rip), %rdx      # 0x14803
movb $0x0, %al
callq 0x2230
jmp 0x1006a
cmpl $0x2, -0x4080(%rbp)
jne 0x10068
movq 0x8023(%rip), %rax      # 0x17ff8
movq (%rax), %rax
movq %rax, -0x40f8(%rbp)
leaq -0x1040(%rbp), %rax
movq %rax, -0x40f0(%rbp)
movl -0x4044(%rbp), %eax
shrl %eax
movl -0x404c(%rbp), %ecx
shrl %ecx
addl %ecx, %eax
movl %eax, -0x40e8(%rbp)
movl -0x4044(%rbp), %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x40e1(%rbp)
je 0x10030
movl -0x404c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x40e1(%rbp)
movq -0x40f0(%rbp), %rcx
movq -0x40f8(%rbp), %rdi
movl -0x40e8(%rbp), %r8d
movb -0x40e1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, %r8d
leaq 0x46cc(%rip), %rsi      # 0x14726
leaq 0x47a2(%rip), %rdx      # 0x14803
movb $0x0, %al
callq 0x2230
jmp 0x1006a
jmp 0x102e5
cmpl $0x0, -0x4084(%rbp)
je 0x101ab
cmpl $0x1, -0x4084(%rbp)
jne 0x100fd
movq -0x4090(%rbp), %rdi
leaq -0x2040(%rbp), %rsi
leaq -0x4098(%rbp), %rdx
callq 0x11290
movl %eax, -0x4094(%rbp)
cmpl $0x0, -0x4098(%rbp)
je 0x100f8
leaq -0x2040(%rbp), %rdi
callq 0x2430
movq %rax, %rdx
movq -0x4090(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4094(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq 0x7f1f(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq -0x2040(%rbp), %rcx
leaq 0x461a(%rip), %rsi      # 0x14704
leaq 0x4712(%rip), %rdx      # 0x14803
movb $0x0, %al
callq 0x2230
jmp 0x101a6
cmpl $0x2, -0x4084(%rbp)
jne 0x101a4
movq 0x7ee7(%rip), %rax      # 0x17ff8
movq (%rax), %rax
movq %rax, -0x4110(%rbp)
leaq -0x2040(%rbp), %rax
movq %rax, -0x4108(%rbp)
movl -0x4048(%rbp), %eax
shrl %eax
movl -0x4050(%rbp), %ecx
shrl %ecx
addl %ecx, %eax
movl %eax, -0x4100(%rbp)
movl -0x4048(%rbp), %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x40f9(%rbp)
je 0x1016c
movl -0x4050(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x40f9(%rbp)
movq -0x4108(%rbp), %rcx
movq -0x4110(%rbp), %rdi
movl -0x4100(%rbp), %r8d
movb -0x40f9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, %r8d
leaq 0x4590(%rip), %rsi      # 0x14726
leaq 0x4666(%rip), %rdx      # 0x14803
movb $0x0, %al
callq 0x2230
jmp 0x101a6
jmp 0x102e3
movq -0x40a8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4054(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x40a8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4058(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x2210
cmpl $0x0, %eax
jg 0x1025f
movq 0x10(%rbp), %rdi
movq -0x40a8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4054(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x4060(%rbp), %rax
movl -0x20(%rbp), %ecx
shrq %cl, %rax
movq %rax, -0x4118(%rbp)
movq -0x40a8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4058(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %r8
movq -0x4068(%rbp), %r9
movl -0x20(%rbp), %eax
movl %eax, %ecx
shrq %cl, %r9
movq -0x4118(%rbp), %rcx
leaq 0x4501(%rip), %rsi      # 0x14757
movb $0x0, %al
callq 0x2230
jmp 0x102d1
movq 0x10(%rbp), %rdi
movq -0x40a8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4058(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x4068(%rbp), %rax
movl -0x20(%rbp), %ecx
shrq %cl, %rax
movq %rax, -0x4120(%rbp)
movq -0x40a8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4054(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %r8
movq -0x4060(%rbp), %r9
movl -0x20(%rbp), %eax
movl %eax, %ecx
shrq %cl, %r9
movq -0x4120(%rbp), %rcx
leaq 0x44a4(%rip), %rsi      # 0x1476e
movb $0x0, %al
callq 0x2230
movq -0x4078(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4078(%rbp)
jmp 0x102e5
jmp 0x10338
movb $0x1, -0x407b(%rbp)
leaq -0x1040(%rbp), %rdi
leaq -0x2040(%rbp), %rsi
callq 0x20a0
movl -0x4048(%rbp), %eax
movl %eax, -0x4044(%rbp)
movl -0x4050(%rbp), %eax
movl %eax, -0x404c(%rbp)
movb -0x407a(%rbp), %al
movb %al, -0x4079(%rbp)
leaq -0x3040(%rbp), %rdi
leaq -0x4040(%rbp), %rsi
callq 0x20a0
jmp 0x1033a
jmp 0x1033c
jmp 0xfc2a
movq 0x7cb0(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
movq -0x4078(%rbp), %rcx
leaq 0x44d9(%rip), %rsi      # 0x14832
leaq 0x44a3(%rip), %rdx      # 0x14803
movb $0x0, %al
callq 0x2230
movl $0x0, -0x4094(%rbp)
movl -0x4094(%rbp), %eax
movq -0x4090(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x103dd
movq -0x4090(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4094(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x4094(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x103ca
movq -0x4090(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4094(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x2050
jmp 0x103cc
movl -0x4094(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4094(%rbp)
jmp 0x10371
movq -0x4090(%rbp), %rdi
callq 0x116b0
movq -0x30(%rbp), %rdi
callq 0x2e20
movq -0x40a8(%rbp), %rdi
callq 0x63d0
movq -0x40a0(%rbp), %rdi
callq 0x62a0
xorl %eax, %eax
addq $0x4130, %rsp           # imm = 0x4130
popq %rbp
retq
nopw %cs:(%rax,%rax)