// File: /workspace/github_c_makefile_star2_O3/ajpaulson[P]srogue11/passages.c
// Function: conn
void conn(int r1,int r2)
{
	struct room *rpf, *rpt;
	char rmt, direc;
	int distance, turn_spot, turn_distance, rm;
	struct coord curr, turn_delta, spos, epos;

	if (r1 < r2) {
		rm = r1;
		if (r1 + 1 == r2)
			direc = 'r';
		else
			direc = 'd';
	}
	else {
		rm = r2;
		if (r2 + 1 == r1)
			direc = 'r';
		else
			direc = 'd';
	}
	rpf = &rooms[rm];
	/*
	 * Set up the movement variables, in two cases:
	 * first drawing one down.
	 */
	if (direc == 'd') {
		rmt = rm + 3;				/* room # of dest */
		rpt = &rooms[rmt];			/* room pointer of dest */
		delta.x = 0;				/* direction of move */
		delta.y = 1;
		spos.x = rpf->r_pos.x;			/* start of move */
		spos.y = rpf->r_pos.y;
		epos.x = rpt->r_pos.x;			/* end of move */
		epos.y = rpt->r_pos.y;
		if (!rf_on(rpf,ISGONE)) {		/* if not gone pick door pos */
			spos.x += rnd(rpf->r_max.x-2)+1;
			spos.y += rpf->r_max.y-1;
		}
		if (!rf_on(rpt,ISGONE))
			epos.x += rnd(rpt->r_max.x-2)+1;
		distance = abs(spos.y - epos.y) - 1;	/* distance to move */
		turn_delta.y = 0;						/* direction to turn */
		turn_delta.x = (spos.x < epos.x ? 1 : -1);
		turn_distance = abs(spos.x - epos.x);	/* how far to turn */
		turn_spot = rnd(distance-1) + 1;		/* where turn starts */
	}
	else if (direc == 'r') {		/* setup for moving right */
		rmt = rm + 1;
		rpt = &rooms[rmt];
		delta.x = 1;
		delta.y = 0;
		spos.x = rpf->r_pos.x;
		spos.y = rpf->r_pos.y;
		epos.x = rpt->r_pos.x;
		epos.y = rpt->r_pos.y;
		if (!rf_on(rpf,ISGONE)) {
			spos.x += rpf->r_max.x-1;
			spos.y += rnd(rpf->r_max.y-2)+1;
		}
		if (!rf_on(rpt,ISGONE))
			epos.y += rnd(rpt->r_max.y-2)+1;
		distance = abs(spos.x - epos.x) - 1;
		turn_delta.y = (spos.y < epos.y ? 1 : -1);
		turn_delta.x = 0;
		turn_distance = abs(spos.y - epos.y);
		turn_spot = rnd(distance-1) + 1;
	}
	else {
		msg("Error in connection tables.");
	}
	/*
	 * Draw in the doors on either side of the passage
	 * or just put #'s if the rooms are gone. Set up
	 * pointers to the connected room.
	 */
	rpf->r_ptr[rpf->r_nexits] = rpt;
	if (rf_on(rpf,ISGONE)) {
		cmov(spos);
		addch('#');		/* gone "from" room */
	}
	else
		door(rpf, &spos);	/* add the door */
	rpt->r_ptr[rpt->r_nexits] = rpf;
	if (rf_on(rpt,ISGONE)) {
		cmov(epos);
		addch('#');		/* gone "to" room */
	}
	else
		door(rpt, &epos);	/* add door */
	/*
	 * Get ready to move...
	 */
	curr.x = spos.x;
	curr.y = spos.y;
	while(distance > 0) {
		/*
		 * Move to new position
		 */
		curr.x += delta.x;
		curr.y += delta.y;
		/*
		 * Check if we are at the turn place, if so do the turn
		 */
		if (distance == turn_spot && turn_distance > 0) {
			while(turn_distance-- > 0) {
				cmov(curr);
				addch(PASSAGE);
				curr.x += turn_delta.x;
				curr.y += turn_delta.y;
			}
		}
		/*
		 * Continue digging along
		 */
		cmov(curr);
		addch(PASSAGE);
		distance--;
	}
	curr.x += delta.x;
	curr.y += delta.y;
	if (!ce(curr, epos)) {
		msg("Warning, connectivity problem on this level.");
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl %esi, %edi
jge 0x10eee
leal 0x1(%rdi), %eax
movslq %edi, %rcx
imulq $0x68, %rcx, %rbx
addq 0x19104(%rip), %rbx     # 0x29f10
cmpl %esi, %eax
je 0x10f09
addb $0x3, %dil
movsbq %dil, %rax
imulq $0x68, %rax, %rax
leaq 0x1ca89(%rip), %rcx     # 0x2d8b0
leaq (%rcx,%rax), %r14
leaq 0x1f632(%rip), %rdx     # 0x30464
movabsq $0x100000000, %rsi      # imm = 0x100000000
movq %rsi, (%rdx)
movl (%rbx), %r13d
movl %r13d, 0xc(%rsp)
movl 0x4(%rbx), %r12d
movl %r12d, 0x10(%rsp)
movl (%rcx,%rax), %r15d
movl %r15d, 0x4(%rsp)
movl 0x4(%rcx,%rax), %ebp
movl %ebp, 0x8(%rsp)
movl $0x2, %esi
movq %rbx, %rdi
callq 0x13d18
testl %eax, %eax
jne 0x10e98
movl 0x8(%rbx), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc674
addl %eax, %r13d
incl %r13d
movl %r13d, 0xc(%rsp)
movl 0xc(%rbx), %eax
addl %eax, %r12d
decl %r12d
movl %r12d, 0x10(%rsp)
movl $0x2, %esi
movq %r14, %rdi
callq 0x13d18
testl %eax, %eax
jne 0x10ec2
movl 0x8(%r14), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc674
addl %eax, %r15d
incl %r15d
movl %r15d, 0x4(%rsp)
movq %r12, 0x18(%rsp)
movl %r12d, %eax
subl %ebp, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
xorl %ecx, %ecx
movl %r13d, %eax
subl %r15d, %eax
setl %cl
leal -0x1(,%rcx,2), %r12d
xorl %r15d, %r15d
jmp 0x10fd7
leal 0x1(%rsi), %eax
movslq %esi, %rcx
imulq $0x68, %rcx, %rbx
addq 0x19011(%rip), %rbx     # 0x29f10
cmpl %edi, %eax
movl %esi, %edi
jne 0x10e14
incb %dil
movsbq %dil, %rax
imulq $0x68, %rax, %rax
leaq 0x1c995(%rip), %rcx     # 0x2d8b0
leaq (%rcx,%rax), %r14
leaq 0x1f53e(%rip), %rdx     # 0x30464
movq $0x1, (%rdx)
movl (%rbx), %r13d
movl %r13d, 0xc(%rsp)
movl 0x4(%rbx), %r12d
movl %r12d, 0x10(%rsp)
movl (%rcx,%rax), %ebp
movl %ebp, 0x4(%rsp)
movl 0x4(%rcx,%rax), %r15d
movl %r15d, 0x8(%rsp)
movl $0x2, %esi
movq %rbx, %rdi
callq 0x13d18
testl %eax, %eax
jne 0x10f86
movl 0x8(%rbx), %eax
addl %eax, %r13d
decl %r13d
movl %r13d, 0xc(%rsp)
movl 0xc(%rbx), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc674
addl %eax, %r12d
incl %r12d
movl %r12d, 0x10(%rsp)
movl $0x2, %esi
movq %r14, %rdi
callq 0x13d18
testl %eax, %eax
jne 0x10fb0
movl 0xc(%r14), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc674
addl %eax, %r15d
incl %r15d
movl %r15d, 0x8(%rsp)
movl %r13d, %eax
subl %ebp, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
xorl %ecx, %ecx
movq %r12, 0x18(%rsp)
movl %r12d, %eax
subl %r15d, %eax
setl %cl
leal -0x1(,%rcx,2), %r15d
xorl %r12d, %r12d
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
movq %rdx, 0x20(%rsp)
leal -0x2(%rdx), %edi
xorl %eax, %eax
callq 0xc674
movl %eax, 0x14(%rsp)
movslq 0x60(%rbx), %rax
movq %r14, 0x38(%rbx,%rax,8)
movl $0x2, %esi
movq %rbx, %rdi
callq 0x13d18
testl %eax, %eax
je 0x11033
movq %r13, %rdx
movq 0x18f1b(%rip), %r13     # 0x29f30
movq (%r13), %rdi
movq 0x18(%rsp), %rsi
callq 0x6490
movq (%r13), %rdi
movl $0x23, %esi
callq 0x64c0
jmp 0x11040
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0x1116f
movslq 0x60(%r14), %rax
movq %rbx, 0x38(%r14,%rax,8)
movl $0x2, %esi
movq %r14, %rdi
callq 0x13d18
testl %eax, %eax
je 0x11080
movq 0x18ecf(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
movl 0x4(%rsp), %edx
movl 0x8(%rsp), %esi
callq 0x6490
movq (%rbx), %rdi
movl $0x23, %esi
callq 0x64c0
jmp 0x1108d
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
callq 0x1116f
movl 0xc(%rsp), %r14d
movl 0x10(%rsp), %ebx
movq 0x20(%rsp), %rax
cmpl $0x2, %eax
jb 0x1112a
addl $0x2, 0x14(%rsp)
movq 0x18e80(%rip), %r13     # 0x29f30
leaq 0x1f3ad(%rip), %rcx     # 0x30464
addl (%rcx), %r14d
addl 0x4(%rcx), %ebx
cmpl 0x14(%rsp), %eax
movq %rax, 0x20(%rsp)
jne 0x110fc
testl %ebp, %ebp
jle 0x110fc
movq (%r13), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x6490
movq (%r13), %rdi
movl $0x23, %esi
callq 0x64c0
addl %r12d, %r14d
addl %r15d, %ebx
decl %ebp
jne 0x110cc
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x20(%rsp), %rax
leal -0x1(%rax), %ecx
movl %ecx, 0x18(%rsp)
movq (%r13), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x6490
movq (%r13), %rdi
movl $0x23, %esi
callq 0x64c0
cmpl $0x2, 0x20(%rsp)
movl 0x18(%rsp), %eax
jg 0x110b0
leaq 0x1f333(%rip), %rax     # 0x30464
addl (%rax), %r14d
cmpl 0x4(%rsp), %r14d
jne 0x11153
addl 0x4(%rax), %ebx
cmpl 0x8(%rsp), %ebx
jne 0x11153
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1050d(%rip), %rdi     # 0x21667
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb620