// File: /workspace/github_c_makefile_star2_O2/ajpaulson[P]srogue11/passages.c
// Function: do_passages
void do_passages()
{
	struct rdes *r1, *r2;
	int i, j;
	int roomcount;
	static struct rdes {
		bool conn[MAXROOMS];		/* possible to connect to room i */
		bool isconn[MAXROOMS];		/* connection was made to room i */
		bool	ingraph;			/* this room in graph already? */
	} rdes[MAXROOMS] = {
		{{ 0, 1, 0, 1, 0, 0, 0, 0, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
		{{ 1, 0, 1, 0, 1, 0, 0, 0, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
		{{ 0, 1, 0, 0, 0, 1, 0, 0, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
		{{ 1, 0, 0, 0, 1, 0, 1, 0, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
		{{ 0, 1, 0, 1, 0, 1, 0, 1, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
		{{ 0, 0, 1, 0, 1, 0, 0, 0, 1 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
		{{ 0, 0, 0, 1, 0, 0, 0, 1, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
		{{ 0, 0, 0, 0, 1, 0, 1, 0, 1 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
		{{ 0, 0, 0, 0, 0, 1, 0, 1, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
	};

	/*
	 * reinitialize room graph description
	 */
	for (r1 = rdes; r1 < &rdes[MAXROOMS]; r1++) {
		for (j = 0; j < MAXROOMS; j++)
			r1->isconn[j] = FALSE;
		r1->ingraph = FALSE;
	}

	/*
	 * starting with one room, connect it to a random adjacent room and
	 * then pick a new room to start with.
	 */
	roomcount = 1;
	r1 = &rdes[rnd(MAXROOMS)];
	r1->ingraph = TRUE;
	do {
		/*
		 * find a room to connect with
		 */
		j = 0;
		for (i = 0; i < MAXROOMS; i++)
			if (r1->conn[i] && !rdes[i].ingraph && rnd(++j) == 0)
				r2 = &rdes[i];
		/*
		 * if no adjacent rooms are outside the graph, pick a new room
		 * to look from
		 */
		if (j == 0) {
			do {
				r1 = &rdes[rnd(MAXROOMS)];
			} until (r1->ingraph);
		}
		/*
		 * otherwise, connect new room to the graph, and draw a tunnel
		 * to it
		 */
		else {
			r2->ingraph = TRUE;
			i = r1 - rdes;
			j = r2 - rdes;
			conn(i, j);
			r1->isconn[j] = TRUE;
			r2->isconn[i] = TRUE;
			roomcount++;
		}
	} while (roomcount < MAXROOMS);

	/*
	 * attempt to add passages to the graph a random number of times so
	 * that there isn't just one unique passage through it.
	 */
	for (roomcount = rnd(5); roomcount > 0; roomcount--) {
		r1 = &rdes[rnd(MAXROOMS)];	/* a random room to look from */
		/*
		 * find an adjacent room not already connected
		 */
		j = 0;
		for (i = 0; i < MAXROOMS; i++)
			if (r1->conn[i] && !r1->isconn[i] && rnd(++j) == 0)
				r2 = &rdes[i];
		/*
		 * if there is one, connect it and look for the next added
		 * passage
		 */
		if (j != 0) {
			i = r1 - rdes;
			j = r2 - rdes;
			conn(i, j);
			r1->isconn[j] = TRUE;
			r2->isconn[i] = TRUE;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x1d2cf(%rip), %rax     # 0x2d3f9
xorl %ecx, %ecx
pushq $-0x9
popq %rdx
leaq 0x1d2ba(%rip), %r12     # 0x2d3f0
cmpq $0xaa, %rcx
ja 0x10161
movq %rdx, %rsi
testq %rsi, %rsi
je 0x10151
movb $0x0, 0x9(%rax,%rsi)
incq %rsi
jmp 0x10142
movb $0x0, 0x12(%rcx,%r12)
addq $0x13, %rcx
addq $0x13, %rax
jmp 0x10136
pushq $0x9
popq %rdi
xorl %eax, %eax
callq 0xc004
cltq
imulq $0x13, %rax, %rax
leaq (%r12,%rax), %rbx
movb $0x1, 0x12(%rax,%r12)
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
movq %r12, %r14
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq $0x9, %r15
je 0x101b8
cmpb $0x1, (%rbx,%r15)
jne 0x101af
cmpb $0x0, 0x12(%r14)
jne 0x101af
incl %ebp
movl %ebp, %edi
xorl %eax, %eax
callq 0xc004
testl %eax, %eax
cmoveq %r14, %r13
incq %r15
addq $0x13, %r14
jmp 0x1018a
testl %ebp, %ebp
je 0x10205
movb $0x1, %bpl
movb %bpl, 0x12(%r13)
movq %rbx, %rax
subq %r12, %rax
cqto
pushq $0x13
popq %rcx
idivq %rcx
movq %rax, %r14
movq %r13, %rax
subq %r12, %rax
cqto
idivq %rcx
movq %rax, %r15
movl %r14d, %edi
movl %r15d, %esi
callq 0x102e8
movslq %r15d, %rax
movb %bpl, 0x9(%rbx,%rax)
movslq %r14d, %rax
movb %bpl, 0x9(%r13,%rax)
movl 0x4(%rsp), %eax
incl %eax
jmp 0x10226
pushq $0x9
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0xc004
cltq
imulq $0x13, %rax, %rbx
cmpb $0x0, 0x12(%rbx,%r12)
je 0x10208
addq %r12, %rbx
movl 0x4(%rsp), %eax
cmpl $0x9, %eax
jl 0x1017e
pushq $0x5
popq %rdi
xorl %eax, %eax
callq 0xc004
testl %eax, %eax
jle 0x102d9
movl %eax, 0x4(%rsp)
xorl %r12d, %r12d
pushq $0x9
popq %rdi
xorl %eax, %eax
callq 0xc004
movslq %eax, %r14
imulq $0x13, %r14, %rbp
leaq 0x1d190(%rip), %rbx     # 0x2d3f0
addq %rbx, %rbp
xorl %r15d, %r15d
cmpq $0x9, %r12
je 0x10298
cmpb $0x1, (%rbp,%r12)
jne 0x1028f
cmpb $0x0, 0x9(%rbp,%r12)
jne 0x1028f
incl %r15d
movl %r15d, %edi
xorl %eax, %eax
callq 0xc004
testl %eax, %eax
cmoveq %rbx, %r13
incq %r12
addq $0x13, %rbx
jmp 0x10266
testl %r15d, %r15d
je 0x102ce
movq %r13, %rax
leaq 0x1d149(%rip), %rcx     # 0x2d3f0
subq %rcx, %rax
cqto
pushq $0x13
popq %rcx
idivq %rcx
movq %rax, %r15
movl %r14d, %edi
movl %r15d, %esi
callq 0x102e8
movslq %r15d, %rax
movb $0x1, %cl
movb %cl, 0x9(%rbp,%rax)
movb %cl, 0x9(%r13,%r14)
movl 0x4(%rsp), %eax
decl %eax
jmp 0x10239
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq