// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x154f3
movl -0x4(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x4(%rbp), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jne 0x154ed
movb $0x72, -0x1a(%rbp)
jmp 0x154f1
movb $0x64, -0x1a(%rbp)
jmp 0x15510
movl -0x8(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x8(%rbp), %eax
addl $0x1, %eax
cmpl -0x4(%rbp), %eax
jne 0x1550a
movb $0x72, -0x1a(%rbp)
jmp 0x1550e
movb $0x64, -0x1a(%rbp)
jmp 0x15510
movslq -0x2c(%rbp), %rcx
leaq 0x21805(%rip), %rax     # 0x36d20
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movsbl -0x1a(%rbp), %eax
cmpl $0x64, %eax
jne 0x15658
movl -0x2c(%rbp), %eax
addl $0x3, %eax
movb %al, -0x19(%rbp)
movsbq -0x19(%rbp), %rcx
leaq 0x217d8(%rip), %rax     # 0x36d20
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
leaq 0x2437a(%rip), %rax     # 0x398d4
movl $0x0, (%rax)
leaq 0x2436d(%rip), %rax     # 0x398d4
movl $0x1, 0x4(%rax)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x19950
cmpl $0x0, %eax
jne 0x155d1
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edi
subl $0x2, %edi
movb $0x0, %al
callq 0xef20
addl $0x1, %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
subl $0x1, %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl $0x2, %esi
callq 0x19950
cmpl $0x0, %eax
jne 0x155fe
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edi
subl $0x2, %edi
movb $0x0, %al
callq 0xef20
addl $0x1, %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x40(%rbp), %eax
subl -0x48(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x44(%rbp), %edx
movl -0x4c(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x44(%rbp), %eax
subl -0x4c(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %edi
subl $0x1, %edi
movb $0x0, %al
callq 0xef20
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x15797
movsbl -0x1a(%rbp), %eax
cmpl $0x72, %eax
jne 0x15787
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movb %al, -0x19(%rbp)
movsbq -0x19(%rbp), %rcx
leaq 0x216a6(%rip), %rax     # 0x36d20
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
leaq 0x24248(%rip), %rax     # 0x398d4
movl $0x1, (%rax)
leaq 0x2423b(%rip), %rax     # 0x398d4
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x19950
cmpl $0x0, %eax
jne 0x15703
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edi
subl $0x2, %edi
movb $0x0, %al
callq 0xef20
addl $0x1, %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl $0x2, %esi
callq 0x19950
cmpl $0x0, %eax
jne 0x15730
movq -0x18(%rbp), %rax
movl 0xc(%rax), %edi
subl $0x2, %edi
movb $0x0, %al
callq 0xef20
addl $0x1, %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
subl -0x4c(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x40(%rbp), %edx
movl -0x48(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x40(%rbp), %eax
subl -0x48(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %edi
subl $0x1, %edi
movb $0x0, %al
callq 0xef20
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x15795
leaq 0x1644d(%rip), %rdi     # 0x2bbdb
movb $0x0, %al
callq 0xd8f0
jmp 0x15797
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x60(%rcx), %rcx
movq %rdx, 0x38(%rax,%rcx,8)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x19950
cmpl $0x0, %eax
je 0x157ea
movq 0x1d7fa(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x6490
movq 0x1d7e5(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movl $0x23, %esi
callq 0x64c0
jmp 0x157f7
movq -0x10(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x15970
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x60(%rcx), %rcx
movq %rdx, 0x38(%rax,%rcx,8)
movq -0x18(%rbp), %rdi
movl $0x2, %esi
callq 0x19950
cmpl $0x0, %eax
je 0x1584a
movq 0x1d79a(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movl -0x48(%rbp), %esi
movl -0x4c(%rbp), %edx
callq 0x6490
movq 0x1d785(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movl $0x23, %esi
callq 0x64c0
jmp 0x15857
movq -0x18(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x15970
movl -0x44(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x15922
leaq 0x24060(%rip), %rax     # 0x398d4
movl (%rax), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
leaq 0x24051(%rip), %rax     # 0x398d4
movl 0x4(%rax), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0x158eb
cmpl $0x0, -0x28(%rbp)
jle 0x158eb
jmp 0x1589c
movl -0x28(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x28(%rbp)
cmpl $0x0, %eax
jle 0x158e9
movq 0x1d70d(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
callq 0x6490
movq 0x1d6f8(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movl $0x23, %esi
callq 0x64c0
movl -0x3c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x1589c
jmp 0x158eb
movq 0x1d6ce(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
callq 0x6490
movq 0x1d6b9(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movl $0x23, %esi
callq 0x64c0
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x15863
leaq 0x23fab(%rip), %rax     # 0x398d4
movl (%rax), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
leaq 0x23f9c(%rip), %rax     # 0x398d4
movl 0x4(%rax), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jne 0x15951
movl -0x30(%rbp), %eax
cmpl -0x48(%rbp), %eax
je 0x1595f
leaq 0x1629f(%rip), %rdi     # 0x2bbf7
movb $0x0, %al
callq 0xd8f0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)