// File: /workspace/github_c_makefile_star2_O1/ajpaulson[P]srogue11/wizard.c
// Function: teleport
int teleport(struct coord spot,struct thing *th)
{
	int rm, y, x;
	struct coord oldspot;
	struct room *rp;
	bool ishero;

	ishero = (th == &player);
	oldspot = th->t_pos;
	y = th->t_pos.y;
	x = th->t_pos.x;
	mvwaddch(cw, y, x, th->t_oldch); 
	if (!ishero)
		mvwaddch(mw, y, x, ' ');
	rp = roomin(&spot);
	if (spot.y < 0 || !step_ok(winat(spot.y, spot.x))) {
		rp = &rooms[rnd_room()];
		th->t_pos = *rnd_pos(rp);
	}
	else
		th->t_pos = spot;
	rm = rp - &rooms[0];
	th->t_room = rp;
	th->t_oldch = mvwinch(cw, th->t_pos.y, th->t_pos.x);
	light(&oldspot);
	th->t_nomove = 0;
	if (ishero) {
		light(&hero);
		mvwaddch(cw, hero.y, hero.x, PLAYER);
		/*
		 * turn off ISHELD in case teleportation was done
		 * while fighting a Fungi or Bone Devil.
		 */
		if (pl_on(ISHELD))
			unhold('F');
		count = 0;
		running = FALSE;
		flushinp();			/* flush typeahead */
		nochange = FALSE;
	}
	else
		mvwaddch(mw, th->t_pos.y, th->t_pos.x, th->t_type);
	return rm;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, (%rsp)
movq 0x50(%rsi), %rax
movq %rax, 0x8(%rsp)
movl 0x50(%rsi), %ebp
movl 0x54(%rsi), %r14d
leaq 0x133bc(%rip), %r12     # 0x309e0
movq (%r12), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0x1d647
movq (%r12), %rdi
movsbl 0x8f(%rbx), %esi
callq 0x64c0
cmpq 0xc90a(%rip), %rbx      # 0x29f58
je 0x1d676
leaq 0x13399(%rip), %r15     # 0x309f0
movq (%r15), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0x1d676
movq (%r15), %rdi
movl $0x20, %esi
callq 0x64c0
movq %rsp, %r15
movq %r15, %rdi
callq 0x7052
movl 0x4(%r15), %edi
testl %edi, %edi
js 0x1d6a1
movq %rax, %r14
movl (%rsp), %esi
callq 0x9514
movsbq %al, %rdi
callq 0xb995
testb %al, %al
jne 0x1d6c0
xorl %eax, %eax
callq 0xfa3f
cltq
imulq $0x68, %rax, %r14
addq 0xc85b(%rip), %r14      # 0x29f10
movq %r14, %rdi
callq 0x14063
movq %rax, %r15
movq (%r15), %rdx
movq %rdx, 0x50(%rbx)
movq %r14, 0x70(%rbx)
movq (%r12), %rdi
movl 0x54(%rbx), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x1d6e7
movq (%r12), %rdi
callq 0x6330
jmp 0x1d6e9
movb $-0x1, %al
movb %al, 0x8f(%rbx)
leaq 0x8(%rsp), %rdi
callq 0xecbc
movl $0x0, 0x84(%rbx)
cmpq 0xc84e(%rip), %rbx      # 0x29f58
je 0x1d73b
leaq 0x132dd(%rip), %r15     # 0x309f0
movq (%r15), %rdi
movl 0x50(%rbx), %edx
movl 0x54(%rbx), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x1d7ab
movq (%r15), %rdi
movsbl 0x8d(%rbx), %esi
callq 0x64c0
jmp 0x1d7ab
leaq 0x1051e(%rip), %rbx     # 0x2dc60
leaq 0x50(%rbx), %rdi
callq 0xecbc
movq (%r12), %rdi
movl 0x50(%rbx), %edx
movl 0x54(%rbx), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x1d76d
movq (%r12), %rdi
movl $0x40, %esi
callq 0x64c0
movl $0x100, %edi            # imm = 0x100
callq 0x9595
testb %al, %al
je 0x1d785
movl $0x46, %edi
callq 0xdd01
leaq 0x100f8(%rip), %rax     # 0x2d884
movl $0x0, (%rax)
leaq 0x10103(%rip), %rax     # 0x2d89c
xorl %ebx, %ebx
movb %bl, (%rax)
callq 0x6070
leaq 0x100fa(%rip), %rax     # 0x2d8a3
movb %bl, (%rax)
subq 0xc75e(%rip), %r14      # 0x29f10
shrq $0x3, %r14
imull $0xc4ec4ec5, %r14d, %eax # imm = 0xC4EC4EC5
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq