// File: /workspace/github_c_makefile_star2_O1/DReichLab[P]adna/ldup.c
// Function: process
static khash_t(64) *process(kdq_t(elem_t) *q, BGZF *fp, khash_t(s) *marked, khash_t(64) *aux, int bc_type)
{
	int i, absent;
	if (kh_n_buckets(aux) < kdq_size(q) * 4 && kh_n_buckets(aux) <= AUX_REALLOC_SIZE) {
		kh_clear(64, aux);
	} else {
		kh_destroy(64, aux);
		aux = kh_init(64);
	}
	for (i = 0; i < kdq_size(q); ++i) {
		elem_t *e = &kdq_at(q, i);
		bam1_t *b = e->b;
		char *qname = bam_get_qname(b);
		if (b->core.flag&0x800) continue;
		if ((b->core.flag&1) && (b->core.flag&(BAM_FREAD1|BAM_FREAD2))) { // PE
			e->is_left = 0, e->is_pe = 1;
			if (b->core.tid < b->core.mtid) e->is_left = 1;
			else if (b->core.tid == b->core.mtid) {
				if (b->core.pos < b->core.mpos) e->is_left = 1;
				else if (b->core.pos == b->core.mpos && (b->core.flag&BAM_FREAD1)) e->is_left = 1;
			}
		} else e->is_left = 1, e->is_pe = 0; // SE
		if (e->is_left) {
			uint64_t key;
			khint_t k;
			int has_BC, rlen;
			if (bc_type == AD_USE_BC) {
				const uint8_t *BC = 0;
				BC = bam_aux_get(b, "BC");
				has_BC = BC? 1 : 0;
				key = has_BC? X31_hash_string(bam_aux2Z(BC)) : 0;
			} else if (bc_type == AD_USE_NAME) {
				const char *p, *qname = bam_get_qname(b);
				int len;
				len = strlen(qname);
				for (p = qname + len - 1; p >= qname && !ispunct(*p); --p);
				has_BC = p > qname? 1 : 0;
				key = has_BC? X31_hash_string(p + 1) : 0;
			} else key = 0, has_BC = 0;
			if (!e->is_pe) rlen = bam_cigar2rlen(b->core.n_cigar, bam_get_cigar(b));
			else rlen = b->core.isize > 0? b->core.isize : -b->core.isize;
			key ^= __ac_Wang_hash(rlen);
			k = kh_put(64, aux, key, &absent);
			if (has_BC) ++lt_n_frags_BC;
			else ++lt_n_frags_noBC;
			if (!absent) {
				if (has_BC) ++lt_n_dups_BC;
				else ++lt_n_dups_noBC;
				b->core.flag |= BAM_FDUP;
				if (e->is_pe) kh_put(s, marked, strdup(qname), &absent);
			}
		}
	}
	for (i = 0; i < kdq_size(q); ++i) {
		elem_t *e = &kdq_at(q, i);
		bam1_t *b = e->b;
		char *qname = bam_get_qname(b);
		if (e->is_pe && !e->is_left) {
			khint_t k;
			k = kh_get(s, marked, qname);
			if (k != kh_end(marked)) {
				b->core.flag |= BAM_FDUP;
				free((char*)kh_key(marked, k));
				kh_del(s, marked, k);
			}
		}
	}
	while (kdq_size(q)) {
		elem_t *e;
		e = kdq_shift(elem_t, q);
		bam_write1(fp, e->b);
		bam_destroy1(e->b);
	}
	return aux;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, 0x28(%rsp)
movq %rcx, %r14
movq %rdx, 0x10(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, %r13
movl (%rcx), %eax
cmpq $0x400, %rax            # imm = 0x400
ja 0x2e1e
movq 0x8(%r13), %rcx
shlq $0x2, %rcx
cmpq %rax, %rcx
jbe 0x2e1e
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0x2e53
movl %eax, %ecx
shrl $0x2, %ecx
andl $0x1fc, %ecx            # imm = 0x1FC
cmpl $0x10, %eax
movl $0x4, %edx
cmovael %ecx, %edx
movl $0xaa, %esi
callq 0x21b0
movq $0x0, 0x4(%r14)
jmp 0x2e53
movq 0x18(%r14), %rdi
callq 0x2050
movq 0x10(%r14), %rdi
callq 0x2050
movq 0x20(%r14), %rdi
callq 0x2050
movq %r14, %rdi
callq 0x2050
movl $0x1, %edi
movl $0x28, %esi
callq 0x21f0
movq %rax, %r14
movabsq $0x3ffffffffffffff, %rbp # imm = 0x3FFFFFFFFFFFFFF
cmpq $0x0, 0x8(%r13)
movq %r13, 0x50(%rsp)
movq %r14, 0x18(%rsp)
je 0x3460
xorl %r12d, %r12d
movq 0x18(%r13), %r15
movq (%r13), %rax
andq %rbp, %rax
addq %r12, %rax
andq 0x10(%r13), %rax
shlq $0x4, %rax
movq (%r15,%rax), %r13
movl 0xc(%r13), %ecx
btl $0xb, %ecx
jb 0x32c3
addq %rax, %r15
movq 0x28(%r13), %rax
movq %rax, 0x20(%rsp)
testb $0x1, %cl
sete %al
testb $-0x40, %cl
sete %cl
orb %al, %cl
je 0x2ec2
movw $0x100, 0x8(%r15)       # imm = 0x100
jmp 0x2eef
movw $0x1, 0x8(%r15)
movl 0x14(%r13), %eax
cmpl %eax, (%r13)
jge 0x2eda
movb $0x1, 0x9(%r15)
jmp 0x2eef
jne 0x2eef
movl 0x18(%r13), %eax
cmpl %eax, 0x4(%r13)
jl 0x2ed3
jne 0x2eef
testb $0x40, 0xc(%r13)
jne 0x2ed3
cmpb $0x0, 0x9(%r15)
je 0x32c3
movl 0x28(%rsp), %eax
cmpl $0x2, %eax
je 0x2f71
cmpl $0x1, %eax
jne 0x2ffe
movq %r13, %rdi
leaq 0xb244(%rip), %rsi      # 0xe15a
callq 0xc663
testq %rax, %rax
setne %cl
je 0x3017
movq %rax, %rdi
callq 0xc9bd
movsbq (%rax), %rbp
movb $0x1, %cl
movq %rcx, 0x8(%rsp)
testq %rbp, %rbp
je 0x301c
movb 0x1(%rax), %cl
testb %cl, %cl
je 0x301e
addq $0x2, %rax
movq %rbp, %rdx
shlq $0x5, %rdx
subq %rbp, %rdx
movsbq %cl, %rbp
addq %rdx, %rbp
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x2f52
jmp 0x301e
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x2150
movslq %eax, %rcx
leaq (%rbx,%rcx), %rax
incq %rax
addq %rbx, %rcx
addq $0x2, %rcx
movq %rax, %r14
movq %rcx, %rbx
leaq -0x2(%rax), %rbp
cmpq 0x20(%rsp), %rbp
jb 0x2fbb
callq 0x2410
movq (%rax), %rdx
movsbq -0x2(%r14), %rsi
leaq -0x1(%r14), %rax
leaq -0x1(%rbx), %rcx
testb $0x4, (%rdx,%rsi,2)
je 0x2f8f
cmpq 0x20(%rsp), %rbp
seta %al
jbe 0x3009
movsbq -0x1(%r14), %rbp
movb $0x1, %al
movq %rax, 0x8(%rsp)
testq %rbp, %rbp
je 0x300e
movb (%r14), %al
testb %al, %al
je 0x3010
movq 0x18(%rsp), %r14
movq %rbp, %rcx
shlq $0x5, %rcx
subq %rbp, %rcx
movsbq %al, %rbp
addq %rcx, %rbp
movb (%rbx), %al
incq %rbx
testb %al, %al
jne 0x2fe2
jmp 0x301e
movq $0x0, 0x8(%rsp)
jmp 0x301c
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
movq 0x18(%rsp), %r14
jmp 0x301e
movq %rcx, 0x8(%rsp)
xorl %ebp, %ebp
cmpb $0x0, 0x8(%r15)
je 0x3032
movl 0x1c(%r13), %eax
movl %eax, %ebx
negl %ebx
cmovsl %eax, %ebx
jmp 0x304b
movq 0x8(%r13), %rsi
movq %rsi, %rdi
shrq $0x30, %rdi
shrl $0x18, %esi
addq 0x28(%r13), %rsi
callq 0x8e66
movl %eax, %ebx
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
jb 0x3074
movl (%r14), %eax
movl 0x4(%r14), %ecx
addl %ecx, %ecx
cmpl %eax, %ecx
movl $0x0, %esi
sbbl %esi, %esi
orl $0x1, %esi
addl %eax, %esi
movq %r14, %rdi
callq 0x3691
movl %ebx, %eax
shll $0xf, %eax
notl %eax
addl %ebx, %eax
movl %eax, %ecx
shrl $0xa, %ecx
xorl %eax, %ecx
leal (%rcx,%rcx,8), %eax
movl %eax, %ecx
shrl $0x6, %ecx
xorl %eax, %ecx
movl %ecx, %edx
shll $0xb, %edx
notl %edx
addl %ecx, %edx
movl %edx, %eax
shrl $0x10, %eax
xorl %edx, %eax
xorq %rbp, %rax
movl (%r14), %edi
leal -0x1(%rdi), %r8d
shrq $0x21, %rbp
xorl %eax, %ebp
movl %eax, %r11d
shll $0xb, %r11d
xorl %ebp, %r11d
movl %r8d, %esi
andl %r11d, %esi
movq 0x10(%r14), %rdx
movl %esi, %ecx
shrl $0x4, %ecx
movl (%rdx,%rcx,4), %r9d
leal (%rsi,%rsi), %ecx
shrl %cl, %r9d
testb $0x2, %r9b
jne 0x316c
movl %r11d, %ecx
shrl $0x3, %ecx
shll $0x3, %r11d
xorl %ecx, %r11d
orl $0x1, %r11d
andl %r8d, %r11d
movl %edi, %r9d
movl %esi, %r10d
movl %r10d, %ecx
shrl $0x4, %ecx
movl (%rdx,%rcx,4), %ebx
leal (%r10,%r10), %ecx
andl $0x1e, %ecx
movl %ebx, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0x3143
testb $0x1, %bpl
jne 0x312c
movq 0x18(%rsp), %r14
movq 0x18(%r14), %r14
movl %r10d, %ebp
cmpq %rax, (%r14,%rbp,8)
movq 0x18(%rsp), %r14
je 0x3143
btl %ecx, %ebx
cmovbl %r10d, %r9d
addl %r11d, %r10d
andl %r8d, %r10d
movl %r9d, %ecx
cmpl %esi, %r10d
jne 0x30f5
jmp 0x3145
movl %edi, %ecx
movl %ecx, %esi
cmpl %edi, %ecx
jne 0x316c
movl %r10d, %ecx
shrl $0x4, %ecx
movl (%rdx,%rcx,4), %esi
leal (%r10,%r10), %ecx
shrl %cl, %esi
cmpl %edi, %r9d
cmovel %r10d, %r9d
testb $0x2, %sil
cmovel %r10d, %r9d
movl %r9d, %esi
movl %esi, %edi
shrl $0x4, %edi
movl (%rdx,%rdi,4), %r8d
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %r8d, %r9d
shrl %cl, %r9d
testb $0x2, %r9b
movabsq $0x3ffffffffffffff, %rbp # imm = 0x3FFFFFFFFFFFFFF
jne 0x3261
testb $0x1, %r9b
jne 0x3288
cmpb $0x0, 0x8(%rsp)
leaq 0xf1ad(%rip), %rax      # 0x12358
leaq 0xf19e(%rip), %rcx      # 0x12350
cmovneq %rcx, %rax
leaq 0xf1ab(%rip), %rcx      # 0x12368
leaq 0xf19c(%rip), %rdx      # 0x12360
cmovneq %rdx, %rcx
incq (%rax)
incq (%rcx)
movabsq $0x40000000000, %rax    # imm = 0x40000000000
orq %rax, 0x8(%r13)
cmpb $0x0, 0x8(%r15)
je 0x32c3
movq 0x20(%rsp), %rdi
callq 0x23d0
movq %rax, %r8
movq 0x10(%rsp), %rbx
movl 0x8(%rbx), %eax
cmpl 0xc(%rbx), %eax
jb 0x3224
movl (%rbx), %eax
movl 0x4(%rbx), %ecx
addl %ecx, %ecx
cmpl %eax, %ecx
movl $0x0, %esi
sbbl %esi, %esi
orl $0x1, %esi
addl %eax, %esi
movq %rbx, %rdi
movq %r8, %r15
callq 0x389e
movq %r15, %r8
movl (%rbx), %esi
movsbl (%r8), %r15d
testl %r15d, %r15d
je 0x32da
movb 0x1(%r8), %al
testb %al, %al
je 0x32dd
movq %r8, %rcx
addq $0x2, %rcx
movl %r15d, %edx
shll $0x5, %edx
subl %r15d, %edx
movsbl %al, %r15d
addl %edx, %r15d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x3246
jmp 0x32dd
movq 0x18(%r14), %r9
movl $0x3, %r10d
shll %cl, %r10d
movl %esi, %ecx
movq %rax, (%r9,%rcx,8)
notl %r10d
andl %r10d, %r8d
movl %r8d, (%rdx,%rdi,4)
incl 0x4(%r14)
incl 0x8(%r14)
jmp 0x32a9
movq 0x18(%r14), %r9
movl $0x3, %r10d
shll %cl, %r10d
movl %esi, %ecx
movq %rax, (%r9,%rcx,8)
notl %r10d
andl %r10d, %r8d
movl %r8d, (%rdx,%rdi,4)
incl 0x4(%r14)
cmpb $0x0, 0x8(%rsp)
leaq 0xf0a3(%rip), %rax      # 0x12358
leaq 0xf094(%rip), %rcx      # 0x12350
cmovneq %rcx, %rax
incq (%rax)
incq %r12
movq 0x50(%rsp), %r13
cmpq %r12, 0x8(%r13)
ja 0x2e75
jmp 0x3460
xorl %r15d, %r15d
leal -0x1(%rsi), %edx
movl %r15d, %r9d
andl %edx, %r9d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movl %r9d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %eax
leal (%r9,%r9), %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x33d9
movl %r15d, %eax
shrl $0x3, %eax
shll $0x3, %r15d
xorl %eax, %r15d
orl $0x1, %r15d
andl %edx, %r15d
movq %rsi, 0x40(%rsp)
movl %esi, %ebp
movl %r9d, %r13d
movq %r8, 0x20(%rsp)
movq %rdi, 0x8(%rsp)
movq %r9, 0x38(%rsp)
movl %edx, 0x30(%rsp)
movl %r13d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %r14d
leal (,%r13,2), %ebx
andl $0x1e, %ebx
movl %r14d, %eax
movl %ebx, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x33a1
testb $0x1, %al
jne 0x338a
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r8, %rsi
callq 0x2200
movl 0x30(%rsp), %edx
movq 0x38(%rsp), %r9
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %r8
testl %eax, %eax
je 0x33a1
btl %ebx, %r14d
cmovbl %r13d, %ebp
addl %r15d, %r13d
andl %edx, %r13d
movl %ebp, %eax
cmpl %r9d, %r13d
jne 0x3337
jmp 0x33a6
movq 0x40(%rsp), %rax
movl %eax, %r9d
movq 0x40(%rsp), %rdx
cmpl %edx, %eax
movq 0x18(%rsp), %r14
jne 0x33d9
movl %r13d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %eax
leal (,%r13,2), %ecx
shrl %cl, %eax
cmpl %edx, %ebp
cmovel %r13d, %ebp
testb $0x2, %al
cmovel %r13d, %ebp
movl %ebp, %r9d
movl %r9d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %edx
leal (%r9,%r9), %ecx
andl $0x1e, %ecx
shrl %cl, %edx
testb $0x2, %dl
jne 0x342b
testb $0x1, %dl
movabsq $0x3ffffffffffffff, %rbp # imm = 0x3FFFFFFFFFFFFFF
je 0x32c3
movq 0x10(%rsp), %rdi
movq 0x18(%rdi), %rdx
movl %r9d, %esi
movq %r8, (%rdx,%rsi,8)
movl $0x3, %edx
shll %cl, %edx
notl %edx
movq 0x10(%rdi), %rcx
andl %edx, (%rcx,%rax,4)
incl 0x4(%rdi)
jmp 0x32c3
movq 0x10(%rsp), %rdi
movq 0x18(%rdi), %rdx
movl %r9d, %esi
movq %r8, (%rdx,%rsi,8)
movl $0x3, %edx
shll %cl, %edx
notl %edx
movq 0x10(%rdi), %rcx
andl %edx, (%rcx,%rax,4)
incl 0x4(%rdi)
incl 0x8(%rdi)
movabsq $0x3ffffffffffffff, %rbp # imm = 0x3FFFFFFFFFFFFFF
jmp 0x32c3
cmpq $0x0, 0x8(%r13)
movq 0x48(%rsp), %r12
movq 0x10(%rsp), %rbx
je 0x361e
xorl %edi, %edi
movq (%r13), %rax
andq %rbp, %rax
addq %rdi, %rax
andq 0x10(%r13), %rax
movq 0x18(%r13), %rcx
shlq $0x4, %rax
cmpb $0x0, 0x8(%rcx,%rax)
je 0x3607
leaq (%rcx,%rax), %rdx
cmpb $0x0, 0x9(%rdx)
jne 0x3607
movq %rdi, 0x28(%rsp)
movq (%rcx,%rax), %rcx
movl (%rbx), %edi
testl %edi, %edi
je 0x34ee
movq 0x28(%rcx), %r14
movsbl (%r14), %r12d
testl %r12d, %r12d
movq %rcx, 0x38(%rsp)
je 0x34f5
movb 0x1(%r14), %al
testb %al, %al
je 0x34f8
leaq 0x2(%r14), %rcx
movl %r12d, %edx
shll $0x5, %edx
subl %r12d, %edx
movsbl %al, %r12d
addl %edx, %r12d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x34d3
jmp 0x34f8
xorl %ebp, %ebp
jmp 0x35ad
xorl %r12d, %r12d
movq %rdi, 0x30(%rsp)
leal -0x1(%rdi), %r15d
movl %r12d, %edi
andl %r15d, %edi
movl %r12d, %eax
shrl $0x3, %eax
shll $0x3, %r12d
xorl %eax, %r12d
orl $0x1, %r12d
andl %r15d, %r12d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r8
movl %edi, %ebp
movl %edi, 0x20(%rsp)
movq %r8, 0x8(%rsp)
movl %ebp, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %r13d
leal (,%rbp,2), %ebx
andl $0x1e, %ebx
movl %r13d, %eax
movl %ebx, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x3588
testb $0x1, %al
jne 0x3575
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %rdi
movq %r14, %rsi
callq 0x2200
movq 0x8(%rsp), %r8
movl 0x20(%rsp), %edi
testl %eax, %eax
je 0x3588
addl %r12d, %ebp
andl %r15d, %ebp
cmpl %edi, %ebp
jne 0x352f
movq 0x30(%rsp), %rdi
movl %edi, %ebp
jmp 0x3599
movl %ebx, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
movq 0x30(%rsp), %rdi
cmovnel %edi, %ebp
movq 0x48(%rsp), %r12
movq 0x50(%rsp), %r13
movq 0x10(%rsp), %rbx
movq 0x38(%rsp), %rcx
cmpl %edi, %ebp
movq 0x28(%rsp), %rdi
je 0x3607
movabsq $0x40000000000, %rax    # imm = 0x40000000000
orq %rax, 0x8(%rcx)
movq 0x18(%rbx), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %rdi
callq 0x2050
movq 0x28(%rsp), %rdi
cmpl %ebp, (%rbx)
je 0x3607
movq 0x10(%rbx), %rax
movl %ebp, %edx
shrl $0x4, %edx
movl (%rax,%rdx,4), %esi
addl %ebp, %ebp
andl $0x1e, %ebp
movl %esi, %edi
movl %ebp, %ecx
shrl %cl, %edi
testb $0x3, %dil
movq 0x28(%rsp), %rdi
jne 0x3607
btsl %ebp, %esi
movl %esi, (%rax,%rdx,4)
decl 0x4(%rbx)
incq %rdi
cmpq %rdi, 0x8(%r13)
movabsq $0x3ffffffffffffff, %rbp # imm = 0x3FFFFFFFFFFFFFF
ja 0x3477
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x367d
movabsq $-0x400000000000000, %rbx # imm = 0xFC00000000000000
movq (%r13), %rcx
movq 0x18(%r13), %r14
movq %rcx, %r15
andq %rbp, %r15
leaq 0x1(%rcx), %rdx
andq %rbp, %rdx
andq %rbx, %rcx
shlq $0x4, %r15
andq 0x10(%r13), %rdx
orq %rcx, %rdx
movq %rdx, (%r13)
decq %rax
movq %rax, 0x8(%r13)
movq (%r14,%r15), %rsi
movq %r12, %rdi
callq 0x9204
movq (%r14,%r15), %rdi
callq 0x8d83
movq 0x8(%r13), %rax
testq %rax, %rax
jne 0x3631
movq 0x18(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq