// File: /workspace/github_c_makefile_star2_O3/c0stya[P]fslib/src/match.c
// Function: match_half_sorted
void match_half_sorted(
                struct _arc * a,
                struct _arc * b,
                arc_t M,
                arc_t N,
                struct _queue * q) 
{
    arc_t l, h, ll, hh;
    arc_t i,m;

    struct _match_item mi;

    for (i=0; i < M; ++i) {
        l = 0;
        h = N-1;
        while ( l <= h ) {
            m = (l + h) >> 1;
            if (a[i].olabel > b[m].ilabel) l = m + 1; 
            else  
                if (a[i].olabel < b[m].ilabel) {
                    if (m == 0) break;  // sentinel for unsigned index h
                    h = m - 1;
                }
                else {
                    ll = hh = m;
                    
                    while ((ll > l) && (a[i].olabel == b[ll-1].ilabel)) --ll;
                    while ((hh < h) && (a[i].olabel == b[hh+1].ilabel)) ++hh;

                    while (ll <= hh ) {
                        mi.a = a[i]; 
                        mi.b = b[ll];
                        if (_match(a, b, i, ll))
                            queue_enque(q, &mi);
                        ++ll;
                    }
                    break;
                }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, -0x58(%rbp)
movl %ecx, -0x2c(%rbp)
movq %rdi, -0x38(%rbp)
testl %edx, %edx
je 0x42a7
movq %rsi, %r15
decl -0x2c(%rbp)
movl %edx, %eax
movq %rax, -0x50(%rbp)
leaq -0x8(%rsi), %rax
movq %rax, -0x40(%rbp)
leaq 0x18(%rsi), %rax
movq %rax, -0x48(%rbp)
xorl %r13d, %r13d
movq %r13, %rax
shlq $0x4, %rax
movq -0x38(%rbp), %rcx
leaq (%rcx,%rax), %rdx
movq %rdx, -0x60(%rbp)
movl 0xc(%rcx,%rax), %ecx
xorl %edi, %edi
movl -0x2c(%rbp), %edx
leal (%rdi,%rdx), %r8d
movl %r8d, %esi
shrl %esi
movq %rsi, %r9
shlq $0x4, %r9
cmpl 0x8(%r15,%r9), %ecx
jbe 0x41c0
incl %esi
movl %esi, %edi
jmp 0x41d0
jae 0x41d9
cmpl $0x2, %r8d
jb 0x429a
decl %esi
movl %esi, %edx
cmpl %edx, %edi
jbe 0x41a3
jmp 0x429a
movl %esi, %r12d
cmpl %edi, %esi
jbe 0x4202
movq %rsi, %r8
shlq $0x4, %r8
addq -0x40(%rbp), %r8
movl %esi, %r12d
cmpl (%r8), %ecx
jne 0x4202
decl %r12d
addq $-0x10, %r8
cmpl %r12d, %edi
jb 0x41ee
movl %edi, %r12d
cmpl %esi, %edx
cmovbel %esi, %edx
leal (%rdx,%rsi), %edi
subl %esi, %edi
negl %edx
movl %esi, %ebx
decl %ebx
shlq $0x4, %rsi
addq -0x48(%rbp), %rsi
leal (%rdx,%rbx), %r8d
cmpl $-0x1, %r8d
je 0x4233
incl %ebx
leaq 0x10(%rsi), %r8
cmpl (%rsi), %ecx
movq %r8, %rsi
je 0x421a
jmp 0x4235
movl %edi, %ebx
cmpl %ebx, %r12d
ja 0x429a
movq -0x38(%rbp), %rcx
leaq (%rcx,%rax), %r14
addq $0xc, %r14
movq -0x60(%rbp), %rax
movups (%rax), %xmm0
movaps %xmm0, -0x80(%rbp)
movl %r12d, %eax
shlq $0x4, %rax
movups (%r15,%rax), %xmm0
leaq -0x70(%rbp), %rax
movups %xmm0, (%rax)
cmpl $0x0, (%r14)
jne 0x4285
testq %r13, %r13
setne %al
testl %r12d, %r12d
setne %cl
andb %al, %cl
movl %r12d, %eax
orl %r13d, %eax
sete %al
orb %cl, %al
jne 0x4292
movq -0x58(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2e1c
incl %r12d
cmpl %ebx, %r12d
jbe 0x4246
incq %r13
cmpq -0x50(%rbp), %r13
jne 0x4187
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq