// File: /workspace/github_c_makefile_star2_O1/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
leal 0x1(%rdi), %eax
xorl %ecx, %ecx
cmpl %esi, %eax
sete %cl
leal 0x1(%rsi), %eax
xorl %edx, %edx
cmpl %edi, %eax
sete %dl
cmpl %esi, %edi
cmovll %ecx, %edx
cmovll %edi, %esi
movslq %esi, %rax
imulq $0x68, %rax, %rbx
addq 0x18f77(%rip), %rbx     # 0x29f10
shlq $0x38, %rax
testb %dl, %dl
je 0x1107a
movabsq $0x100000000000000, %rcx # imm = 0x100000000000000
addq %rcx, %rax
sarq $0x38, %rax
imulq $0x68, %rax, %rax
leaq 0x1c8ef(%rip), %rcx     # 0x2d8b0
leaq (%rcx,%rax), %r14
leaq 0x1f498(%rip), %rdx     # 0x30464
movq $0x1, (%rdx)
movl (%rbx), %r13d
movl %r13d, 0x4(%rsp)
movl 0x4(%rbx), %r12d
movl %r12d, 0x8(%rsp)
movl (%rcx,%rax), %ebp
movl %ebp, 0xc(%rsp)
movl 0x4(%rcx,%rax), %r15d
movl %r15d, 0x10(%rsp)
movl $0x2, %esi
movq %rbx, %rdi
callq 0x13e74
testl %eax, %eax
jne 0x11028
movl 0x8(%rbx), %eax
addl %r13d, %eax
decl %eax
movl %eax, 0x4(%rsp)
movl 0xc(%rbx), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc72d
addl %r12d, %eax
incl %eax
movl %eax, 0x8(%rsp)
movl $0x2, %esi
movq %r14, %rdi
callq 0x13e74
testl %eax, %eax
jne 0x11050
movl 0xc(%r14), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc72d
addl %r15d, %eax
incl %eax
movl %eax, 0x10(%rsp)
movl 0x4(%rsp), %eax
subl %ebp, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
movl 0x8(%rsp), %eax
xorl %ecx, %ecx
subl 0x10(%rsp), %eax
setl %cl
leal -0x1(,%rcx,2), %r12d
xorl %r13d, %r13d
jmp 0x11150
movabsq $0x300000000000000, %rcx # imm = 0x300000000000000
addq %rcx, %rax
sarq $0x38, %rax
imulq $0x68, %rax, %rax
leaq 0x1c81a(%rip), %rcx     # 0x2d8b0
leaq (%rcx,%rax), %r14
leaq 0x1f3c3(%rip), %rdx     # 0x30464
movabsq $0x100000000, %rsi      # imm = 0x100000000
movq %rsi, (%rdx)
movl (%rbx), %r13d
movl %r13d, 0x4(%rsp)
movl 0x4(%rbx), %r12d
movl %r12d, 0x8(%rsp)
movl (%rcx,%rax), %r15d
movl %r15d, 0xc(%rsp)
movl 0x4(%rcx,%rax), %ebp
movl %ebp, 0x10(%rsp)
movl $0x2, %esi
movq %rbx, %rdi
callq 0x13e74
testl %eax, %eax
jne 0x11103
movl 0x8(%rbx), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc72d
addl %r13d, %eax
incl %eax
movl %eax, 0x4(%rsp)
movl 0xc(%rbx), %eax
addl %r12d, %eax
decl %eax
movl %eax, 0x8(%rsp)
movl $0x2, %esi
movq %r14, %rdi
callq 0x13e74
testl %eax, %eax
jne 0x1112b
movl 0x8(%r14), %edi
addl $-0x2, %edi
xorl %eax, %eax
callq 0xc72d
addl %r15d, %eax
incl %eax
movl %eax, 0xc(%rsp)
movl 0x8(%rsp), %eax
subl %ebp, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
movl 0x4(%rsp), %eax
xorl %ecx, %ecx
subl 0xc(%rsp), %eax
setl %cl
leal -0x1(,%rcx,2), %r13d
xorl %r12d, %r12d
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
movq %rdx, 0x18(%rsp)
leal -0x2(%rdx), %edi
xorl %eax, %eax
callq 0xc72d
movl %eax, 0x14(%rsp)
movslq 0x60(%rbx), %rax
movq %r14, 0x38(%rbx,%rax,8)
movl $0x2, %esi
movq %rbx, %rdi
callq 0x13e74
testl %eax, %eax
je 0x111aa
movq 0x18da5(%rip), %r15     # 0x29f30
movq (%r15), %rdi
movl 0x4(%rsp), %edx
movl 0x8(%rsp), %esi
callq 0x6490
movq (%r15), %rdi
movl $0x23, %esi
callq 0x64c0
jmp 0x111b7
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0x112e7
movslq 0x60(%r14), %rax
movq %rbx, 0x38(%r14,%rax,8)
movl $0x2, %esi
movq %r14, %rdi
callq 0x13e74
testl %eax, %eax
je 0x111f7
movq 0x18d58(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
movl 0xc(%rsp), %edx
movl 0x10(%rsp), %esi
callq 0x6490
movq (%rbx), %rdi
movl $0x23, %esi
callq 0x64c0
jmp 0x11204
leaq 0xc(%rsp), %rsi
movq %r14, %rdi
callq 0x112e7
movl 0x4(%rsp), %r14d
movl 0x8(%rsp), %ebx
movq 0x18(%rsp), %rax
cmpl $0x2, %eax
jb 0x112a2
addl $0x2, 0x14(%rsp)
movq 0x18d09(%rip), %r15     # 0x29f30
leaq 0x1f236(%rip), %rcx     # 0x30464
addl (%rcx), %r14d
addl 0x4(%rcx), %ebx
cmpl 0x14(%rsp), %eax
movq %rax, 0x18(%rsp)
jne 0x11276
testl %ebp, %ebp
jle 0x11276
incl %ebp
movq (%r15), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x6490
movq (%r15), %rdi
movl $0x23, %esi
callq 0x64c0
addl %r13d, %r14d
addl %r12d, %ebx
decl %ebp
cmpl $0x1, %ebp
jg 0x11245
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rax
leal -0x1(%rax), %ecx
movl %ecx, 0x24(%rsp)
movq (%r15), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x6490
movq (%r15), %rdi
movl $0x23, %esi
callq 0x64c0
cmpl $0x2, 0x18(%rsp)
movl 0x24(%rsp), %eax
jg 0x11227
leaq 0x1f1bb(%rip), %rax     # 0x30464
addl (%rax), %r14d
cmpl 0xc(%rsp), %r14d
jne 0x112cb
addl 0x4(%rax), %ebx
cmpl 0x10(%rsp), %ebx
jne 0x112cb
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1031d(%rip), %rdi     # 0x215ef
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb6e0