// File: /workspace/github_c_makefile_star2_O3/rikuu[P]kermit/miniasm/asg.c
// Function: asg_cut_biloop
int asg_cut_biloop(asg_t *g, int max_ext)
{
	asg64_v a = {0,0,0};
	uint32_t n_vtx = g->n_seq * 2, v, i, cnt = 0;
	for (v = 0; v < n_vtx; ++v) {
		uint32_t nv, nw, w = UINT32_MAX, x, ov = 0, ox = 0;
		asg_arc_t *av, *aw;
		if (g->seq[v>>1].del) continue;
		if (asg_is_utg_end(g, v, 0) != ASG_ET_MULTI_NEI) continue;
		if (asg_extend(g, v, max_ext, &a) != ASG_ET_MULTI_OUT) continue;
		x = (uint32_t)a.a[a.n - 1] ^ 1;
		nv = asg_arc_n(g, v ^ 1), av = asg_arc_a(g, v ^ 1);
		for (i = 0; i < nv; ++i)
			if (!av[i].del) w = av[i].v ^ 1;
		assert(w != UINT32_MAX);
		nw = asg_arc_n(g, w), aw = asg_arc_a(g, w);
		for (i = 0; i < nw; ++i) { // we are looking for: v->...->x', w->v and w->x
			if (aw[i].del) continue;
			if (aw[i].v == x) ox = aw[i].ol;
			if (aw[i].v == v) ov = aw[i].ol;
		}
		if (ov == 0 && ox == 0) continue;
		if (ov > ox) {
			asg_arc_del(g, w, x, 1);
			asg_arc_del(g, x^1, w^1, 1);
			++cnt;
		}
	}
	free(a.a);
	if (cnt > 0) asg_cleanup(g);
	fprintf(stderr, "[M::%s] cut %d small bi-loops\n", __func__, cnt);
	return cnt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl 0x14(%rdi), %r13d
addl %r13d, %r13d
je 0x4540
movl %esi, %ebx
movq %rdi, %r14
xorl %r15d, %r15d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
movl %esi, 0xc(%rsp)
movq 0x18(%r14), %rax
movl %r15d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,4)
js 0x4522
movq 0x20(%r14), %rcx
movl %r15d, %r12d
xorl $0x1, %r12d
movq (%rcx,%r12,8), %rdi
movq %rdi, %rdx
andq %rbp, %rdx
je 0x4522
movq 0x8(%r14), %rax
shrq $0x20, %rdi
shlq $0x4, %rdi
leaq (%rax,%rdi), %rsi
leaq (%rax,%rdi), %r8
addq $0xc, %r8
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %r11d, %r11d
cmpl $0x0, (%r8)
setns %r11b
cmovnsl %r9d, %edi
addl %r11d, %r10d
incq %r9
addq $0x10, %r8
cmpq %r9, %rdx
jne 0x4348
cmpl $0x1, %r10d
jne 0x4522
movslq %edi, %rdx
shlq $0x4, %rdx
movl 0x8(%rsi,%rdx), %edx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rdx
movq %rdx, %rcx
andq %rbp, %rcx
je 0x43be
shrq $0x20, %rdx
shlq $0x4, %rcx
shlq $0x4, %rdx
addq %rdx, %rax
addq $0xc, %rax
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x43a2
cmpl $0x1, %esi
je 0x4522
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %edx
leaq 0x10(%rsp), %rcx
callq 0x4116
cmpl $0x2, %eax
jne 0x4522
movq 0x20(%r14), %rsi
movq (%rsi,%r12,8), %rax
testl %eax, %eax
je 0x457e
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq -0x8(%rdx,%rcx,8), %rdx
movl %edx, %r11d
xorl $0x1, %edx
movq 0x8(%r14), %rdi
movq %rax, %rcx
shrq $0x20, %rcx
movl %eax, %r8d
shlq $0x4, %rcx
leaq (%rdi,%rcx), %r9
addq $0xc, %r9
shlq $0x4, %r8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r10d, %r10d
cmpl $0x0, (%r9,%r10)
js 0x4433
movl -0x4(%r9,%r10), %eax
xorl $0x1, %eax
addq $0x10, %r10
cmpq %r10, %r8
jne 0x4424
cmpl $-0x1, %eax
je 0x457e
movl %eax, %ecx
movq (%rsi,%rcx,8), %r10
testl %r10d, %r10d
je 0x4522
movq %r11, 0x30(%rsp)
movq %r10, %rcx
shrq $0x20, %rcx
movl %r10d, %r8d
shlq $0x4, %rcx
leaq (%rdi,%rcx), %r9
addq $0xc, %r9
shlq $0x4, %r8
xorl %ebp, %ebp
xorl %r11d, %r11d
xorl %r12d, %r12d
movl (%r9,%rbp), %ecx
testl %ecx, %ecx
js 0x4495
movl -0x4(%r9,%rbp), %ebx
cmpl %edx, %ebx
cmovel %ecx, %r11d
cmpl %r15d, %ebx
cmovel %ecx, %r12d
addq $0x10, %rbp
cmpq %rbp, %r8
jne 0x447b
movl %r12d, %ecx
orl %r11d, %ecx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
je 0x451e
cmpl %r11d, %r12d
movl 0xc(%rsp), %ebx
jbe 0x4522
testl %r10d, %r10d
movq 0x30(%rsp), %rcx
je 0x44de
xorl %esi, %esi
cmpl %edx, -0x4(%r9,%rsi)
jne 0x44cd
orb $-0x80, 0x3(%r9,%rsi)
addq $0x10, %rsi
cmpq %rsi, %r8
jne 0x44c0
movq 0x8(%r14), %rdi
movq 0x20(%r14), %rsi
movq (%rsi,%rcx,8), %rdx
movq %rdx, %rcx
andq %rbp, %rcx
je 0x4518
shrq $0x20, %rdx
shlq $0x4, %rcx
shlq $0x4, %rdx
addq %rdi, %rdx
addq $0xc, %rdx
xorl %esi, %esi
movl -0x4(%rdx,%rsi), %edi
xorl %eax, %edi
cmpl $0x1, %edi
jne 0x450f
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x10, %rsi
cmpq %rsi, %rcx
jne 0x44ff
incl 0x8(%rsp)
jmp 0x4522
movl 0xc(%rsp), %ebx
incl %r15d
cmpl %r13d, %r15d
jne 0x42f7
movq 0x20(%rsp), %rdi
callq 0x1040
movl 0x8(%rsp), %ebx
testl %ebx, %ebx
jne 0x4544
xorl %ebx, %ebx
jmp 0x454c
movq %r14, %rdi
callq 0x40c7
movq 0x9aa5(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x5c73(%rip), %rsi      # 0xa1d0
leaq 0x5c8b(%rip), %rdx      # 0xa1ef
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1120
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5c0c(%rip), %rdi      # 0xa191
leaq 0x5c15(%rip), %rsi      # 0xa1a1
leaq 0x5c1c(%rip), %rcx      # 0xa1af
movl $0x120, %edx            # imm = 0x120
callq 0x10c0