// File: 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 %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x4f249
movq -0x50(%rbp), %rax
addq $0xc, %rax
movslq -0x10(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x3, %eax
jne 0x4f10e
jmp 0x4f3b8
movq -0x20(%rbp), %rax
movzbl 0x8(%rax), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
movzbl 0x8(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jge 0x4f244
movq -0x50(%rbp), %rdi
movl -0x24(%rbp), %eax
movb %al, %cl
movq %rdi, %rax
addq $0xc, %rax
movslq -0x10(%rbp), %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rax
movl -0xc(%rbp), %edx
addl -0x2c(%rbp), %edx
movslq %edx, %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x8(%rax)
movl -0x24(%rbp), %eax
movb %al, %cl
movq %rdi, %rax
addq $0xc, %rax
movslq -0x10(%rbp), %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rax
movl -0xc(%rbp), %edx
addl -0x2c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0xa(%rax)
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
movq %rdi, %rax
addq $0xc, %rax
movslq -0x10(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movl -0xc(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %esi
callq 0x4e8e0
movl -0x58(%rbp), %edx
movq -0x50(%rbp), %rdi
movsbl 0x1(%rax), %ecx
addl %edx, %ecx
movb %cl, 0x1(%rax)
movl -0x28(%rbp), %eax
movl %eax, -0x54(%rbp)
movq %rdi, %rax
addq $0xc, %rax
movslq -0x10(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movl -0xc(%rbp), %ecx
addl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %esi
callq 0x4e8e0
movl -0x54(%rbp), %edx
movsbl 0x1(%rax), %ecx
addl %edx, %ecx
movb %cl, 0x1(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4f13b
jmp 0x4f3b8
movq -0x50(%rbp), %rax
addq $0xc, %rax
movslq -0x10(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movzbl 0xb(%rax), %eax
cmpl $0x3, %eax
jne 0x4f280
jmp 0x4f3b8
movq -0x38(%rbp), %rax
movzbl 0xb(%rax), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x38(%rbp), %rcx
movzbl 0xb(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x38(%rbp), %rcx
movsbl 0x7(%rcx), %ecx
cmpl %ecx, %eax
jge 0x4f3b6
movq -0x50(%rbp), %rdi
movl -0x3c(%rbp), %eax
movb %al, %cl
movq %rdi, %rax
addq $0xc, %rax
movl -0x10(%rbp), %edx
addl -0x44(%rbp), %edx
movslq %edx, %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rax
movslq -0xc(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0xb(%rax)
movl -0x3c(%rbp), %eax
movb %al, %cl
movq %rdi, %rax
addq $0xc, %rax
movl -0x10(%rbp), %edx
addl -0x44(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rax
movslq -0xc(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x9(%rax)
movl -0x40(%rbp), %eax
movl %eax, -0x60(%rbp)
movq %rdi, %rax
addq $0xc, %rax
movl -0x10(%rbp), %ecx
addl -0x44(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %esi
callq 0x4e8e0
movl -0x60(%rbp), %edx
movq -0x50(%rbp), %rdi
movsbl 0x1(%rax), %ecx
addl %edx, %ecx
movb %cl, 0x1(%rax)
movl -0x40(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq %rdi, %rax
addq $0xc, %rax
movl -0x10(%rbp), %ecx
addl -0x44(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %esi
callq 0x4e8e0
movl -0x5c(%rbp), %edx
movsbl 0x1(%rax), %ecx
addl %edx, %ecx
movb %cl, 0x1(%rax)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x4f2ad
jmp 0x4f3b8
addq $0x60, %rsp
popq %rbp
retq
nop