// File: Alcaro[P]bridges/gamemap.cpp
// Function: gamemap::init(char const*)
void gamemap::init(const char * inmap)
{
	width = 0;
	while (inmap[width] != '\n') width++;
	height = 0;
	while (inmap[(width+1) * height] != '\0') height++;
	
	numislands = 0;
	
	has_castles = false;
	an_island[0] = -1; // this value is used if there are zero islands
	an_island[1] = -1;
	an_island[2] = -1;
	an_island[3] = -1;
	an_island[4] = -1;
	
	for (int y=0;y<height;y++)
	for (int x=0;x<width;x++)
	{
		island& here = map[y][x];
		
		int rootpos = y*100+x;
		char mapchar = inmap[y*(width+1) + x];
		
		while (mapchar == '<' || mapchar == '>' || mapchar == 'v' || mapchar == '^')
		{
			if (mapchar == '>') rootpos += 1;
			if (mapchar == '^') rootpos -= 100;
			if (mapchar == '<') rootpos -= 1;
			if (mapchar == 'v') rootpos += 100;
			
			int y2 = rootpos/100;
			int x2 = rootpos%100;
			mapchar = inmap[y2*(width+1) + x2];
		}
		
		if (mapchar == ' ') here.population = -1;
		else if (mapchar == '#') here.population = -2;
		else if (mapchar == 'r') here.population = 80;
		else if (mapchar == 'b') here.population = 81;
		else if (mapchar == 'y') here.population = 82;
		else if (mapchar == 'g') here.population = 83;
		else if (mapchar >= '0' && mapchar <= '9') here.population = mapchar-'0';
		else here.population = mapchar-'A'+10;
		
		here.totbridges = 0;
		here.bridges[0] = 0;
		here.bridges[1] = 0;
		here.bridges[2] = 0;
		here.bridges[3] = 0;
		
		here.bridgelen[0] = -1;
		here.bridgelen[1] = -1;
		here.bridgelen[2] = -1;
		here.bridgelen[3] = -1;
		
		here.rootnode = rootpos;
		
		if (here.population >= 0)
		{
			numislands++;
			if (rootpos == y*100+x)
			{
				an_island[0] = rootpos;
				if (here.population >= 80)
				{
					an_island[here.population-80+1] = rootpos;
					has_castles = true;
				}
			}
			
			for (int x2=x-1;x2>=0;x2--)
			{
				if (map[y][x2].population != -1)
				{
					if (map[y][x2].population == -2) break;
					
					here.bridgelen[2] = x-x2;
					map[y][x2].bridgelen[0] = x-x2;
					for (int x3=x2+1;x3<x;x3++)
					{
						map[y][x3].bridgelen[0] = x-x3;
						map[y][x3].bridgelen[2] = x3-x2;
					}
					
					if (map[y][x2].rootnode == here.rootnode && x-x2==1)
					{
						here.bridges[2] = 3;
						map[y][x2].bridges[0] = 3;
					}
					
					break;
				}
			}
			for (int y2=y-1;y2>=0;y2--)
			{
				if (map[y2][x].population != -1)
				{
					if (map[y2][x].population == -2) break;
					
					here.bridgelen[1] = y-y2;
					map[y2][x].bridgelen[3] = y-y2;
					for (int y3=y2+1;y3<y;y3++)
					{
						map[y3][x].bridgelen[1] = y3-y2;
						map[y3][x].bridgelen[3] = y-y3;
					}
					
					if (map[y2][x].rootnode == here.rootnode && y-y2==1)
					{
						here.bridges[1] = 3;
						map[y2][x].bridges[3] = 3;
					}
					
					break;
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, (%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movslq (%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x4ea2b
movq -0x48(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4ea0a
movq -0x48(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rax
movl (%rdx), %ecx
addl $0x1, %ecx
imull 0x4(%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x4ea62
movq -0x48(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
jmp 0x4ea36
movq -0x48(%rbp), %rax
movl $0x0, 0x8(%rax)
movb $0x0, 0x1d4cc(%rax)
movw $0xffff, 0x1d4ce(%rax)  # imm = 0xFFFF
movw $0xffff, 0x1d4d0(%rax)  # imm = 0xFFFF
movw $0xffff, 0x1d4d2(%rax)  # imm = 0xFFFF
movw $0xffff, 0x1d4d4(%rax)  # imm = 0xFFFF
movw $0xffff, 0x1d4d6(%rax)  # imm = 0xFFFF
movl $0x0, -0x14(%rbp)
movq -0x48(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x4f0a9
movl $0x0, -0x18(%rbp)
movq -0x48(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl (%rcx), %eax
jge 0x4f099
movq -0x48(%rbp), %rdx
movq %rdx, %rax
addq $0xc, %rax
movslq -0x14(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
imull $0x64, -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl (%rdx), %edx
addl $0x1, %edx
imull %edx, %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x25(%rbp)
movsbl -0x25(%rbp), %ecx
movb $0x1, %al
cmpl $0x3c, %ecx
movb %al, -0x49(%rbp)
je 0x4eb52
movsbl -0x25(%rbp), %ecx
movb $0x1, %al
cmpl $0x3e, %ecx
movb %al, -0x49(%rbp)
je 0x4eb52
movsbl -0x25(%rbp), %ecx
movb $0x1, %al
cmpl $0x76, %ecx
movb %al, -0x49(%rbp)
je 0x4eb52
movsbl -0x25(%rbp), %eax
cmpl $0x5e, %eax
sete %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x4eb5e
jmp 0x4ebe8
movsbl -0x25(%rbp), %eax
cmpl $0x3e, %eax
jne 0x4eb70
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movsbl -0x25(%rbp), %eax
cmpl $0x5e, %eax
jne 0x4eb82
movl -0x24(%rbp), %eax
subl $0x64, %eax
movl %eax, -0x24(%rbp)
movsbl -0x25(%rbp), %eax
cmpl $0x3c, %eax
jne 0x4eb94
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
movsbl -0x25(%rbp), %eax
cmpl $0x76, %eax
jne 0x4eba6
movl -0x24(%rbp), %eax
addl $0x64, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %edx, %eax
movq -0x48(%rbp), %rdx
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl (%rdx), %edx
addl $0x1, %edx
imull %edx, %ecx
addl -0x30(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x25(%rbp)
jmp 0x4eb1b
movsbl -0x25(%rbp), %eax
cmpl $0x20, %eax
jne 0x4ebfd
movq -0x20(%rbp), %rax
movb $-0x1, (%rax)
jmp 0x4ec9b
movsbl -0x25(%rbp), %eax
cmpl $0x23, %eax
jne 0x4ec12
movq -0x20(%rbp), %rax
movb $-0x2, (%rax)
jmp 0x4ec99
movsbl -0x25(%rbp), %eax
cmpl $0x72, %eax
jne 0x4ec24
movq -0x20(%rbp), %rax
movb $0x50, (%rax)
jmp 0x4ec97
movsbl -0x25(%rbp), %eax
cmpl $0x62, %eax
jne 0x4ec36
movq -0x20(%rbp), %rax
movb $0x51, (%rax)
jmp 0x4ec95
movsbl -0x25(%rbp), %eax
cmpl $0x79, %eax
jne 0x4ec48
movq -0x20(%rbp), %rax
movb $0x52, (%rax)
jmp 0x4ec93
movsbl -0x25(%rbp), %eax
cmpl $0x67, %eax
jne 0x4ec5a
movq -0x20(%rbp), %rax
movb $0x53, (%rax)
jmp 0x4ec91
movsbl -0x25(%rbp), %eax
cmpl $0x30, %eax
jl 0x4ec7d
movsbl -0x25(%rbp), %eax
cmpl $0x39, %eax
jg 0x4ec7d
movsbl -0x25(%rbp), %eax
subl $0x30, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
jmp 0x4ec8f
movsbl -0x25(%rbp), %eax
subl $0x41, %eax
addl $0xa, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
jmp 0x4ec91
jmp 0x4ec93
jmp 0x4ec95
jmp 0x4ec97
jmp 0x4ec99
jmp 0x4ec9b
movq -0x20(%rbp), %rax
movb $0x0, 0x1(%rax)
movq -0x20(%rbp), %rax
movb $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
movb $0x0, 0x9(%rax)
movq -0x20(%rbp), %rax
movb $0x0, 0xa(%rax)
movq -0x20(%rbp), %rax
movb $0x0, 0xb(%rax)
movq -0x20(%rbp), %rax
movb $-0x1, 0x4(%rax)
movq -0x20(%rbp), %rax
movb $-0x1, 0x5(%rax)
movq -0x20(%rbp), %rax
movb $-0x1, 0x6(%rax)
movq -0x20(%rbp), %rax
movb $-0x1, 0x7(%rax)
movl -0x24(%rbp), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jl 0x4f089
movq -0x48(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movl -0x24(%rbp), %eax
imull $0x64, -0x14(%rbp), %ecx
addl -0x18(%rbp), %ecx
cmpl %ecx, %eax
jne 0x4ed61
movq -0x48(%rbp), %rax
movl -0x24(%rbp), %ecx
movw %cx, 0x1d4ce(%rax)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x50, %eax
jl 0x4ed5f
movq -0x48(%rbp), %rax
movl -0x24(%rbp), %ecx
movw %cx, %dx
movq -0x20(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x50, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, 0x1d4ce(%rax,%rcx,2)
movb $0x1, 0x1d4cc(%rax)
jmp 0x4ed61
movl -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jl 0x4eef4
movq -0x48(%rbp), %rax
addq $0xc, %rax
movslq -0x14(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movsbl (%rax), %eax
cmpl $-0x1, %eax
je 0x4eee4
movq -0x48(%rbp), %rax
addq $0xc, %rax
movslq -0x14(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movsbl (%rax), %eax
cmpl $-0x2, %eax
jne 0x4edcf
jmp 0x4eef4
movq -0x48(%rbp), %rax
movl -0x18(%rbp), %ecx
subl -0x34(%rbp), %ecx
movb %cl, %dl
movq -0x20(%rbp), %rcx
movb %dl, 0x6(%rcx)
movl -0x18(%rbp), %ecx
subl -0x34(%rbp), %ecx
addq $0xc, %rax
movslq -0x14(%rbp), %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rax
movslq -0x34(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x4(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x4ee79
movq -0x48(%rbp), %rax
movl -0x18(%rbp), %ecx
subl -0x38(%rbp), %ecx
movb %cl, %dl
movq %rax, %rcx
addq $0xc, %rcx
movslq -0x14(%rbp), %rsi
imulq $0x4b0, %rsi, %rsi      # imm = 0x4B0
addq %rsi, %rcx
movslq -0x38(%rbp), %rsi
imulq $0xc, %rsi, %rsi
addq %rsi, %rcx
movb %dl, 0x4(%rcx)
movl -0x38(%rbp), %ecx
subl -0x34(%rbp), %ecx
addq $0xc, %rax
movslq -0x14(%rbp), %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rax
movslq -0x38(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x6(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4ee11
movq -0x48(%rbp), %rax
addq $0xc, %rax
movslq -0x14(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movswl 0x2(%rax), %eax
movq -0x20(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jne 0x4eee2
movl -0x18(%rbp), %eax
subl -0x34(%rbp), %eax
cmpl $0x1, %eax
jne 0x4eee2
movq -0x48(%rbp), %rax
movq -0x20(%rbp), %rcx
movb $0x3, 0xa(%rcx)
addq $0xc, %rax
movslq -0x14(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movb $0x3, 0x8(%rax)
jmp 0x4eef4
jmp 0x4eee6
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4ed6a
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x4f087
movq -0x48(%rbp), %rax
addq $0xc, %rax
movslq -0x3c(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movsbl (%rax), %eax
cmpl $-0x1, %eax
je 0x4f077
movq -0x48(%rbp), %rax
addq $0xc, %rax
movslq -0x3c(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movsbl (%rax), %eax
cmpl $-0x2, %eax
jne 0x4ef62
jmp 0x4f087
movq -0x48(%rbp), %rax
movl -0x14(%rbp), %ecx
subl -0x3c(%rbp), %ecx
movb %cl, %dl
movq -0x20(%rbp), %rcx
movb %dl, 0x5(%rcx)
movl -0x14(%rbp), %ecx
subl -0x3c(%rbp), %ecx
addq $0xc, %rax
movslq -0x3c(%rbp), %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rax
movslq -0x18(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x7(%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4f00c
movq -0x48(%rbp), %rax
movl -0x40(%rbp), %ecx
subl -0x3c(%rbp), %ecx
movb %cl, %dl
movq %rax, %rcx
addq $0xc, %rcx
movslq -0x40(%rbp), %rsi
imulq $0x4b0, %rsi, %rsi      # imm = 0x4B0
addq %rsi, %rcx
movslq -0x18(%rbp), %rsi
imulq $0xc, %rsi, %rsi
addq %rsi, %rcx
movb %dl, 0x5(%rcx)
movl -0x14(%rbp), %ecx
subl -0x40(%rbp), %ecx
addq $0xc, %rax
movslq -0x40(%rbp), %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rax
movslq -0x18(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x7(%rax)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4efa4
movq -0x48(%rbp), %rax
addq $0xc, %rax
movslq -0x3c(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movswl 0x2(%rax), %eax
movq -0x20(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jne 0x4f075
movl -0x14(%rbp), %eax
subl -0x3c(%rbp), %eax
cmpl $0x1, %eax
jne 0x4f075
movq -0x48(%rbp), %rax
movq -0x20(%rbp), %rcx
movb $0x3, 0x9(%rcx)
addq $0xc, %rax
movslq -0x3c(%rbp), %rcx
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movb $0x3, 0xb(%rax)
jmp 0x4f087
jmp 0x4f079
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4eefd
jmp 0x4f089
jmp 0x4f08b
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x4eabf
jmp 0x4f09b
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4eaa8
popq %rbp
retq
nopl (%rax,%rax)