// File: /workspace/github_cpp_makefile_star2_O1/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 0x15081b
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r12
movq %rcx, %r13
movq %rdx, %r8
movq %rdi, %rbx
movq %rsi, 0x8(%rsp)
movl %esi, %eax
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
shrl %edx
movb $0x8, (%r8,%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x150501
movq $0x0, (%r12)
cmpq $0x0, 0x8(%r12)
movq %r8, (%rsp)
jne 0x150548
movq $0x2, 0x8(%r12)
movq 0x10(%r12), %rdi
movl $0x8, %esi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x10(%r12)
movq %rbx, 0x20(%rsp)
movl (%rbx), %ecx
shrl %ecx
movq (%r12), %rdx
movq 0x10(%r12), %rsi
movq %rdx, %rax
movl $0x0, %r9d
incq %rax
movq %rax, (%r12)
movl %ecx, (%rsi,%rdx,4)
je 0x15065d
xorl %r9d, %r9d
movq %r9, 0x10(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, (%r12)
movq 0x10(%r12), %rcx
movl -0x4(%rcx,%rax,4), %ecx
movzbl (%r8,%rcx), %r15d
movl %r15d, %eax
orb $0x1, %al
movb %al, (%r8,%rcx)
movq 0x10(%r13), %rax
leaq (%rcx,%rcx,2), %rbp
shlq $0x4, %rbp
cmpq $0x0, 0x18(%rax,%rbp)
je 0x150641
movl $0x1, %ebx
xorl %ecx, %ecx
movq 0x28(%rax,%rbp), %rax
leaq (%rcx,%rcx,4), %rcx
cmpb $0x0, 0x18(%rax,%rcx,8)
js 0x15062e
leaq (%rax,%rcx,8), %rax
cmpq $0x0, 0x10(%rax)
jne 0x15062e
movl 0x8(%rax), %r14d
movb (%r8,%r14), %al
andb $0x9, %al
cmpb $0x8, %al
jne 0x15062e
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x150619
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x2, %rsi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r12)
movl %r14d, (%rcx,%rax,4)
movl %ebx, %ecx
movq 0x10(%r13), %rax
incl %ebx
cmpq %rcx, 0x18(%rax,%rbp)
ja 0x1505b9
notl %r15d
andl $0x1, %r15d
movq 0x10(%rsp), %r9
addl %r15d, %r9d
movq (%r12), %rax
testq %rax, %rax
jne 0x150576
movl $0x0, %edi
cmpl 0x8(%rsp), %r9d
movl $0x0, %eax
jne 0x150823
movq 0x8(%rsp), %rax
cmpl $0x1, %eax
adcl $0x0, %eax
xorl %ecx, %ecx
movq 0x20(%rsp), %rbx
movl (%rbx,%rcx,4), %edx
shrl %edx
movb $0x8, (%r8,%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x150684
movq $0x0, (%r12)
cmpq $0x0, 0x8(%r12)
jne 0x1506c7
movq $0x2, 0x8(%r12)
movq 0x10(%r12), %rdi
movl $0x8, %esi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x10(%r12)
movl (%rbx), %eax
shrl %eax
movq (%r12), %rcx
movq 0x10(%r12), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r12)
movl %eax, (%rdx,%rcx,4)
movl (%rbx), %eax
shrl %eax
orb $0x2, (%r8,%rax)
movq (%r12), %rax
testq %rax, %rax
sete %dil
je 0x15081e
leaq -0x1(%rax), %rcx
movq %rcx, (%r12)
movq 0x10(%r12), %rcx
movl -0x4(%rcx,%rax,4), %eax
movzbl (%r8,%rax), %r10d
movl %r10d, %ecx
orb $0x1, %cl
movb %cl, (%r8,%rax)
movq 0x10(%r13), %rdx
leaq (%rax,%rax,2), %rbp
shlq $0x4, %rbp
movq 0x18(%rdx,%rbp), %rax
testq %rax, %rax
je 0x150809
andl $0x4, %r10d
movl %r10d, %r14d
xorb $0x6, %r14b
movl $0x1, %r15d
xorl %ecx, %ecx
movq 0x28(%rdx,%rbp), %rdx
leaq (%rcx,%rcx,4), %rsi
cmpb $0x0, 0x18(%rdx,%rsi,8)
js 0x1507ef
leaq (%rdx,%rsi,8), %rdx
cmpq $0x0, 0x10(%rdx)
jne 0x1507ef
movl 0x8(%rdx), %ebx
movzbl (%r8,%rbx), %edx
testb $0x8, %dl
je 0x1507ef
testb $0x2, %dl
je 0x150789
movl %edx, %esi
andl $0x4, %esi
cmpl %r10d, %esi
je 0x15080b
testb $0x1, %dl
jne 0x1507ef
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x1507d7
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movl %edi, 0x10(%rsp)
movq 0x10(%r12), %rdi
shlq $0x2, %rsi
movl %r10d, 0x1c(%rsp)
callq 0x2370
movl 0x1c(%rsp), %r10d
movl 0x10(%rsp), %edi
movq (%rsp), %r8
movq %rax, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r12)
movl %ebx, (%rcx,%rax,4)
orb %r14b, (%r8,%rbx)
movl %r15d, %ecx
movq 0x10(%r13), %rdx
movq 0x18(%rdx,%rbp), %rax
incl %r15d
cmpq %rcx, %rax
ja 0x150746
jmp 0x15080b
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x1506e8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x150823
xorl %eax, %eax
retq
movl $0x1, %eax
testb %dil, %dil
jne 0x15084c
movq 0x8(%rsp), %rdx
cmpl $0x1, %edx
adcl $0x0, %edx
xorl %edi, %edi
movq 0x20(%rsp), %rsi
movl (%rsi,%rdi,4), %ecx
shrl %ecx
movb $0x0, (%r8,%rcx)
incq %rdi
cmpq %rdi, %rdx
jne 0x15083a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq