// File: /workspace/github_c_makefile_star2_O2/ajpaulson[P]srogue11/move.c
// Function: do_move
int do_move(int dy,int dx)
{
	int ch;
	struct room *rp;

	firstmove = FALSE;
	curprice = -1;
	inpool = FALSE;

	if (player.t_nomove > 0) {
		player.t_nomove -= 1;
		msg("You are still stuck in the bear trap.");
		return 0;
	}
	/*
	 * Do a confused move (maybe)
	 */
	if ((rnd(100) < 80 && pl_on(ISHUH)) ||
	  (iswearing(R_DELUS) && rnd(100) < 25))
		nh = *rndmove(&player);
	else {
		nh.y = hero.y + dy;
		nh.x = hero.x + dx;
	}
	/*
	 * Check if he tried to move off the screen or make
	 *  an illegal diagonal move, and stop him if he did.
	 */
	if (!cordok(nh.y, nh.x) ||
	  (pl_off(ISETHER) && !diag_ok(&hero, &nh))) {
		after = running = FALSE;
		return 0;
	}
	if (running) {
		ch = winat(nh.y, nh.x);
		if (dead_end(ch)) {
			int gox, goy, apsg, whichway;

			gox = goy = apsg = 0;
			if (dy == 0) {
				ch = show(hero.y+1,hero.x);
				if (ch == PASSAGE) {
					apsg += 1;
					goy = 1;
				}
				ch = show(hero.y-1,hero.x);
				if (ch == PASSAGE) {
					apsg += 1;
					goy = -1;
				}
			}
			else if (dx == 0) {
				ch = show(hero.y,hero.x+1);
				if (ch == PASSAGE) {
					gox = 1;
					apsg += 1;
				}
				ch = show(hero.y,hero.x-1);
				if (ch == PASSAGE) {
					gox = -1;
					apsg += 1;
				}
			}
			if (apsg != 1) {
				running = after = FALSE;
				return 0;
			}
			else {			/* can still run here */
				nh.y = hero.y + goy;
				nh.x = hero.x + gox;
				whichway = (goy + 1) * 3 + gox + 1;
				switch(whichway) {
					case 0: runch = 'y';
					when 1: runch = 'k';
					when 2: runch = 'u';
					when 3: runch = 'h';
					when 4: runch = '.';	/* shouldn't do */
					when 5: runch = 'l';
					when 6: runch = 'b';
					when 7: runch = 'j';
					when 8: runch = 'n';
				}
			}
		}
	}
	if (running && ce(hero, nh))
		after = running = FALSE;
	ch = winat(nh.y, nh.x);
	if (pl_on(ISHELD) && ch != 'F' && ch != 'd') {
		msg("You are being held.");
		return 0;
	}
	if (pl_off(ISETHER)) {
		if (isatrap(ch)) {
			ch = be_trapped(&nh, &player);
			if (nlmove) {
				nlmove = FALSE;
				return 0;
			}
			else if (ch == POOL)
				inpool = TRUE;
		}
	 	else if (dead_end(ch)) {
			after = running = FALSE;
			return 0;
		}
		else {
			switch(ch) {
				case GOLD:	case POTION:	case SCROLL:
				case FOOD:	case WEAPON:	case ARMOR:
				case RING:	case AMULET:	case STICK:
					running = FALSE;
					take = ch;
				default:
					if (illeg_ch(ch)) {
						running = FALSE;
						mvaddch(nh.y, nh.x, FLOOR);
						teleport(rndspot, &player);
						light(&nh);
						msg("The spatial warp disappears !");
						return 0;
					}
			}
		}
	}
	rp = roomin(&nh);
	if (ch == DOOR) {		/* just stepped on a door */
		running = FALSE;
		if (rp != NULL && rf_on(rp, ISTREAS)) {
			struct linked_list *item;
			struct thing *tp;

			for (item = mlist; item != NULL; item = next(item)) {
				tp = THINGPTR(item);
				if (tp->t_room == rp)
					runto(&tp->t_pos, &hero);
			}
		}
	}
	else if (ch == STAIRS && pl_off(ISETHER))
		running = FALSE;
	else if (isalpha(ch) && pl_off(ISETHER)) {
		running = FALSE;
		fight(&nh, cur_weapon, FALSE);
		return 0;
	}
	if (rp == NULL && player.t_room != NULL)
		light(&hero);		/* exiting a room */
	else if (rp != NULL && player.t_room == NULL)
		light(&nh);			/* just entering a room */
	if (pl_on(ISBLIND))
		ch = ' ';
	else
		ch = player.t_oldch;
	mvwaddch(cw, hero.y, hero.x, ch);
	mvwaddch(cw, nh.y, nh.x, PLAYER);
	hero = nh;
	player.t_room = rp;
	player.t_oldch = mvinch(hero.y, hero.x);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x20322(%rip), %rax     # 0x2d88f
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x1cd6c(%rip), %rax     # 0x2a2e4
orl $-0x1, (%rax)
leaq 0x20308(%rip), %r13     # 0x2d88a
movb %cl, (%r13)
leaq 0x206c3(%rip), %r15     # 0x2dc50
movl 0x84(%r15), %eax
testl %eax, %eax
jle 0xd5b4
decl %eax
movl %eax, 0x84(%r15)
leaq 0x11b4e(%rip), %rdi     # 0x1f0f6
xorl %eax, %eax
callq 0xb178
jmp 0xd6ea
movl %esi, %ebx
movl %edi, %ebp
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
cmpl $0x4f, %eax
jg 0xd5d5
movl $0x200, %edi            # imm = 0x200
callq 0x932c
testb %al, %al
jne 0xd5f0
pushq $0xf
popq %rdi
callq 0x11fa5
testb %al, %al
je 0xd613
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
cmpl $0x18, %eax
jg 0xd613
leaq 0x20659(%rip), %rdi     # 0x2dc50
callq 0xea34
movq 0x25895(%rip), %rsi     # 0x32e98
movq %rsi, 0x25886(%rip)     # 0x32e90
movq %rsi, %rdi
shrq $0x20, %rdi
jmp 0xd62b
movl 0x54(%r15), %edi
addl %ebp, %edi
movl %edi, 0x25875(%rip)     # 0x32e94
movl 0x50(%r15), %esi
addl %ebx, %esi
movl %esi, 0x25865(%rip)     # 0x32e90
callq 0x9308
testb %al, %al
je 0xd6d6
movl $0x10000, %edi          # imm = 0x10000
callq 0x933b
testb %al, %al
je 0xd65a
leaq 0x50(%r15), %rdi
leaq 0x2583f(%rip), %rsi     # 0x32e90
callq 0x7398
testb %al, %al
je 0xd6d6
leaq 0x2022b(%rip), %r12     # 0x2d88c
cmpb $0x1, (%r12)
jne 0xd76d
movl 0x25822(%rip), %edi     # 0x32e94
movl 0x25818(%rip), %esi     # 0x32e90
callq 0x92ab
movsbl %al, %edi
callq 0xb415
testb %al, %al
je 0xd76d
pushq $-0x1
popq %r14
testl %ebp, %ebp
je 0xd6fb
testl %ebx, %ebx
jne 0xd816
movl 0x50(%r15), %esi
movl 0x54(%r15), %edi
incl %esi
callq 0xdabc
xorl %ebx, %ebx
cmpb $0x23, %al
sete %bl
movl 0x50(%r15), %esi
movl 0x54(%r15), %edi
decl %esi
callq 0xdabc
leal 0x1(%rbx), %ecx
cmpb $0x23, %al
cmovnel %ebx, %r14d
cmovnel %ebx, %ecx
movl %r14d, %eax
xorl %r14d, %r14d
jmp 0xd72e
leaq 0x201af(%rip), %rax     # 0x2d88c
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x1cc15(%rip), %rax     # 0x2a2fd
movb %cl, (%rax)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x50(%r15), %esi
movl 0x54(%r15), %edi
incl %edi
callq 0xdabc
xorl %ebx, %ebx
cmpb $0x23, %al
sete %bl
movl 0x50(%r15), %esi
movl 0x54(%r15), %edi
decl %edi
callq 0xdabc
cmpb $0x23, %al
cmovnel %ebx, %r14d
leal 0x1(%rbx), %ecx
cmovnel %ebx, %ecx
xorl %eax, %eax
cmpl $0x1, %ecx
jne 0xd816
movl %r14d, %ecx
addl 0x54(%r15), %ecx
movl %ecx, 0x25750(%rip)     # 0x32e94
movl 0x50(%r15), %ecx
addl %eax, %ecx
movl %ecx, 0x25740(%rip)     # 0x32e90
leal (%r14,%r14,2), %ecx
addl %eax, %ecx
movslq %ecx, %rax
leaq 0x11ccb(%rip), %rcx     # 0x1f42b
movb 0x4(%rax,%rcx), %al
leaq 0x206fa(%rip), %rcx     # 0x2de65
movb %al, (%rcx)
movl 0x2571d(%rip), %esi     # 0x32e90
cmpb $0x0, (%r12)
je 0xd7a1
movl 0x50(%r15), %eax
movl 0x25710(%rip), %edi     # 0x32e94
cmpl %esi, %eax
jne 0xd7a7
cmpl %edi, 0x54(%r15)
jne 0xd79d
xorl %ecx, %ecx
movb %cl, (%r12)
leaq 0x1cb62(%rip), %rdx     # 0x2a2fd
movb %cl, (%rdx)
movl %eax, %esi
jmp 0xd7a7
movl 0x256ed(%rip), %edi     # 0x32e94
callq 0x92ab
movl %eax, %ebp
movl $0x100, %edi            # imm = 0x100
callq 0x932c
movzbl %bpl, %ebx
testb %al, %al
je 0xd7cb
cmpb $0x46, %bpl
je 0xd7cb
cmpl $0x64, %ebx
jne 0xd84a
movl $0x10000, %edi          # imm = 0x10000
callq 0x933b
testb %al, %al
je 0xd90b
movsbl %bpl, %r14d
movl %r14d, %edi
callq 0xdbbb
testb %al, %al
je 0xd82a
leaq 0x2569c(%rip), %rdi     # 0x32e90
leaq 0x20455(%rip), %rsi     # 0x2dc50
callq 0xdbe6
movl %eax, %ebp
leaq 0x20080(%rip), %rax     # 0x2d889
cmpb $0x1, (%rax)
jne 0xd856
movb $0x0, (%rax)
jmp 0xd6ea
leaq 0x1cae0(%rip), %rax     # 0x2a2fd
xorl %ecx, %ecx
movb %cl, (%rax)
movb %cl, (%r12)
jmp 0xd6ea
movl %r14d, %edi
callq 0xb415
testb %al, %al
je 0xd87b
xorl %eax, %eax
movb %al, (%r12)
leaq 0x1caba(%rip), %rcx     # 0x2a2fd
movb %al, (%rcx)
jmp 0xd6ea
leaq 0xfd24(%rip), %rdi      # 0x1d575
jmp 0xd5a8
cmpb $0x22, %bpl
jne 0xd90b
movb $0x1, (%r13)
leaq 0x25624(%rip), %rdi     # 0x32e90
callq 0x6f44
movq %rax, %rbx
pushq $0x22
jmp 0xd994
leal -0x21(%rbx), %eax
cmpl $0x3c, %eax
ja 0xd8a2
movabsq $0x1000000052004b01, %rcx # imm = 0x1000000052004B01
btq %rax, %rcx
jae 0xd8a2
movb $0x0, (%r12)
leaq 0x205c5(%rip), %rax     # 0x2de64
movb %bpl, (%rax)
movl %ebx, %edi
callq 0xb758
testb %al, %al
je 0xd90b
movb $0x0, (%r12)
movq 0x1c67f(%rip), %rbx     # 0x29f38
movq (%rbx), %rdi
movl 0x255d2(%rip), %esi     # 0x32e94
movl 0x255c8(%rip), %edx     # 0x32e90
callq 0x6470
cmpl $-0x1, %eax
je 0xd8dd
movq (%rbx), %rdi
pushq $0x2e
popq %rsi
callq 0x64a0
leaq 0x1cabc(%rip), %rax     # 0x2a3a0
movq (%rax), %rdi
leaq 0x20362(%rip), %rsi     # 0x2dc50
callq 0x1b91f
leaq 0x25596(%rip), %rdi     # 0x32e90
callq 0xe29f
leaq 0x11816(%rip), %rdi     # 0x1f11c
jmp 0xd5a8
leaq 0x2557e(%rip), %rdi     # 0x32e90
callq 0x6f44
movq %rax, %rbx
cmpb $0x25, %bpl
je 0xd977
movzbl %bpl, %eax
cmpl $0x2b, %eax
jne 0xd98c
movb $0x0, (%r12)
testq %rbx, %rbx
je 0xd9d6
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x12f50
testl %eax, %eax
je 0xd9d8
leaq 0x1fedf(%rip), %r12     # 0x2d830
leaq 0x50(%r15), %r14
movq (%r12), %r12
testq %r12, %r12
je 0xd9d8
movq 0x10(%r12), %rdi
cmpq %rbx, 0x70(%rdi)
jne 0xd955
addq $0x50, %rdi
movq %r14, %rsi
callq 0x7427
jmp 0xd955
movl $0x10000, %edi          # imm = 0x10000
callq 0x933b
testb %al, %al
je 0xd992
movb $0x0, (%r12)
jmp 0xd9d8
movsbq %bpl, %r14
jmp 0xd996
pushq $0x25
popq %r14
callq 0x6590
movq (%rax), %rax
testb $0x4, 0x1(%rax,%r14,2)
je 0xd9d8
movl $0x10000, %edi          # imm = 0x10000
callq 0x933b
testb %al, %al
je 0xd9d8
movb $0x0, (%r12)
leaq 0x1fe80(%rip), %rax     # 0x2d840
movq (%rax), %rsi
leaq 0x254c6(%rip), %rdi     # 0x32e90
xorl %edx, %edx
callq 0x96f0
jmp 0xd6ea
xorl %ebx, %ebx
testq %rbx, %rbx
sete %cl
movq 0x70(%r15), %rax
testq %rax, %rax
setne %dl
testb %dl, %cl
je 0xd9f2
leaq 0x50(%r15), %rdi
jmp 0xda0b
testq %rbx, %rbx
setne %cl
testq %rax, %rax
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0xda10
leaq 0x25485(%rip), %rdi     # 0x32e90
callq 0xe29f
pushq $0x1
popq %rdi
callq 0x932c
movl %eax, %r14d
movsbl 0x8f(%r15), %ebp
leaq 0x22fa6(%rip), %r12     # 0x309d0
movq (%r12), %rdi
movl 0x50(%r15), %edx
movl 0x54(%r15), %esi
callq 0x6470
cmpl $-0x1, %eax
je 0xda54
testb %r14b, %r14b
pushq $0x20
popq %rax
cmovnel %eax, %ebp
movq (%r12), %rdi
movl %ebp, %esi
callq 0x64a0
movq (%r12), %rdi
movl 0x25436(%rip), %esi     # 0x32e94
movl 0x2542c(%rip), %edx     # 0x32e90
callq 0x6470
cmpl $-0x1, %eax
je 0xda7a
movq (%r12), %rdi
pushq $0x40
popq %rsi
callq 0x64a0
movq 0x2540f(%rip), %rdx     # 0x32e90
movq %rdx, 0x50(%r15)
movq %rbx, 0x70(%r15)
movq 0x1c4a8(%rip), %rbx     # 0x29f38
movq (%rbx), %rdi
movq %rdx, %rsi
shrq $0x20, %rsi
callq 0x6470
cmpl $-0x1, %eax
je 0xdaae
movq (%rbx), %rdi
callq 0x6320
jmp 0xdab0
movb $-0x1, %al
movb %al, 0x8f(%r15)
jmp 0xd6ea