// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
cmpl %esi, %edi
jge 0x103f5
leal 0x1(%rdi), %eax
movslq %edi, %rcx
imulq $0x68, %rcx, %rbx
addq 0x19c01(%rip), %rbx     # 0x29f10
cmpl %esi, %eax
je 0x10410
addb $0x3, %dil
movsbq %dil, %rax
imulq $0x68, %rax, %rax
leaq 0x1d576(%rip), %rcx     # 0x2d8a0
leaq (%rcx,%rax), %r14
leaq 0x2011f(%rip), %rdx     # 0x30454
movabsq $0x100000000, %rsi      # imm = 0x100000000
movq %rsi, (%rdx)
movl (%rbx), %r13d
movl %r13d, 0x14(%rsp)
movl 0x4(%rbx), %r15d
movl %r15d, 0x18(%rsp)
movl (%rcx,%rax), %r12d
movl %r12d, 0xc(%rsp)
movl 0x4(%rcx,%rax), %ebp
movl %ebp, 0x10(%rsp)
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x12f50
testl %eax, %eax
jne 0x10399
movl 0x8(%rbx), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc004
addl %eax, %r13d
incl %r13d
movl %r13d, 0x14(%rsp)
movl 0xc(%rbx), %eax
addl %eax, %r15d
decl %r15d
movl %r15d, 0x18(%rsp)
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x12f50
testl %eax, %eax
jne 0x103c1
movl 0x8(%r14), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc004
addl %eax, %r12d
incl %r12d
movl %r12d, 0xc(%rsp)
movl %r15d, %eax
subl %ebp, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
xorl %ecx, %ecx
movq %r13, 0x28(%rsp)
movl %r13d, %eax
subl %r12d, %eax
setl %cl
leal -0x1(,%rcx,2), %ecx
movl %ecx, 0x20(%rsp)
movl $0x0, 0x24(%rsp)
jmp 0x104e2
leal 0x1(%rsi), %eax
movslq %esi, %rcx
imulq $0x68, %rcx, %rbx
addq 0x19b0a(%rip), %rbx     # 0x29f10
cmpl %edi, %eax
movl %esi, %edi
jne 0x10317
incb %dil
movsbq %dil, %rax
imulq $0x68, %rax, %rax
leaq 0x1d47e(%rip), %rcx     # 0x2d8a0
leaq (%rcx,%rax), %r14
leaq 0x20027(%rip), %rdx     # 0x30454
movq $0x1, (%rdx)
movl (%rbx), %r13d
movl %r13d, 0x14(%rsp)
movl 0x4(%rbx), %r15d
movl %r15d, 0x18(%rsp)
movl (%rcx,%rax), %ebp
movl %ebp, 0xc(%rsp)
movl 0x4(%rcx,%rax), %r12d
movl %r12d, 0x10(%rsp)
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x12f50
testl %eax, %eax
jne 0x1048b
movl 0x8(%rbx), %eax
addl %eax, %r13d
decl %r13d
movl %r13d, 0x14(%rsp)
movl 0xc(%rbx), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc004
addl %eax, %r15d
incl %r15d
movl %r15d, 0x18(%rsp)
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x12f50
testl %eax, %eax
jne 0x104b3
movl 0xc(%r14), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc004
addl %eax, %r12d
incl %r12d
movl %r12d, 0x10(%rsp)
movq %r13, 0x28(%rsp)
movl %r13d, %eax
subl %ebp, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
xorl %ecx, %ecx
movl %r15d, %eax
subl %r12d, %eax
setl %cl
leal -0x1(,%rcx,2), %ecx
movl %ecx, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
movl %eax, %r13d
negl %r13d
cmovsl %eax, %r13d
movq %rdx, 0x30(%rsp)
leal -0x2(%rdx), %edi
xorl %eax, %eax
callq 0xc004
movl %eax, 0x1c(%rsp)
movslq 0x60(%rbx), %rax
movq %r14, 0x38(%rbx,%rax,8)
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x12f50
testl %eax, %eax
je 0x1053d
movq 0x19a1a(%rip), %r12     # 0x29f38
movq (%r12), %rdi
movl %r15d, %esi
movq 0x28(%rsp), %rdx
callq 0x6470
movq (%r12), %rdi
pushq $0x23
popq %rsi
callq 0x64a0
jmp 0x1054a
leaq 0x14(%rsp), %rsi
movq %rbx, %rdi
callq 0x1065d
movslq 0x60(%r14), %rax
movq %rbx, 0x38(%r14,%rax,8)
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x12f50
testl %eax, %eax
je 0x10586
movq 0x199cf(%rip), %rbx     # 0x29f38
movq (%rbx), %rdi
movl 0xc(%rsp), %edx
movl 0x10(%rsp), %esi
callq 0x6470
movq (%rbx), %rdi
pushq $0x23
popq %rsi
callq 0x64a0
jmp 0x10593
leaq 0xc(%rsp), %rsi
movq %r14, %rdi
callq 0x1065d
movl 0x14(%rsp), %r14d
movl 0x18(%rsp), %ebx
addl $0x2, 0x1c(%rsp)
leaq 0x1feac(%rip), %rcx     # 0x30454
movq 0x19989(%rip), %r12     # 0x29f38
pushq $0x23
popq %r15
movq 0x30(%rsp), %rbp
addl (%rcx), %r14d
cmpl $0x2, %ebp
jl 0x10622
addl 0x4(%rcx), %ebx
cmpl 0x1c(%rsp), %ebp
jne 0x105fd
testl %r13d, %r13d
jle 0x105fd
subl $0x1, %r13d
jb 0x105f9
movq (%r12), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x6470
movq (%r12), %rdi
movl %r15d, %esi
callq 0x64a0
addl 0x20(%rsp), %r14d
addl 0x24(%rsp), %ebx
jmp 0x105ce
pushq $-0x1
popq %r13
decl %ebp
movq (%r12), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x6470
movq (%r12), %rdi
movl %r15d, %esi
callq 0x64a0
leaq 0x1fe34(%rip), %rcx     # 0x30454
jmp 0x105b8
cmpl 0xc(%rsp), %r14d
jne 0x10641
addl 0x4(%rcx), %ebx
cmpl 0x10(%rsp), %ebx
jne 0x10641
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf01f(%rip), %rdi      # 0x1f667
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb178