// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: graph_bipartiteness(unsigned int*, unsigned int, unsigned char*, hc_links*, kvec_t_u32_warp*)
int graph_bipartiteness(uint32_t* b_a, uint32_t b_a_n, uint8_t *color, hc_links* link, kvec_t_u32_warp* stack)
{
    if(b_a_n == 0) return 0;
    uint32_t i, uID, cur, occ = 0, sucess = 0, c;
    for (i = 0; i < b_a_n; i++) color[b_a[i]>>1] = 8;
    stack->a.n = 0;
    kv_push(uint32_t, stack->a, b_a[0]>>1);
    while (stack->a.n > 0)
    {
        stack->a.n--;
        cur = stack->a.a[stack->a.n];
        if((color[cur] & 1) == 0) occ++;
        color[cur] |= 1;
        for (i = 0; i < link->a.a[cur].f.n; i++)
        {
            if(link->a.a[cur].f.a[i].del) continue;
            if(link->a.a[cur].f.a[i].dis != RC_0) continue;
            uID = link->a.a[cur].f.a[i].uID;
            if((color[uID] & 8) == 0) continue;
            if((color[uID] & 1) == 1) continue;
            kv_push(uint32_t, stack->a, uID);
        }
    }
    if(occ != b_a_n) goto Failed;

    sucess = 1;
    for (i = 0; i < b_a_n; i++) color[b_a[i]>>1] = 8;
    stack->a.n = 0;
    kv_push(uint32_t, stack->a, b_a[0]>>1);
    color[b_a[0]>>1] |= 2;///colored
    while (stack->a.n > 0)
    {
        stack->a.n--;
        cur = stack->a.a[stack->a.n];
        color[cur] |= 1;
        c = color[cur] & 4; ///get color
        for (i = 0; i < link->a.a[cur].f.n; i++)
        {
            if(link->a.a[cur].f.a[i].del) continue;
            if(link->a.a[cur].f.a[i].dis != RC_0) continue;
            uID = link->a.a[cur].f.a[i].uID;
            if((color[uID] & 8) == 0) continue;
            if((color[uID] & 2) && ((color[uID] & 4) == c)) break; ///conflict
            if((color[uID] & 1) == 1) continue;
            kv_push(uint32_t, stack->a, uID);
            color[uID] |= 2; color[uID] |= (c^4);
        }

        if(i != link->a.a[cur].f.n)
        {
            sucess = -1;
            break;
        }
    }

    Failed: 
    if(sucess != 1)
    {
        for (i = 0; i < b_a_n; i++) color[b_a[i]>>1] = 0;
    }
    
    return sucess;
}

// Assembly:
testl %esi, %esi
je 0x10fc6a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r15
movq %rcx, %r12
movl %esi, 0x34(%rsp)
movl %esi, %eax
movq %rax, 0x28(%rsp)
xorl %eax, %eax
cmpq %rax, 0x28(%rsp)
je 0x10fc4d
movl (%rdi,%rax,4), %ecx
shrl %ecx
movb $0x8, (%rdx,%rcx)
incq %rax
jmp 0x10fc38
movq %rdi, 0x10(%rsp)
andq $0x0, (%r15)
cmpq $0x0, 0x8(%r15)
movq %rdx, 0x20(%rsp)
je 0x10fc6d
movq 0x10(%r15), %rax
xorl %edi, %edi
jmp 0x10fc8d
xorl %eax, %eax
retq
movq $0x2, 0x8(%r15)
movq 0x10(%r15), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq 0x20(%rsp), %rdx
movq %rax, 0x10(%r15)
movq (%r15), %rdi
movq 0x10(%rsp), %rcx
movl (%rcx), %esi
shrl %esi
leaq 0x1(%rdi), %rcx
movq %rcx, (%r15)
movl %esi, (%rax,%rdi,4)
xorl %eax, %eax
testq %rcx, %rcx
je 0x10fd6c
movl %eax, 0xc(%rsp)
leaq -0x1(%rcx), %rax
movq %rax, (%r15)
movq 0x10(%r15), %rax
movl -0x4(%rax,%rcx,4), %eax
movzbl (%rdx,%rax), %ecx
movl %ecx, %r14d
notl %r14d
andl $0x1, %r14d
orb $0x1, %cl
movb %cl, (%rdx,%rax)
xorl %r13d, %r13d
imulq $0x30, %rax, %rbp
movl %r13d, %r13d
movq 0x10(%r12), %rax
cmpq %r13, 0x18(%rax,%rbp)
jbe 0x10fd5d
addq %rbp, %rax
addq $0x18, %rax
movq 0x10(%rax), %rax
imulq $0x28, %r13, %rcx
cmpb $0x0, 0x18(%rax,%rcx)
js 0x10fd55
addq %rcx, %rax
cmpq $0x0, 0x10(%rax)
jne 0x10fd55
movl 0x8(%rax), %ebx
movb (%rdx,%rbx), %al
andb $0x9, %al
cmpb $0x8, %al
jne 0x10fd55
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x10fd4b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %rdx
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movl %ebx, (%rax,%rcx,4)
incl %r13d
jmp 0x10fcd9
movl 0xc(%rsp), %eax
addl %r14d, %eax
movq (%r15), %rcx
jmp 0x10fca2
movl $0x0, 0x1c(%rsp)
cmpl 0x34(%rsp), %eax
movq 0x10(%rsp), %rdi
jne 0x10fee5
xorl %eax, %eax
cmpq %rax, 0x28(%rsp)
je 0x10fd9a
movl (%rdi,%rax,4), %ecx
shrl %ecx
movb $0x8, (%rdx,%rcx)
incq %rax
jmp 0x10fd85
andq $0x0, (%r15)
cmpq $0x0, 0x8(%r15)
movq 0x10(%r15), %rax
je 0x10fdad
xorl %ecx, %ecx
jmp 0x10fdcc
movq $0x2, 0x8(%r15)
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %rdx
movq %rax, 0x10(%r15)
movq (%r15), %rcx
movq 0x10(%rsp), %rsi
movl (%rsi), %edi
shrl %edi
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movl %edi, (%rax,%rcx,4)
movq 0x10(%rsp), %rdi
movl (%rdi), %eax
shrl %eax
orb $0x2, (%rdx,%rax)
pushq $-0x1
popq %rax
movl %eax, 0x1c(%rsp)
movq (%r15), %rax
testq %rax, %rax
je 0x10ff02
leaq -0x1(%rax), %rcx
movq %rcx, (%r15)
movq 0x10(%r15), %rcx
movl -0x4(%rcx,%rax,4), %eax
movzbl (%rdx,%rax), %ebx
movl %ebx, %ecx
orb $0x1, %cl
movb %cl, (%rdx,%rax)
andl $0x4, %ebx
movl %ebx, %r9d
xorb $0x6, %r9b
xorl %r14d, %r14d
imulq $0x30, %rax, %r13
movl %r14d, %r14d
movq 0x10(%r12), %rcx
movq 0x18(%rcx,%r13), %rax
cmpq %r14, %rax
jbe 0x10fedc
addq %r13, %rcx
addq $0x18, %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %r14, %rsi
cmpb $0x0, 0x18(%rcx,%rsi)
js 0x10fed4
addq %rsi, %rcx
cmpq $0x0, 0x10(%rcx)
jne 0x10fed4
movl 0x8(%rcx), %ebp
movzbl (%rdx,%rbp), %ecx
testb $0x8, %cl
je 0x10fed4
testb $0x2, %cl
je 0x10fe7b
movl %ecx, %esi
andl $0x4, %esi
cmpl %ebx, %esi
je 0x10fedc
testb $0x1, %cl
jne 0x10fed4
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x10fec6
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
movb %r9b, 0xc(%rsp)
callq 0x2370
movb 0xc(%rsp), %r9b
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rdx
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movl %ebp, (%rax,%rcx,4)
orb %r9b, (%rdx,%rbp)
incl %r14d
jmp 0x10fe2b
cmpq %r14, %rax
je 0x10fdf3
xorl %eax, %eax
cmpq %rax, 0x28(%rsp)
je 0x10fefc
movl (%rdi,%rax,4), %ecx
shrl %ecx
movb $0x0, (%rdx,%rcx)
incq %rax
jmp 0x10fee7
movl 0x1c(%rsp), %eax
jmp 0x10ff05
pushq $0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq