// File: chhylp123[P]hifiasm/inter.cpp
// Function: cc_bub_match(ul_ov_t*, long)
uint64_t cc_bub_match(ul_ov_t *ch, int64_t ch_n) {
	if(ch_n == 0) return 0;
    int64_t i, j, k;

    radix_sort_ul_ov_srt_qs(ch, ch + ch_n);
	for (i = 1, j = 0; i <= ch_n; i++) {
        if (i == ch_n || ch[i].qs != ch[j].qs) {
            if(i - j > 1) radix_sort_ul_ov_srt_qe(ch+j, ch+i);
            j = i;
        }
    }

	for (i = k = 0; i < ch_n; ++i) {
		if(ch[i].tn == (uint32_t)-1) continue;
		for (j = i + 1; j < ch_n && ch[i].qe >= ch[j].qs; j++) {
			if(ch[j].tn == (uint32_t)-1) continue;
			if((ch[i].qe == ch[j].qs) && (ch[i].rev == ch[j].rev) && (ch[i].qn == ch[j].qn)) {
				if(!ch[i].rev) {
					if(ch[i].te == ch[j].ts) {
						ch[i].qe = ch[j].qe;
						ch[i].te = ch[j].te;
						ch[j].tn = (uint32_t)-1;
					}
				} else {
					if(ch[j].te == ch[i].ts) {
						ch[i].qe = ch[j].qe;
						ch[i].ts = ch[j].ts;
						ch[j].tn = (uint32_t)-1;
					}
				}
			}
		}

		ch[k++] = ch[i];
	}

	return k;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x2dfe44
movq $0x0, -0x8(%rbp)
jmp 0x2e0152
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
imulq $0x1c, -0x18(%rbp), %rax
addq %rax, %rsi
callq 0x27b890
movq $0x1, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jg 0x2dfee0
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x2dfe9d
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
imulq $0x1c, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
je 0x2dfed0
movq -0x20(%rbp), %rax
subq -0x28(%rbp), %rax
cmpq $0x1, %rax
jle 0x2dfec8
movq -0x10(%rbp), %rdi
imulq $0x1c, -0x28(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
imulq $0x1c, -0x20(%rbp), %rax
addq %rax, %rsi
callq 0x27b350
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x2dfed2
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2dfe69
movq $0x0, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x2e014a
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
jne 0x2dff15
jmp 0x2e0139
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x31(%rbp)
jge 0x2dff54
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
imulq $0x1c, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
setae %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x2dff60
jmp 0x2e00f7
movq -0x10(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
jne 0x2dff77
jmp 0x2e00e6
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
imulq $0x1c, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0x2e00e4
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
movq -0x10(%rbp), %rcx
imulq $0x1c, -0x28(%rbp), %rdx
addq %rdx, %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
cmpl %ecx, %eax
jne 0x2e00e4
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
imulq $0x1c, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0x2e00e4
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x2e0071
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x10(%rbp), %rcx
imulq $0x1c, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jne 0x2e006f
movq -0x10(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %ecx
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
jmp 0x2e00e2
movq -0x10(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x10(%rbp), %rcx
imulq $0x1c, -0x20(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jne 0x2e00e0
movq -0x10(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x10(%rbp), %rax
imulq $0x1c, -0x20(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
jmp 0x2e00e2
jmp 0x2e00e4
jmp 0x2e00e6
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2dff21
movq -0x10(%rbp), %rcx
imulq $0x1c, -0x20(%rbp), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2dfef0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)