// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x2, %rcx
cmpq %rcx, %rax
jae 0x2a2d
movq -0x20(%rbp), %rax
cmpl $0x400, (%rax)          # imm = 0x400
ja 0x2a2d
movq -0x20(%rbp), %rdi
callq 0x3260
jmp 0x2a3f
movq -0x20(%rbp), %rdi
callq 0x3130
callq 0x3180
movq %rax, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movslq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x2e83
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rdx
movabsq $0x3ffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFF
andq (%rdx), %rcx
movslq -0x28(%rbp), %rdx
addq %rdx, %rcx
movq -0x8(%rbp), %rdx
andq 0x10(%rdx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x2ac3
jmp 0x2e75
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2b8d
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0xc0, %eax
cmpl $0x0, %eax
je 0x2b8d
movq -0x38(%rbp), %rax
movb $0x0, 0x9(%rax)
movq -0x38(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x2b2a
movq -0x38(%rbp), %rax
movb $0x1, 0x9(%rax)
jmp 0x2b8b
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x2b89
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x2b53
movq -0x38(%rbp), %rax
movb $0x1, 0x9(%rax)
jmp 0x2b87
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x2b85
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x40, %eax
cmpl $0x0, %eax
je 0x2b85
movq -0x38(%rbp), %rax
movb $0x1, 0x9(%rax)
jmp 0x2b87
jmp 0x2b89
jmp 0x2b8b
jmp 0x2b9d
movq -0x38(%rbp), %rax
movb $0x1, 0x9(%rax)
movq -0x38(%rbp), %rax
movb $0x0, 0x8(%rax)
movq -0x38(%rbp), %rax
cmpb $0x0, 0x9(%rax)
je 0x2e73
cmpl $0x1, -0x24(%rbp)
jne 0x2c1d
movq $0x0, -0x68(%rbp)
movq -0x40(%rbp), %rdi
leaq 0x10596(%rip), %rsi     # 0x1315a
callq 0x10e60
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x2c02
movq -0x68(%rbp), %rdi
callq 0x112c0
movq %rax, %rdi
callq 0x32e0
movq %rax, -0xb0(%rbp)
jmp 0x2c0d
xorl %eax, %eax
movq %rax, -0xb0(%rbp)
jmp 0x2c0d
movq -0xb0(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x2d04
cmpl $0x2, -0x24(%rbp)
jne 0x2cf3
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x2150
movl %eax, -0x7c(%rbp)
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
xorl %eax, %eax
cmpq -0x78(%rbp), %rcx
movb %al, -0xb1(%rbp)
jb 0x2c8b
callq 0x2430
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0xb1(%rbp)
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x2c97
jmp 0x2ca7
jmp 0x2c99
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x2c52
movq -0x70(%rbp), %rdx
movq -0x78(%rbp), %rsi
xorl %eax, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmoval %ecx, %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x2cdb
movq -0x70(%rbp), %rdi
addq $0x1, %rdi
callq 0x32e0
movq %rax, -0xc0(%rbp)
jmp 0x2ce6
xorl %eax, %eax
movq %rax, -0xc0(%rbp)
jmp 0x2ce6
movq -0xc0(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x2d02
movq $0x0, -0x50(%rbp)
movl $0x0, -0x58(%rbp)
jmp 0x2d04
movq -0x38(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x2d45
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x30, %rax
movl %eax, %edi
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x18, %rax
andq $0xff, %rax
cltq
addq %rax, %rsi
callq 0xd020
movl %eax, -0x5c(%rbp)
jmp 0x2d76
movq -0x40(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jle 0x2d5e
movq -0x40(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0xc4(%rbp)
jmp 0x2d6d
movq -0x40(%rbp), %rcx
xorl %eax, %eax
subl 0x1c(%rcx), %eax
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %edi
callq 0x3350
movl %eax, %eax
xorq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x33b0
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x2db6
movq 0x145c7(%rip), %rax     # 0x17370
addq $0x1, %rax
movq %rax, 0x145bc(%rip)     # 0x17370
jmp 0x2dc8
movq 0x145bb(%rip), %rax     # 0x17378
addq $0x1, %rax
movq %rax, 0x145b0(%rip)     # 0x17378
cmpl $0x0, -0x2c(%rbp)
jne 0x2e71
cmpl $0x0, -0x58(%rbp)
je 0x2dec
movq 0x145a1(%rip), %rax     # 0x17380
addq $0x1, %rax
movq %rax, 0x14596(%rip)     # 0x17380
jmp 0x2dfe
movq 0x14595(%rip), %rax     # 0x17388
addq $0x1, %rax
movq %rax, 0x1458a(%rip)     # 0x17388
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x20, %rcx
andq $0xffff, %rcx           # imm = 0xFFFF
orl $0x400, %ecx            # imm = 0x400
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
shlq $0x20, %rdx
movabsq $-0xffff00000001, %rsi  # imm = 0xFFFF0000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
cmpb $0x0, 0x8(%rax)
je 0x2e6f
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x48(%rbp), %rdi
callq 0x23f0
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
leaq -0x2c(%rbp), %rdx
callq 0x36e0
jmp 0x2e71
jmp 0x2e73
jmp 0x2e75
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2a46
movl $0x0, -0x28(%rbp)
movslq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x2fb9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rdx
movabsq $0x3ffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFF
andq (%rdx), %rcx
movslq -0x28(%rbp), %rdx
addq %rdx, %rcx
movq -0x8(%rbp), %rdx
andq 0x10(%rdx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x88(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
je 0x2fa9
movq -0x88(%rbp), %rax
cmpb $0x0, 0x9(%rax)
jne 0x2fa9
movq -0x18(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x3a10
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x2fa7
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x20, %rcx
andq $0xffff, %rcx           # imm = 0xFFFF
orl $0x400, %ecx            # imm = 0x400
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
shlq $0x20, %rdx
movabsq $-0xffff00000001, %rsi  # imm = 0xFFFF0000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x9c(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x2040
movq -0x18(%rbp), %rdi
movl -0x9c(%rbp), %esi
callq 0x3b70
jmp 0x2fa9
jmp 0x2fab
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2e8a
jmp 0x2fbb
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2ffa
movq -0x8(%rbp), %rdi
callq 0x3bf0
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
movq -0xa8(%rbp), %rax
movq (%rax), %rsi
callq 0xd650
movq -0xa8(%rbp), %rax
movq (%rax), %rdi
callq 0xce80
jmp 0x2fbb
movq -0x20(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)