// File: lotuskip[P]yuxtapa/server/map.cpp
// Function: (anonymous namespace)::room_recur(char, char, char)
void room_recur(const char rx, const char ry, const char dir)
{
	if(rooms[ry*ROOM_NUM+rx])
		return;
	rooms[ry*ROOM_NUM+rx] = true;
	// See where we can branch from here:
	bool branches[4] = {  (dir != 0 && ry != 0) /*N*/,
		(dir != 1 && rx != ROOM_NUM-1) /*E*/,
		(dir != 2 && ry != ROOM_NUM-1) /*S*/,
		(dir != 3 && rx != 0) /*W*/ };
	char (*rot_func)(const char, const char, const char*) = &rot_0;
	// Make a random kind of room here:
	char room_type; // index to the 'roomcell' table
	// First room (dir == -1) must not be a corridor only, and we favour
	// the non-corridors otherwise, too:
	if(dir == -1 || !(random()%5))
		room_type = random()%2; // 0 or 1 is okay
	else
		room_type = random()%7;
	switch(room_type)
	{
	case 1: case 6: /* #..  #.#  rotate these similarly
			         * #..  #..
			         * ###  ###  */
		if(dir != -1)
		{
			if(random()%2) // dir enters from the top
			{
				rot_func = rot_fs[dir];
				branches[(dir+2)%4] = branches[(dir+3)%4] = false;
			}
			else // dir enters from the side
			{
				rot_func = rot_fs[(dir+3)%4];
				branches[(dir+1)%4] = branches[(dir+2)%4] = false;
			}
		}
		else
			branches[2] = branches[3] = false;
		break;
	case 4: /* #.#  can branch only one way
			 * #.#
			 * ### */
		if(dir != -1)
			rot_func = rot_fs[dir];
		branches[0] = branches[1] = branches[2] = branches[3] = false;
		break;
	case 3: /* #.# can branch N / S
			 * #.#
			 * #.# */
		if(dir%2)
		{
			rot_func = rot_90;
			branches[0] = branches[2] = false;
		}
		else
			branches[1] = branches[3] = false;
		break;
	// default: (Others can branch any way and don't need rotation.)
	}

	// Put the room in place:
	char x, y;
	for(y = 0; y < ROOM_SIZE; ++y)
	{
		for(x = 0; x < ROOM_SIZE; ++x)
			house[(ry*ROOM_SIZE+1+y)*MAX_HS+rx*ROOM_SIZE+1+x]
				= rot_func(x, y, roomcell[room_type]);
	}

	// Branch where-ever we can:
	if(branches[0]) room_recur(rx, ry-1, 2);
	if(branches[1]) room_recur(rx+1, ry, 3);
	if(branches[2]) room_recur(rx, ry+1, 0);
	if(branches[3]) room_recur(rx-1, ry, 1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %dl, %al
movb %sil, %cl
movb %dil, %dl
movb %dl, -0x1(%rbp)
movb %cl, -0x2(%rbp)
movb %al, -0x3(%rbp)
movsbl -0x2(%rbp), %eax
shll $0x2, %eax
movsbl -0x1(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x62e10(%rip), %rax     # 0x90d40
testb $0x1, (%rax,%rcx)
je 0x2df3b
jmp 0x2e2b9
movsbl -0x2(%rbp), %eax
shll $0x2, %eax
movsbl -0x1(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x62dee(%rip), %rax     # 0x90d40
movb $0x1, (%rax,%rcx)
movsbl -0x3(%rbp), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x14(%rbp)
je 0x2df71
movsbl -0x2(%rbp), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x14(%rbp)
movb -0x14(%rbp), %al
andb $0x1, %al
movb %al, -0x7(%rbp)
leaq -0x7(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movsbl -0x3(%rbp), %ecx
xorl %eax, %eax
cmpl $0x1, %ecx
movb %al, -0x15(%rbp)
je 0x2dfa0
movsbl -0x1(%rbp), %eax
cmpl $0x3, %eax
setne %al
movb %al, -0x15(%rbp)
movq -0x20(%rbp), %rax
movb -0x15(%rbp), %cl
andb $0x1, %cl
movb %cl, (%rax)
leaq -0x7(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movsbl -0x3(%rbp), %ecx
xorl %eax, %eax
cmpl $0x2, %ecx
movb %al, -0x21(%rbp)
je 0x2dfd3
movsbl -0x2(%rbp), %eax
cmpl $0x3, %eax
setne %al
movb %al, -0x21(%rbp)
movq -0x30(%rbp), %rax
movb -0x21(%rbp), %cl
andb $0x1, %cl
movb %cl, (%rax)
leaq -0x7(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x40(%rbp)
movsbl -0x3(%rbp), %ecx
xorl %eax, %eax
cmpl $0x3, %ecx
movb %al, -0x31(%rbp)
je 0x2e006
movsbl -0x1(%rbp), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x31(%rbp)
movq -0x40(%rbp), %rax
movb -0x31(%rbp), %cl
andb $0x1, %cl
movb %cl, (%rax)
leaq 0x2a7(%rip), %rax       # 0x2e2c0
movq %rax, -0x10(%rbp)
movsbl -0x3(%rbp), %eax
cmpl $-0x1, %eax
je 0x2e03b
callq 0x5270
movl $0x5, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x2e051
callq 0x5270
movl $0x2, %ecx
cqto
idivq %rcx
movb %dl, %al
movb %al, -0x11(%rbp)
jmp 0x2e065
callq 0x5270
movl $0x7, %ecx
cqto
idivq %rcx
movb %dl, %al
movb %al, -0x11(%rbp)
movsbl -0x11(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x5, %eax
ja 0x2e1ae
movq -0x48(%rbp), %rax
leaq 0x33c17(%rip), %rcx     # 0x61c9c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movsbl -0x3(%rbp), %eax
cmpl $-0x1, %eax
je 0x2e145
callq 0x5270
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x2e0f4
movsbq -0x3(%rbp), %rcx
leaq 0x5f4b4(%rip), %rax     # 0x8d570
movq (%rax,%rcx,8), %rax
movq %rax, -0x10(%rbp)
movsbl -0x3(%rbp), %eax
addl $0x3, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movslq %edx, %rax
movb $0x0, -0x7(%rbp,%rax)
movsbl -0x3(%rbp), %eax
addl $0x2, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movslq %edx, %rax
movb $0x0, -0x7(%rbp,%rax)
jmp 0x2e143
movsbl -0x3(%rbp), %eax
addl $0x3, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x5f463(%rip), %rax     # 0x8d570
movq (%rax,%rcx,8), %rax
movq %rax, -0x10(%rbp)
movsbl -0x3(%rbp), %eax
addl $0x2, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movslq %edx, %rax
movb $0x0, -0x7(%rbp,%rax)
movsbl -0x3(%rbp), %eax
addl $0x1, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movslq %edx, %rax
movb $0x0, -0x7(%rbp,%rax)
jmp 0x2e14d
movb $0x0, -0x4(%rbp)
movb $0x0, -0x5(%rbp)
jmp 0x2e1ae
movsbl -0x3(%rbp), %eax
cmpl $-0x1, %eax
je 0x2e16c
movsbq -0x3(%rbp), %rcx
leaq 0x5f40c(%rip), %rax     # 0x8d570
movq (%rax,%rcx,8), %rax
movq %rax, -0x10(%rbp)
movb $0x0, -0x4(%rbp)
movb $0x0, -0x5(%rbp)
movb $0x0, -0x6(%rbp)
movb $0x0, -0x7(%rbp)
jmp 0x2e1ae
movsbl -0x3(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x2e1a4
leaq 0x15a(%rip), %rax       # 0x2e2f0
movq %rax, -0x10(%rbp)
movb $0x0, -0x5(%rbp)
movb $0x0, -0x7(%rbp)
jmp 0x2e1ac
movb $0x0, -0x4(%rbp)
movb $0x0, -0x6(%rbp)
jmp 0x2e1ae
movb $0x0, -0x13(%rbp)
movsbl -0x13(%rbp), %eax
cmpl $0x3, %eax
jge 0x2e240
movb $0x0, -0x12(%rbp)
movsbl -0x12(%rbp), %eax
cmpl $0x3, %eax
jge 0x2e231
movq -0x10(%rbp), %rax
movb -0x12(%rbp), %sil
movb -0x13(%rbp), %cl
movsbq -0x11(%rbp), %rdi
leaq 0x33c1d(%rip), %rdx     # 0x61e00
imulq $0x9, %rdi, %rdi
addq %rdi, %rdx
movsbl %sil, %edi
movsbl %cl, %esi
callq *%rax
movb %al, %dl
movsbl -0x2(%rbp), %eax
imull $0x3, %eax, %eax
addl $0x1, %eax
movsbl -0x13(%rbp), %ecx
addl %ecx, %eax
imull $0xe, %eax, %eax
movsbl -0x1(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl %ecx, %eax
addl $0x1, %eax
movsbl -0x12(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x62a4c(%rip), %rax     # 0x90c70
movb %dl, (%rax,%rcx)
movb -0x12(%rbp), %al
addb $0x1, %al
movb %al, -0x12(%rbp)
jmp 0x2e1c3
jmp 0x2e233
movb -0x13(%rbp), %al
addb $0x1, %al
movb %al, -0x13(%rbp)
jmp 0x2e1b2
testb $0x1, -0x7(%rbp)
je 0x2e260
movb -0x1(%rbp), %cl
movsbl -0x2(%rbp), %eax
subl $0x1, %eax
movl $0x2, %edx
movsbl %cl, %edi
movsbl %al, %esi
callq 0x2df00
testb $0x1, -0x6(%rbp)
je 0x2e27e
movsbl -0x1(%rbp), %eax
addl $0x1, %eax
movl $0x3, %edx
movsbl %al, %edi
movsbl -0x2(%rbp), %esi
callq 0x2df00
testb $0x1, -0x5(%rbp)
je 0x2e29b
movb -0x1(%rbp), %cl
movsbl -0x2(%rbp), %eax
addl $0x1, %eax
xorl %edx, %edx
movsbl %cl, %edi
movsbl %al, %esi
callq 0x2df00
testb $0x1, -0x4(%rbp)
je 0x2e2b9
movsbl -0x1(%rbp), %eax
subl $0x1, %eax
movl $0x1, %edx
movsbl %al, %edi
movsbl -0x2(%rbp), %esi
callq 0x2df00
addq $0x50, %rsp
popq %rbp
retq
nop