// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
leaq 0x1fb21(%rip), %rax     # 0x2d89f
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x1c56b(%rip), %rax     # 0x2a2f4
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x1fb04(%rip), %r12     # 0x2d89a
movb %cl, (%r12)
leaq 0x1febf(%rip), %r15     # 0x2dc60
movl 0x84(%r15), %eax
testl %eax, %eax
jle 0xddc8
decl %eax
movl %eax, 0x84(%r15)
leaq 0x1333a(%rip), %rdi     # 0x210f6
xorl %eax, %eax
callq 0xb620
jmp 0xdeff
movl %esi, %ebx
movl %edi, %ebp
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x4f, %eax
jg 0xddeb
movl $0x200, %edi            # imm = 0x200
callq 0x9513
testb %al, %al
jne 0xde0a
movl $0xf, %edi
callq 0x12c34
testb %al, %al
je 0xde2d
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x18, %eax
jg 0xde2d
leaq 0x1fe4f(%rip), %rdi     # 0x2dc60
callq 0xf412
movq 0x2508b(%rip), %rsi     # 0x32ea8
movq %rsi, 0x2507c(%rip)     # 0x32ea0
movq %rsi, %rdi
shrq $0x20, %rdi
jmp 0xde45
movl 0x54(%r15), %edi
addl %ebp, %edi
movl %edi, 0x2506b(%rip)     # 0x32ea4
movl 0x50(%r15), %esi
addl %ebx, %esi
movl %esi, 0x2505b(%rip)     # 0x32ea0
callq 0x94ef
testb %al, %al
je 0xdeeb
movl $0x10000, %edi          # imm = 0x10000
callq 0x9522
testb %al, %al
je 0xde74
leaq 0x50(%r15), %rdi
leaq 0x25035(%rip), %rsi     # 0x32ea0
callq 0x742a
testb %al, %al
je 0xdeeb
leaq 0x1fa21(%rip), %r14     # 0x2d89c
cmpb $0x1, (%r14)
jne 0xdf7e
movl 0x25019(%rip), %edi     # 0x32ea4
movl 0x2500f(%rip), %esi     # 0x32ea0
callq 0x9492
movsbl %al, %edi
callq 0xb91a
testb %al, %al
je 0xdf7e
testl %ebp, %ebp
je 0xdf0a
testl %ebx, %ebx
jne 0xe024
movl 0x50(%r15), %esi
movl 0x54(%r15), %edi
incl %esi
callq 0xe2de
xorl %ebx, %ebx
cmpb $0x23, %al
sete %bl
movl 0x50(%r15), %esi
movl 0x54(%r15), %edi
decl %esi
callq 0xe2de
cmpb $0x23, %al
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %ebx, %eax
leal 0x1(%rbx), %edx
cmovnel %ebx, %edx
xorl %ecx, %ecx
jmp 0xdf41
leaq 0x1f9aa(%rip), %rax     # 0x2d89c
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x1c410(%rip), %rax     # 0x2a30d
movb %cl, (%rax)
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x50(%r15), %esi
movl 0x54(%r15), %edi
incl %edi
callq 0xe2de
xorl %ebx, %ebx
cmpb $0x23, %al
sete %bl
movl 0x50(%r15), %esi
movl 0x54(%r15), %edi
decl %edi
callq 0xe2de
cmpb $0x23, %al
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovnel %ebx, %ecx
leal 0x1(%rbx), %edx
cmovnel %ebx, %edx
xorl %eax, %eax
cmpl $0x1, %edx
jne 0xe024
movl %ecx, %edx
addl 0x54(%r15), %edx
movl %edx, 0x24f4e(%rip)     # 0x32ea4
movl 0x50(%r15), %edx
addl %eax, %edx
movl %edx, 0x24f3e(%rip)     # 0x32ea0
leal (%rcx,%rcx,2), %ecx
addl %eax, %ecx
movslq %ecx, %rax
leaq 0x134ba(%rip), %rcx     # 0x2142b
movb 0x4(%rax,%rcx), %al
leaq 0x1fef9(%rip), %rcx     # 0x2de75
movb %al, (%rcx)
movl 0x24f1c(%rip), %esi     # 0x32ea0
cmpb $0x0, (%r14)
je 0xdfb0
movl 0x50(%r15), %eax
movl 0x24f10(%rip), %edi     # 0x32ea4
cmpl %esi, %eax
jne 0xdfb6
cmpl %edi, 0x54(%r15)
jne 0xdfac
xorl %ecx, %ecx
movb %cl, (%r14)
leaq 0x1c363(%rip), %rdx     # 0x2a30d
movb %cl, (%rdx)
movl %eax, %esi
jmp 0xdfb6
movl 0x24eee(%rip), %edi     # 0x32ea4
callq 0x9492
movl %eax, %ebp
movl $0x100, %edi            # imm = 0x100
callq 0x9513
testb %al, %al
je 0xdfda
cmpb $0x46, %bpl
je 0xdfda
movzbl %bpl, %eax
cmpl $0x64, %eax
jne 0xe055
movl $0x10000, %edi          # imm = 0x10000
callq 0x9522
testb %al, %al
je 0xe11c
movsbl %bpl, %ebx
movl %ebx, %edi
callq 0xe41e
testb %al, %al
je 0xe037
leaq 0x24e9e(%rip), %rdi     # 0x32ea0
leaq 0x1fc57(%rip), %rsi     # 0x2dc60
callq 0xe449
movl %eax, %ebp
leaq 0x1f882(%rip), %rax     # 0x2d899
cmpb $0x1, (%rax)
jne 0xe061
movb $0x0, (%rax)
jmp 0xdeff
leaq 0x1c2e2(%rip), %rax     # 0x2a30d
xorl %ecx, %ecx
movb %cl, (%rax)
movb %cl, (%r14)
jmp 0xdeff
movl %ebx, %edi
callq 0xb91a
testb %al, %al
je 0xe08a
xorl %eax, %eax
movb %al, (%r14)
leaq 0x1c2bf(%rip), %rcx     # 0x2a30d
movb %al, (%rcx)
jmp 0xdeff
leaq 0x11519(%rip), %rdi     # 0x1f575
jmp 0xddbc
cmpb $0x22, %bpl
jne 0xe11c
movb $0x1, (%r12)
leaq 0x24e29(%rip), %rdi     # 0x32ea0
callq 0x701c
movq %rax, %rbx
movl $0x22, %r12d
jmp 0xe1b3
movzbl %bpl, %edi
leal -0x21(%rdi), %eax
cmpl $0x3c, %eax
ja 0xe0b4
movabsq $0x1000000052004b01, %rcx # imm = 0x1000000052004B01
btq %rax, %rcx
jae 0xe0b4
movb $0x0, (%r14)
leaq 0x1fdc3(%rip), %rax     # 0x2de74
movb %bpl, (%rax)
callq 0xbca6
testb %al, %al
je 0xe11c
movb $0x0, (%r14)
movq 0x1be68(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
movl 0x24dd3(%rip), %esi     # 0x32ea4
movl 0x24dc9(%rip), %edx     # 0x32ea0
callq 0x6490
cmpl $-0x1, %eax
je 0xe0ee
movq (%rbx), %rdi
movl $0x2e, %esi
callq 0x64c0
leaq 0x1c2bb(%rip), %rax     # 0x2a3b0
movq (%rax), %rdi
leaq 0x1fb61(%rip), %rsi     # 0x2dc60
callq 0x1d502
leaq 0x24d95(%rip), %rdi     # 0x32ea0
callq 0xeba8
leaq 0x13005(%rip), %rdi     # 0x2111c
jmp 0xddbc
leaq 0x24d7d(%rip), %rdi     # 0x32ea0
callq 0x701c
movq %rax, %rbx
cmpb $0x25, %bpl
je 0xe195
movzbl %bpl, %eax
cmpl $0x2b, %eax
jne 0xe1af
movb $0x0, (%r14)
testq %rbx, %rbx
je 0xe1f8
movl $0x4, %esi
movq %rbx, %rdi
callq 0x13d18
testl %eax, %eax
je 0xe1f2
leaq 0x1f6dd(%rip), %rax     # 0x2d840
movq (%rax), %r12
testq %r12, %r12
je 0xe1f2
leaq 0x50(%r15), %r14
movq 0x10(%r12), %rdi
cmpq %rbx, 0x70(%rdi)
jne 0xe18a
addq $0x50, %rdi
movq %r14, %rsi
callq 0x74b9
movq (%r12), %r12
testq %r12, %r12
jne 0xe173
jmp 0xe1fa
movl $0x10000, %edi          # imm = 0x10000
callq 0x9522
movl $0x25, %r12d
testb %al, %al
je 0xe1b3
movb $0x0, (%r14)
jmp 0xe1fa
movsbq %bpl, %r12
callq 0x65b0
movq (%rax), %rax
testb $0x4, 0x1(%rax,%r12,2)
je 0xe1fa
movl $0x10000, %edi          # imm = 0x10000
callq 0x9522
testb %al, %al
je 0xe1fa
movb $0x0, (%r14)
leaq 0x1f674(%rip), %rax     # 0x2d850
movq (%rax), %rsi
leaq 0x24cba(%rip), %rdi     # 0x32ea0
xorl %edx, %edx
callq 0x9954
jmp 0xdeff
movq 0x70(%r15), %rax
jmp 0xe216
xorl %ebx, %ebx
testq %rbx, %rbx
sete %cl
movq 0x70(%r15), %rax
testq %rax, %rax
setne %dl
testb %dl, %cl
je 0xe216
leaq 0x50(%r15), %rdi
xorl %ebx, %ebx
jmp 0xe227
testq %rbx, %rbx
je 0xe22c
testq %rax, %rax
jne 0xe22c
leaq 0x24c79(%rip), %rdi     # 0x32ea0
callq 0xeba8
movl $0x1, %edi
callq 0x9513
movl %eax, %r14d
movsbl 0x8f(%r15), %ebp
leaq 0x22798(%rip), %r12     # 0x309e0
movq (%r12), %rdi
movl 0x50(%r15), %edx
movl 0x54(%r15), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0xe274
testb %r14b, %r14b
movl $0x20, %eax
cmovnel %eax, %ebp
movq (%r12), %rdi
movl %ebp, %esi
callq 0x64c0
movq (%r12), %rdi
movl 0x24c26(%rip), %esi     # 0x32ea4
movl 0x24c1c(%rip), %edx     # 0x32ea0
callq 0x6490
cmpl $-0x1, %eax
je 0xe29c
movq (%r12), %rdi
movl $0x40, %esi
callq 0x64c0
movq 0x24bfd(%rip), %rdx     # 0x32ea0
movq %rdx, 0x50(%r15)
movq %rbx, 0x70(%r15)
movq 0x1bc7e(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
movq %rdx, %rsi
shrq $0x20, %rsi
callq 0x6490
cmpl $-0x1, %eax
je 0xe2d0
movq (%rbx), %rdi
callq 0x6330
jmp 0xe2d2
movb $-0x1, %al
movb %al, 0x8f(%r15)
jmp 0xdeff