// File: /workspace/github_cpp_makefile_star2_O3/Alcaro[P]bridges/gamemap.cpp
// Function: gamemap::toggle(int, int, int)
void gamemap::toggle(int x, int y, int dir)
{
	if (dir == 0)
	{
		island& here = map[y][x];
		if (here.bridges[0] == 3) return;
		
		int newbridges = (here.bridges[0]+1)%3;
		int diff = newbridges - here.bridges[0];
		for (int xx=0;xx<here.bridgelen[0];xx++)
		{
			map[y][x+xx  ].bridges[0] = newbridges;
			map[y][x+xx+1].bridges[2] = newbridges;
			get(map[y][x+xx  ].rootnode).totbridges += diff;
			get(map[y][x+xx+1].rootnode).totbridges += diff;
		}
	}
	else
	{
		island& here = map[y][x];
		if (here.bridges[3] == 3) return;
		
		int newbridges = (here.bridges[3]+1)%3;
		int diff = newbridges - here.bridges[3];
		for (int yy=0;yy<here.bridgelen[3];yy++)
		{
			map[y+yy  ][x].bridges[3] = newbridges;
			map[y+yy+1][x].bridges[1] = newbridges;
			get(map[y+yy  ][x].rootnode).totbridges += diff;
			get(map[y+yy+1][x].rootnode).totbridges += diff;
		}
	}
}

// Assembly:
pushq %rbx
leaq 0xc(%rdi), %rax
movslq %edx, %rdx
imulq $0x4b0, %rdx, %r8       # imm = 0x4B0
movslq %esi, %rdx
leaq (%rdi,%r8), %rsi
addq $0xc, %rsi
leaq (%rdx,%rdx,2), %r9
leaq (%rsi,%r9,4), %rdx
testl %ecx, %ecx
je 0x2300b
movzbl 0xb(%rdx), %r10d
cmpw $0x3, %r10w
je 0x230cf
movsbq 0x7(%rdx), %rcx
testq %rcx, %rcx
jle 0x230cf
movzwl %r10w, %edx
incl %edx
imull $0x5556, %edx, %esi     # imm = 0x5556
shrl $0x10, %esi
leal (%rsi,%rsi,2), %esi
subl %esi, %edx
movl %edx, %esi
subb %r10b, %sil
leaq (%r8,%r9,4), %r8
addq %r8, %rdi
addq $0x4c5, %rdi            # imm = 0x4C5
xorl %r8d, %r8d
movl $0xffff, %r9d           # imm = 0xFFFF
movb %dl, -0x4ae(%rdi)
movb %dl, (%rdi)
movzwl -0x4b7(%rdi), %r10d
movl %r10d, %r11d
shrl $0x2, %r11d
imull $0x147b, %r11d, %r11d   # imm = 0x147B
shrl $0x11, %r11d
imull $0x64, %r11d, %ebx
subl %ebx, %r10d
andl %r9d, %r10d
imulq $0x4b0, %r11, %r11      # imm = 0x4B0
addq %rax, %r11
leaq (%r10,%r10,2), %r10
addb %sil, 0x1(%r11,%r10,4)
movzwl -0x7(%rdi), %r10d
movl %r10d, %r11d
shrl $0x2, %r11d
imull $0x147b, %r11d, %r11d   # imm = 0x147B
shrl $0x11, %r11d
imull $0x64, %r11d, %ebx
subl %ebx, %r10d
andl %r9d, %r10d
imulq $0x4b0, %r11, %r11      # imm = 0x4B0
addq %rax, %r11
leaq (%r10,%r10,2), %r10
addb %sil, 0x1(%r11,%r10,4)
incq %r8
addq $0x4b0, %rdi            # imm = 0x4B0
cmpq %rcx, %r8
jb 0x22f80
jmp 0x230cf
movzbl 0x8(%rdx), %r10d
cmpw $0x3, %r10w
je 0x230cf
movsbq 0x4(%rdx), %rcx
testq %rcx, %rcx
jle 0x230cf
movzwl %r10w, %edx
incl %edx
imull $0x5556, %edx, %esi     # imm = 0x5556
shrl $0x10, %esi
leal (%rsi,%rsi,2), %esi
subl %esi, %edx
movl %edx, %esi
subb %r10b, %sil
leaq (%r8,%r9,4), %r8
addq %r8, %rdi
addq $0x22, %rdi
xorl %r8d, %r8d
movl $0xffff, %r9d           # imm = 0xFFFF
movb %dl, -0xe(%rdi)
movb %dl, (%rdi)
movzwl -0x14(%rdi), %r10d
movl %r10d, %r11d
shrl $0x2, %r11d
imull $0x147b, %r11d, %r11d   # imm = 0x147B
shrl $0x11, %r11d
imull $0x64, %r11d, %ebx
subl %ebx, %r10d
andl %r9d, %r10d
imulq $0x4b0, %r11, %r11      # imm = 0x4B0
addq %rax, %r11
leaq (%r10,%r10,2), %r10
addb %sil, 0x1(%r11,%r10,4)
movzwl -0x8(%rdi), %r10d
movl %r10d, %r11d
shrl $0x2, %r11d
imull $0x147b, %r11d, %r11d   # imm = 0x147B
shrl $0x11, %r11d
imull $0x64, %r11d, %ebx
subl %ebx, %r10d
andl %r9d, %r10d
imulq $0x4b0, %r11, %r11      # imm = 0x4B0
addq %rax, %r11
leaq (%r10,%r10,2), %r10
addb %sil, 0x1(%r11,%r10,4)
incq %r8
addq $0xc, %rdi
cmpq %rcx, %r8
jb 0x23056
popq %rbx
retq
nop