// File: /workspace/github_cpp_makefile_star2_O3/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 0x156aa5
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r15
movq %rcx, %r9
movq %rdi, %rbx
movl %esi, 0x14(%rsp)
movl %esi, %esi
xorl %eax, %eax
movl (%rbx,%rax,4), %ecx
shrl %ecx
movb $0x8, (%rdx,%rcx)
incq %rax
cmpq %rax, %rsi
jne 0x156a62
movq %rsi, 0x18(%rsp)
movq $0x0, (%r15)
cmpq $0x0, 0x8(%r15)
movq %rdx, 0x8(%rsp)
movq %rbx, 0x20(%rsp)
movq %r9, (%rsp)
je 0x156aa8
movq 0x10(%r15), %rax
movl (%rbx), %ecx
shrl %ecx
movl %ecx, (%rax)
movl $0x1, %ecx
jmp 0x156ae6
xorl %eax, %eax
retq
movq $0x2, 0x8(%r15)
movq 0x10(%r15), %rdi
movl $0x8, %esi
callq 0x2370
movq (%rsp), %r9
movq 0x8(%rsp), %rdx
movq %rax, 0x10(%r15)
movq (%r15), %rdi
movl (%rbx), %esi
shrl %esi
xorl %ebp, %ebp
movq %rdi, %rcx
incq %rcx
movq %rcx, (%r15)
movl %esi, (%rax,%rdi,4)
je 0x156bba
xorl %ebp, %ebp
leaq -0x1(%rcx), %rax
movq %rax, (%r15)
movq 0x10(%r15), %rax
movl -0x4(%rax,%rcx,4), %eax
movzbl (%rdx,%rax), %r13d
movl %r13d, %ecx
orb $0x1, %cl
movb %cl, (%rdx,%rax)
movq 0x10(%r9), %rcx
leaq (%rax,%rax,2), %r14
shlq $0x4, %r14
cmpq $0x0, 0x18(%rcx,%r14)
je 0x156ba4
movl $0x1, %r12d
xorl %eax, %eax
movq 0x28(%rcx,%r14), %rsi
leaq (%rax,%rax,4), %rax
cmpb $0x0, 0x18(%rsi,%rax,8)
js 0x156b97
leaq (%rsi,%rax,8), %rax
cmpq $0x0, 0x10(%rax)
jne 0x156b97
movl 0x8(%rax), %ebx
movb (%rdx,%rbx), %al
andb $0x9, %al
cmpb $0x8, %al
jne 0x156b97
movq (%r15), %rdi
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rdi
jne 0x156b8d
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r9
movq 0x8(%rsp), %rdx
movq %rax, 0x10(%r15)
movq (%r15), %rdi
movq 0x10(%r9), %rcx
leaq 0x1(%rdi), %rsi
movq %rsi, (%r15)
movl %ebx, (%rax,%rdi,4)
movl %r12d, %eax
incl %r12d
cmpq %rax, 0x18(%rcx,%r14)
ja 0x156b25
notl %r13d
andl $0x1, %r13d
addl %r13d, %ebp
movq (%r15), %rcx
testq %rcx, %rcx
jne 0x156ae8
xorl %eax, %eax
cmpl 0x14(%rsp), %ebp
movq 0x20(%rsp), %rbx
movq 0x18(%rsp), %rdi
jne 0x156d47
xorl %eax, %eax
movl (%rbx,%rax,4), %ecx
shrl %ecx
movb $0x8, (%rdx,%rcx)
incq %rax
cmpq %rax, %rdi
jne 0x156bd2
movq $0x0, (%r15)
cmpq $0x0, 0x8(%r15)
movq 0x10(%r15), %rax
je 0x156bf9
xorl %ecx, %ecx
jmp 0x156c1e
movq $0x2, 0x8(%r15)
movl $0x8, %esi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r9
movq 0x8(%rsp), %rdx
movq %rax, 0x10(%r15)
movq (%r15), %rcx
movl (%rbx), %edi
shrl %edi
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movl %edi, (%rax,%rcx,4)
movl (%rbx), %eax
shrl %eax
orb $0x2, (%rdx,%rax)
movq (%r15), %rax
testq %rax, %rax
je 0x156d5c
leaq -0x1(%rax), %rcx
movq %rcx, (%r15)
movq 0x10(%r15), %rcx
movl -0x4(%rcx,%rax,4), %ecx
movzbl (%rdx,%rcx), %ebp
movl %ebp, %eax
orb $0x1, %al
movb %al, (%rdx,%rcx)
movq 0x10(%r9), %rax
leaq (%rcx,%rcx,2), %r13
shlq $0x4, %r13
movq 0x18(%rax,%r13), %rcx
testq %rcx, %rcx
je 0x156d2a
andl $0x4, %ebp
movl %ebp, %ebx
xorb $0x6, %bl
movl $0x1, %r14d
xorl %r8d, %r8d
movq 0x28(%rax,%r13), %rsi
leaq (%r8,%r8,4), %rdi
cmpb $0x0, 0x18(%rsi,%rdi,8)
js 0x156d14
leaq (%rsi,%rdi,8), %rsi
cmpq $0x0, 0x10(%rsi)
jne 0x156d14
movl 0x8(%rsi), %r12d
movzbl (%rdx,%r12), %esi
testb $0x8, %sil
je 0x156d14
testb $0x2, %sil
je 0x156cbe
movl %esi, %edi
andl $0x4, %edi
cmpl %ebp, %edi
je 0x156d2f
testb $0x1, %sil
jne 0x156d14
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x156d01
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r9
movq 0x8(%rsp), %rdx
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movl %r12d, (%rax,%rcx,4)
orb %bl, (%rdx,%r12)
movq 0x10(%r9), %rax
movl %r14d, %r8d
movq 0x18(%rax,%r13), %rcx
incl %r14d
cmpq %r8, %rcx
ja 0x156c85
jmp 0x156d2f
xorl %r8d, %r8d
xorl %ecx, %ecx
cmpq %r8, %rcx
movq 0x20(%rsp), %rbx
movq 0x18(%rsp), %rdi
je 0x156c34
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %esi
shrl %esi
movb $0x0, (%rdx,%rsi)
incq %rcx
cmpq %rcx, %rdi
jne 0x156d49
jmp 0x156d61
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq