// File: /workspace/github_cpp_makefile_star2_O2/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:
xorl %r8d, %r8d
movl %r8d, (%rdi)
cmpb $0xa, (%rsi,%r8)
leaq 0x1(%r8), %r8
jne 0x1d0e3
movl %r8d, %eax
xorl %edx, %edx
movl %edx, 0x4(%rdi)
movq %rdx, %rcx
imulq %rax, %rcx
incq %rdx
cmpb $0x0, (%rsi,%rcx)
jne 0x1d0f6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
andl $0x0, 0x8(%rdi)
movb $0x0, 0x1d4cc(%rdi)
leaq 0x1d4ce(%rdi), %rax
movq %rax, -0x18(%rsp)
orq $-0x1, 0x1d4ce(%rdi)
leaq 0xc(%rdi), %rax
movq %rax, -0x10(%rsp)
orw $-0x1, 0x1d4d6(%rdi)
movl %r8d, %eax
movq %rax, -0x58(%rsp)
decq %rdx
leaq -0x1(%r8), %rax
movq %rax, 0x8(%rsp)
leaq 0x14(%rdi), %r14
leaq 0x12(%rdi), %rax
leaq 0x17(%rdi), %rcx
leaq 0x13(%rdi), %r9
xorl %ebx, %ebx
movabsq $-0x1, %r10
movl $0x64, %r15d
movq $-0x4b0, %rbp           # imm = 0xFB50
xorl %r12d, %r12d
movq %rdx, -0x50(%rsp)
cmpq %rbx, %rdx
je 0x1d48c
imulq $0x64, %rbx, %rdx
movq %rdx, (%rsp)
movq %rbx, %rdx
imulq -0x58(%rsp), %rdx
movq %rdx, -0x8(%rsp)
movq %r10, -0x48(%rsp)
negq %r10
movq %r10, -0x20(%rsp)
movq %r9, -0x40(%rsp)
movq %r9, -0x60(%rsp)
movq %rcx, -0x38(%rsp)
movq %rcx, -0x68(%rsp)
movq %rax, -0x30(%rsp)
movq %rax, -0x70(%rsp)
movq %r14, -0x28(%rsp)
movabsq $-0x1, %rax
movq %rax, -0x78(%rsp)
xorl %r10d, %r10d
cmpq %r10, 0x8(%rsp)
je 0x1d452
imulq $0x4b0, %rbx, %rax      # imm = 0x4B0
addq -0x10(%rsp), %rax
imulq $0xc, %r10, %r13
addq %rax, %r13
movq (%rsp), %rax
leal (%r10,%rax), %r9d
movq -0x8(%rsp), %rax
leal (%r10,%rax), %r11d
movl %r9d, %ecx
movslq %r11d, %rax
movzbl (%rsi,%rax), %eax
cmpl $0x3c, %eax
je 0x1d23e
cmpl $0x3e, %eax
je 0x1d23c
cmpl $0x5e, %eax
je 0x1d23e
cmpl $0x76, %eax
je 0x1d23e
jmp 0x1d26e
incl %ecx
xorl %edx, %edx
cmpb $0x3c, %al
sete %dl
leal -0x64(%rcx), %r11d
cmpb $0x5e, %al
cmovnel %ecx, %r11d
subl %edx, %r11d
leal 0x64(%r11), %ecx
cmpb $0x76, %al
cmovnel %r11d, %ecx
movl %ecx, %eax
cltd
idivl %r15d
movl %r8d, %r11d
imull %eax, %r11d
addl %edx, %r11d
jmp 0x1d21f
cmpl $0x20, %eax
je 0x1d2b4
cmpl $0x23, %eax
je 0x1d2b0
cmpl $0x62, %eax
je 0x1d290
cmpl $0x67, %eax
je 0x1d298
cmpl $0x72, %eax
je 0x1d294
cmpl $0x79, %eax
jne 0x1d29c
movb $0x52, %al
jmp 0x1d2b6
movb $0x51, %al
jmp 0x1d2b6
movb $0x50, %al
jmp 0x1d2b6
movb $0x53, %al
jmp 0x1d2b6
leal -0x30(%rax), %edx
addl $-0x37, %eax
cmpb $0xa, %dl
movzbl %dl, %edx
movzbl %al, %eax
cmovbl %edx, %eax
jmp 0x1d2b6
movb $-0x2, %al
jmp 0x1d2b6
movb $-0x1, %al
movb %al, (%r13)
movb $0x0, 0x1(%r13)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rdx, 0x4(%r13)
movw %cx, 0x2(%r13)
testb %al, %al
js 0x1d42f
incl %r12d
movl %r12d, -0x7c(%rsp)
movl %r12d, 0x8(%rdi)
cmpl %r9d, %ecx
jne 0x1d307
movq -0x18(%rsp), %rdx
movw %cx, (%rdx)
cmpb $0x50, %al
jb 0x1d307
movzbl %al, %eax
addl $-0x4f, %eax
movw %cx, 0x1d4ce(%rdi,%rax,2)
movb $0x1, 0x1d4cc(%rdi)
movq -0x70(%rsp), %rdx
movq %r14, %rax
xorl %r12d, %r12d
movq %rdx, %r9
leaq (%r10,%r12), %rdx
testq %rdx, %rdx
jle 0x1d395
movq %r12, %rcx
movzbl -0x14(%rax), %r11d
decq %r12
addq $-0xc, %rax
leaq -0xc(%r9), %rdx
cmpl $0xff, %r11d
je 0x1d312
cmpl $0xfe, %r11d
je 0x1d395
movl %r12d, %edx
negb %dl
movb %dl, 0x6(%r13)
movb %dl, -0x4(%rax)
movq %r12, %rdx
subq -0x78(%rsp), %rdx
negb %cl
movb $0x1, %r11b
cmpq %r10, %rdx
jge 0x1d376
movb %cl, -0x2(%r9)
movb %r11b, (%r9)
incq %rdx
decb %cl
incb %r11b
addq $0xc, %r9
jmp 0x1d35c
movzwl -0x6(%rax), %ecx
cmpw 0x2(%r13), %cx
sete %cl
cmpl $-0x1, %r12d
sete %dl
testb %dl, %cl
je 0x1d395
movb $0x3, %cl
movb %cl, 0xa(%r13)
movb %cl, (%rax)
movq -0x60(%rsp), %r11
movq -0x68(%rsp), %rax
xorl %edx, %edx
movq %rdx, %rcx
addq %rbx, %rdx
testq %rdx, %rdx
jle 0x1d42a
movq %r11, %r9
movzbl -0x4bb(%rax), %r12d
leaq -0x1(%rcx), %rdx
addq %rbp, %rax
addq %rbp, %r11
cmpl $0xff, %r12d
je 0x1d3a1
cmpl $0xfe, %r12d
je 0x1d42a
movl %edx, %r11d
negb %r11b
movb %r11b, 0x5(%r13)
movb %r11b, -0x4(%rax)
movq -0x20(%rsp), %r11
leaq (%r11,%rdx), %r12
negb %cl
movb $0x1, %r11b
cmpq %rbx, %r12
jge 0x1d40c
movb %r11b, -0x2(%r9)
movb %cl, (%r9)
incq %r12
incb %r11b
decb %cl
addq $0x4b0, %r9             # imm = 0x4B0
jmp 0x1d3ef
movzwl -0x9(%rax), %ecx
cmpw 0x2(%r13), %cx
sete %cl
cmpl $-0x1, %edx
sete %dl
testb %dl, %cl
je 0x1d42a
movb $0x3, %cl
movb %cl, 0x9(%r13)
movb %cl, (%rax)
movl -0x7c(%rsp), %r12d
incq %r10
decq -0x78(%rsp)
addq $0xc, %r14
addq $0xc, -0x70(%rsp)
addq $0xc, -0x68(%rsp)
addq $0xc, -0x60(%rsp)
jmp 0x1d1ed
incq %rbx
movq -0x28(%rsp), %r14
movl $0x4b0, %edx            # imm = 0x4B0
addq %rdx, %r14
movq -0x30(%rsp), %rax
addq %rdx, %rax
movq -0x48(%rsp), %r10
decq %r10
movq -0x38(%rsp), %rcx
addq %rdx, %rcx
movq -0x40(%rsp), %r9
addq %rdx, %r9
movq -0x50(%rsp), %rdx
jmp 0x1d18c
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop