// File: /workspace/github_cpp_makefile_star2_O1/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 %eax, %eax
movl %eax, (%rdi)
cmpb $0xa, (%rsi,%rax)
leaq 0x1(%rax), %rax
jne 0x22e1e
movl %eax, %ecx
xorl %r8d, %r8d
movl %r8d, 0x4(%rdi)
movq %r8, %rdx
imulq %rcx, %rdx
incq %r8
cmpb $0x0, (%rsi,%rdx)
jne 0x22e2f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x0, 0x8(%rdi)
movb $0x0, 0x1d4cc(%rdi)
movq $-0x1, 0x1d4ce(%rdi)
movq %rdi, -0x78(%rsp)
movw $0xffff, 0x1d4d6(%rdi)  # imm = 0xFFFF
cmpq $0x1, %r8
je 0x23234
movq -0x78(%rsp), %r9
leaq 0x1d4ce(%r9), %rcx
movq %rcx, -0x20(%rsp)
movabsq $0x100000000, %r11      # imm = 0x100000000
movl 0x8(%r9), %edi
leaq 0xc(%r9), %rcx
movq %rcx, -0x10(%rsp)
movl %eax, %ecx
movq %rcx, -0x50(%rsp)
decq %r8
leaq -0x1(%rax), %rcx
movq %rcx, -0x18(%rsp)
leaq 0x14(%r9), %r14
leaq 0x12(%r9), %rcx
leaq 0x17(%r9), %rdx
addq $0x13, %r9
xorl %ebx, %ebx
movq %r11, -0x70(%rsp)
movq %r8, -0x48(%rsp)
cmpq $0x1, %rax
movq %r14, -0x28(%rsp)
movq %rcx, -0x30(%rsp)
movq %rdx, -0x38(%rsp)
movq %r9, -0x40(%rsp)
je 0x231f8
imulq $0x64, %rbx, %r8
movq %r8, (%rsp)
movq %rbx, %r8
imulq -0x50(%rsp), %r8
movq %r8, -0x8(%rsp)
movq %r9, -0x58(%rsp)
movq %rdx, -0x60(%rsp)
movq %rcx, -0x68(%rsp)
movq %r11, %r15
xorl %r9d, %r9d
imulq $0x4b0, %rbx, %rcx      # imm = 0x4B0
addq -0x10(%rsp), %rcx
leaq (%r9,%r9,2), %rdx
leaq (%rcx,%rdx,4), %r13
movq (%rsp), %rcx
leaq (%r9,%rcx), %rbp
movq -0x8(%rsp), %rcx
addl %r9d, %ecx
movl %ebp, %r12d
movslq %ecx, %rcx
movb (%rsi,%rcx), %r10b
movzbl %r10b, %ecx
cmpl $0x5d, %ecx
jle 0x22f65
cmpl $0x71, %ecx
jg 0x22f71
cmpl $0x5e, %ecx
je 0x22f84
jmp 0x22ff1
cmpl $0x3d, %ecx
jg 0x22f78
cmpl $0x3c, %ecx
je 0x22f84
jmp 0x22fd3
cmpl $0x76, %ecx
je 0x22f84
jmp 0x22fe2
cmpl $0x3e, %ecx
jne 0x2300f
incl %r12d
xorl %ecx, %ecx
cmpb $0x3c, %r10b
sete %cl
leal -0x64(%r12), %edx
cmpb $0x5e, %r10b
cmovnel %r12d, %edx
subl %ecx, %edx
leal 0x64(%rdx), %r12d
cmpb $0x76, %r10b
cmovnel %edx, %r12d
movslq %r12d, %rdx
imulq $0x51eb851f, %rdx, %r8  # imm = 0x51EB851F
movq %r8, %rcx
shrq $0x3f, %rcx
sarq $0x25, %r8
addl %ecx, %r8d
imull $0x64, %r8d, %ecx
subl %ecx, %edx
movl %eax, %ecx
imull %r8d, %ecx
addl %edx, %ecx
jmp 0x22f46
cmpl $0x20, %ecx
je 0x23000
cmpl $0x23, %ecx
jne 0x2300f
movb $-0x2, %r8b
jmp 0x23025
cmpl $0x72, %ecx
je 0x23005
cmpl $0x79, %ecx
jne 0x2300f
movb $0x52, %r8b
jmp 0x23025
cmpl $0x62, %ecx
je 0x2300a
cmpl $0x67, %ecx
jne 0x2300f
movb $0x53, %r8b
jmp 0x23025
movb $-0x1, %r8b
jmp 0x23025
movb $0x50, %r8b
jmp 0x23025
movb $0x51, %r8b
jmp 0x23025
leal -0x30(%r10), %ecx
addb $-0x37, %r10b
cmpb $0xa, %cl
movzbl %cl, %ecx
movzbl %r10b, %r8d
cmovbl %ecx, %r8d
movb %r8b, (%r13)
movb $0x0, 0x1(%r13)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x4(%r13)
movw %r12w, 0x2(%r13)
movsbq %r8b, %rcx
testq %rcx, %rcx
js 0x231d1
incl %edi
movl %edi, -0x7c(%rsp)
movq -0x78(%rsp), %rdx
movl %edi, 0x8(%rdx)
cmpl %ebp, %r12d
jne 0x23084
movq %rdx, %rdi
movq -0x20(%rsp), %rdx
movw %r12w, (%rdx)
cmpb $0x50, %r8b
jl 0x23084
addl %r11d, %ecx
addl $-0x4f, %ecx
movw %r12w, 0x1d4ce(%rdi,%rcx,2)
movb $0x1, 0x1d4cc(%rdi)
movq -0x68(%rsp), %r8
movq %r14, %rdi
movq %r15, %rcx
xorl %ebp, %ebp
movq %r8, %rdx
leaq (%r9,%rbp), %r8
testq %r8, %r8
jle 0x2311a
movq %rbp, %r10
movzbl -0x14(%rdi), %r12d
decq %rbp
movabsq $-0x100000000, %r8      # imm = 0xFFFFFFFF00000000
addq %r8, %rcx
addq $-0xc, %rdi
leaq -0xc(%rdx), %r8
cmpl $0xff, %r12d
je 0x23091
cmpl $0xfe, %r12d
je 0x2311a
movl %ebp, %r8d
negb %r8b
movb %r8b, 0x6(%r13)
movb %r8b, -0x4(%rdi)
sarq $0x20, %rcx
cmpq %r9, %rcx
jge 0x230fc
negq %r10
movb $0x1, %cl
movb %r10b, -0x2(%rdx)
movb %cl, (%rdx)
addq $0xc, %rdx
incb %cl
decq %r10
jne 0x230eb
movzwl -0x6(%rdi), %ecx
cmpw 0x2(%r13), %cx
sete %cl
cmpl $-0x1, %ebp
sete %dl
testb %dl, %cl
je 0x2311a
movb $0x3, %cl
movb %cl, 0xa(%r13)
movb %cl, (%rdi)
movq %r11, %rdi
movq -0x58(%rsp), %rdx
movq -0x60(%rsp), %r11
movq -0x70(%rsp), %rcx
xorl %r8d, %r8d
movq %rdx, %rbp
leaq (%rbx,%r8), %rdx
testq %rdx, %rdx
jle 0x231ca
movq %r8, %r10
movzbl -0x4bb(%r11), %r12d
decq %r8
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
addq %rdx, %rcx
movq $-0x4b0, %rdx           # imm = 0xFB50
addq %rdx, %r11
addq %rbp, %rdx
cmpl $0xff, %r12d
je 0x2312f
cmpl $0xfe, %r12d
je 0x231ca
movl %r8d, %edx
negb %dl
movb %dl, 0x5(%r13)
movb %dl, -0x4(%r11)
sarq $0x20, %rcx
cmpq %rbx, %rcx
jge 0x231a9
negq %r10
movb $0x1, %cl
movb %cl, -0x2(%rbp)
movb %r10b, (%rbp)
addq $0x4b0, %rbp            # imm = 0x4B0
incb %cl
decq %r10
jne 0x23194
movzwl -0x9(%r11), %ecx
cmpw 0x2(%r13), %cx
sete %cl
cmpl $-0x1, %r8d
sete %dl
testb %dl, %cl
je 0x231ca
movb $0x3, %cl
movb %cl, 0x9(%r13)
movb %cl, (%r11)
movq %rdi, %r11
movl -0x7c(%rsp), %edi
incq %r9
addq %r11, %r15
addq $0xc, %r14
addq $0xc, -0x68(%rsp)
addq $0xc, -0x60(%rsp)
addq $0xc, -0x58(%rsp)
cmpq %r9, -0x18(%rsp)
jne 0x22f1f
incq %rbx
movq -0x28(%rsp), %r14
movl $0x4b0, %r8d            # imm = 0x4B0
addq %r8, %r14
movq -0x30(%rsp), %rcx
addq %r8, %rcx
addq %r11, -0x70(%rsp)
movq -0x38(%rsp), %rdx
addq %r8, %rdx
movq -0x40(%rsp), %r9
addq %r8, %r9
movq -0x48(%rsp), %r8
cmpq %rbx, %r8
jne 0x22ed6
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop