// File: /workspace/github_cpp_makefile_star2_O3/lotuskip[P]yuxtapa/server/map.cpp
// Function: (anonymous namespace)::gen_house(bool)
void gen_house(const bool outdoor)
{
	unsigned short sh;
	for(sh = 0; sh < MAX_HS*MAX_HS; ++sh)
		house[sh] = '#';
	for(sh = 0; sh < ROOM_NUM*ROOM_NUM; ++sh)
		rooms[sh] = false;
	
	// This calls itself recursively:
	room_recur(random()%ROOM_NUM, random()%ROOM_NUM, -1);

	// Remove extra (surrounding) walls; any wall that has as neighbours
	// only '#' or '_' becomes '_'. While looping, also place doors and
	// windows.
	Coords c, d;
	string card;
	bool outwall;
	size_t i;
	for(c.y = 0; c.y < MAX_HS; ++(c.y))
	{
		for(c.x = 0; c.x < MAX_HS; ++(c.x))
		{
			if(house[c.y*MAX_HS+c.x] == '#')
			{
				card.clear();
				outwall = true;
				for(sh = 0; sh < MAX_D; ++sh)
				{
					d = c.in(e_Dir(sh));
					if(d.x >= 0 && d.y >= 0 && d.x < MAX_HS && d.y < MAX_HS)
					{
						if(house[d.y*MAX_HS+d.x] == '.' || house[d.y*MAX_HS+d.x] == ':')
							outwall = false;
						if(!(sh%2)) // cardinal direction
							card += house[d.y*MAX_HS+d.x];
					}
					else if(!(sh%2))
						card += '_'; // outside of buffer
				}
				if(outwall)
					house[c.y*MAX_HS+c.x] = '_';
				else // See if this is a wall we could place a window on
				{
					// replace any ':' with '.' (there can be at most one)
					if((i = card.find(':')) != string::npos)
						card[sh] = '.';
					if(card == "_#.#" || card == ".#_#")
						house[c.y*MAX_HS+c.x] = '-';
					else if(card == "#.#_" || card == "#_#.")
						house[c.y*MAX_HS+c.x] = '|';
				}
			}
			// Check if could place a door:
			else if(house[c.y*MAX_HS+c.x] == ':'
				&& random()%3 // skip every 2nd potential door loc
				&& house[(c.y+1)*MAX_HS+c.x] == house[(c.y-1)*MAX_HS+c.x]
				&& house[c.y*MAX_HS+c.x+1] == house[c.y*MAX_HS+c.x-1])
				house[c.y*MAX_HS+c.x] = '+';
		}
	}

	// The windows we placed above were only "preliminary plans". At least one
	// of them must be replaced by our front door, and if we are not outside,
	// there can be no windows!
	//First place a front door:
	outwall = false;
	do {
		sh = random()%(MAX_HS*MAX_HS);
		while(sh)
		{
			if(house[sh] == '|' || house[sh] == '-')
			{
				house[sh] = '+';
				outwall = true;
				break;
			}
			--sh;
		}
	} while(!outwall);
	// Next, remove all or some windows and add more doors:
	char num = 0; // number of additional doors
	for(sh = 0; sh < MAX_HS*MAX_HS; ++sh)
	{
		if(house[sh] == '|' || house[sh] == '-')
		{
			if(num < 3 && !(random()%10)) // another front door
			{
				house[sh] = '+';
				++num;
			}
			else if(!outdoor || random()%4)
				house[sh] = '#';
		}
		// possibly turn some walls into illusions: 
		else if(!outdoor && house[sh] == '#' && !(random()%15))
			house[sh] = 'I';
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edi, -0x34(%rbp)
leaq 0x2d357(%rip), %rdi     # 0x43b00
movl $0xc4, %edx
movl $0x23, %esi
callq 0x4200
xorps %xmm0, %xmm0
movaps %xmm0, 0x2d40e(%rip)    # 0x43bd0
callq 0x41d0
movq %rax, %rbx
addl $0x3, %eax
testq %rbx, %rbx
cmovnsl %ebx, %eax
movl $0xfc, %r14d
andl %r14d, %eax
subl %eax, %ebx
callq 0x41d0
leal 0x3(%rax), %ecx
testq %rax, %rax
cmovnsl %eax, %ecx
andl %r14d, %ecx
subl %ecx, %eax
movsbl %bl, %edi
movsbl %al, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x18437
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b798
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b798
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x2c(%rbp), %r15
movw $0x0, 0x2(%r15)
leaq -0x38(%rbp), %r12
leaq -0x58(%rbp), %r13
leaq 0x2d2b8(%rip), %r14     # 0x43b00
movw $0x0, -0x2c(%rbp)
xorl %ecx, %ecx
movswq %cx, %rax
movswq -0x2a(%rbp), %rdx
leaq (%rdx,%rdx), %rsi
shlq $0x4, %rdx
subq %rsi, %rdx
addq %rax, %rdx
movzbl (%r14,%rdx), %eax
cmpl $0x3a, %eax
je 0x16957
cmpl $0x23, %eax
jne 0x16a81
movq $0x0, -0x50(%rbp)
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
movb $0x1, %r14b
xorl %ebx, %ebx
movq %r12, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x2b818
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
movq %r12, %rdi
callq 0x2b7a6
movzwl -0x30(%rbp), %eax
cmpq $0xe, %rax
setb %dl
movzwl -0x2e(%rbp), %ecx
cmpw $0xe, %cx
setb %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x16907
movzwl %cx, %ecx
leaq (%rcx,%rcx), %rdx
shll $0x4, %ecx
subq %rdx, %rcx
addq %rax, %rcx
leaq 0x2d21c(%rip), %rax     # 0x43b00
movzbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
je 0x168f2
cmpl $0x2e, %eax
jne 0x168f5
xorl %r14d, %r14d
testb $0x1, %bl
jne 0x16919
movsbl %al, %esi
movq %r13, %rdi
callq 0x4340
jmp 0x16919
testb $0x1, %bl
jne 0x16919
movq %r13, %rdi
movl $0x5f, %esi
callq 0x4340
incl %ebx
cmpl $0x8, %ebx
jne 0x16892
testb $0x1, %r14b
je 0x169cf
movswq -0x2a(%rbp), %rax
leaq (%rax,%rax), %rcx
shlq $0x4, %rax
subq %rcx, %rax
movswq -0x2c(%rbp), %rcx
addq %rcx, %rax
leaq 0x2d1b3(%rip), %r14     # 0x43b00
movb $0x5f, (%r14,%rax)
jmp 0x16a81
callq 0x41d0
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
movabsq $0x2aaaaaaaaaaaaaaa, %rcx # imm = 0x2AAAAAAAAAAAAAAA
addq %rcx, %rax
movzwl -0x2c(%rbp), %ecx
movabsq $0x5555555555555555, %rdx # imm = 0x5555555555555555
cmpq %rdx, %rax
jb 0x16a81
movswq %cx, %rdx
movswq -0x2a(%rbp), %rax
leaq (%rax,%rax), %rsi
shlq $0x4, %rax
subq %rsi, %rax
addq %rdx, %rax
movb 0xe(%rax,%r14), %dl
cmpb -0xe(%rax,%r14), %dl
jne 0x16a81
movb 0x1(%rax,%r14), %dl
cmpb -0x1(%rax,%r14), %dl
jne 0x16a81
movb $0x2b, (%rax,%r14)
jmp 0x16a81
movq %r13, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4550
cmpq $-0x1, %rax
leaq 0x2d117(%rip), %r14     # 0x43b00
je 0x169f3
movq -0x58(%rbp), %rax
movb $0x2e, 0x8(%rax)
movq %r13, %rdi
leaq 0x1835a(%rip), %rsi     # 0x2ed57
callq 0x4120
testl %eax, %eax
je 0x16a45
movq %r13, %rdi
leaq 0x1834c(%rip), %rsi     # 0x2ed5c
callq 0x4120
testl %eax, %eax
je 0x16a45
movq %r13, %rdi
leaq 0x1833e(%rip), %rsi     # 0x2ed61
callq 0x4120
testl %eax, %eax
je 0x16a64
movq %r13, %rdi
leaq 0x18330(%rip), %rsi     # 0x2ed66
callq 0x4120
testl %eax, %eax
je 0x16a64
movzwl -0x2c(%rbp), %ecx
jmp 0x16a81
movswq -0x2a(%rbp), %rax
leaq (%rax,%rax), %rcx
shlq $0x4, %rax
subq %rcx, %rax
movswq -0x2c(%rbp), %rcx
addq %rcx, %rax
movb $0x2d, (%r14,%rax)
jmp 0x16a81
movswq -0x2a(%rbp), %rax
leaq (%rax,%rax), %rcx
shlq $0x4, %rax
subq %rcx, %rax
movswq -0x2c(%rbp), %rcx
addq %rcx, %rax
movb $0x7c, (%r14,%rax)
incl %ecx
movw %cx, -0x2c(%rbp)
cmpw $0xe, %cx
jl 0x16850
movzwl -0x2a(%rbp), %eax
incl %eax
movw %ax, -0x2a(%rbp)
cmpw $0xe, %ax
jl 0x16848
movabsq $0x5397829cbc14e5e1, %rbx # imm = 0x5397829CBC14E5E1
callq 0x41d0
movq %rax, %rcx
imulq %rbx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x6, %rdx
addq %rax, %rdx
imulq $0xc4, %rdx, %rax
subq %rax, %rcx
je 0x16aaf
movzwl %cx, %ecx
movzbl (%rcx,%r14), %eax
cmpl $0x2d, %eax
je 0x16aed
cmpl $0x7c, %eax
je 0x16aed
decw %cx
jne 0x16ad4
jmp 0x16aaf
movb $0x2b, (%rcx,%r14)
xorl %ebx, %ebx
movabsq $-0x3333333333333333, %r14 # imm = 0xCCCCCCCCCCCCCCCD
movabsq $0x1999999999999998, %r15 # imm = 0x1999999999999998
movabsq $0x1111111111111110, %r12 # imm = 0x1111111111111110
xorl %r13d, %r13d
leaq 0x2cfe4(%rip), %rax     # 0x43b00
movzbl (%rbx,%rax), %eax
cmpl $0x7c, %eax
je 0x16b2a
cmpl $0x2d, %eax
jne 0x16b60
cmpb $0x2, %r13b
jg 0x16b44
callq 0x41d0
imulq %r14, %rax
addq %r15, %rax
rorq %rax
cmpq %r15, %rax
jbe 0x16b9c
cmpb $0x0, -0x34(%rbp)
je 0x16b53
callq 0x41d0
testb $0x3, %al
je 0x16baa
leaq 0x2cfa6(%rip), %rax     # 0x43b00
movb $0x23, (%rbx,%rax)
jmp 0x16baa
cmpb $0x23, %al
setne %al
orb -0x34(%rbp), %al
jne 0x16baa
callq 0x41d0
movabsq $-0x1111111111111111, %rcx # imm = 0xEEEEEEEEEEEEEEEF
imulq %rcx, %rax
movabsq $0x888888888888888, %rcx # imm = 0x888888888888888
addq %rcx, %rax
cmpq %r12, %rax
ja 0x16baa
leaq 0x2cf6a(%rip), %rax     # 0x43b00
movb $0x49, (%rbx,%rax)
jmp 0x16baa
leaq 0x2cf5d(%rip), %rax     # 0x43b00
movb $0x2b, (%rbx,%rax)
incb %r13b
incq %rbx
cmpq $0xc4, %rbx
jne 0x16b15
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x16bd3
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x30(%rbp), %rdi
callq 0x2b7a6
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x16c20
jmp 0x16bfb
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x16c17
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x30(%rbp), %rdi
callq 0x2b7a6
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
movq %rbx, %rdi
callq 0x4740
nop