// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, (%rsp)
movq 0x50(%rsi), %r14
movq %r14, 0x8(%rsp)
movq %r14, %r15
shrq $0x20, %r15
leaq 0x134b3(%rip), %r12     # 0x309e0
movq (%r12), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0x1d551
movq (%r12), %rdi
movsbl 0x8f(%rbx), %esi
callq 0x64c0
cmpq 0xca00(%rip), %rbx      # 0x29f58
je 0x1d583
leaq 0x1348f(%rip), %r13     # 0x309f0
movq (%r13), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0x1d583
movq (%r13), %rdi
movl $0x20, %esi
callq 0x64c0
movq %rsp, %r15
movq %r15, %rdi
callq 0x701c
movl 0x4(%r15), %edi
testl %edi, %edi
js 0x1d5ae
movq %rax, %r14
movl (%rsp), %esi
callq 0x9492
movsbq %al, %rdi
callq 0xb8d5
testb %al, %al
jne 0x1d5cd
xorl %eax, %eax
callq 0xf913
cltq
imulq $0x68, %rax, %r14
addq 0xc94e(%rip), %r14      # 0x29f10
movq %r14, %rdi
callq 0x13f09
movq %rax, %r15
movq (%r15), %rdx
movq %rdx, 0x50(%rbx)
movq %r14, 0x70(%rbx)
movq (%r12), %rdi
movq %rdx, %rsi
shrq $0x20, %rsi
callq 0x6490
cmpl $-0x1, %eax
je 0x1d5f8
movq (%r12), %rdi
callq 0x6330
jmp 0x1d5fa
movb $-0x1, %al
movb %al, 0x8f(%rbx)
leaq 0x8(%rsp), %rdi
callq 0xeba8
movl $0x0, 0x84(%rbx)
cmpq 0xc93d(%rip), %rbx      # 0x29f58
je 0x1d64c
leaq 0x133cc(%rip), %r15     # 0x309f0
movq (%r15), %rdi
movl 0x50(%rbx), %edx
movl 0x54(%rbx), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x1d6bc
movq (%r15), %rdi
movsbl 0x8d(%rbx), %esi
callq 0x64c0
jmp 0x1d6bc
leaq 0x1060d(%rip), %rbx     # 0x2dc60
leaq 0x50(%rbx), %rdi
callq 0xeba8
movq (%r12), %rdi
movl 0x50(%rbx), %edx
movl 0x54(%rbx), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x1d67e
movq (%r12), %rdi
movl $0x40, %esi
callq 0x64c0
movl $0x100, %edi            # imm = 0x100
callq 0x9513
testb %al, %al
je 0x1d696
movl $0x46, %edi
callq 0xdca2
leaq 0x101e7(%rip), %rax     # 0x2d884
movl $0x0, (%rax)
leaq 0x101f2(%rip), %rax     # 0x2d89c
xorl %ebx, %ebx
movb %bl, (%rax)
callq 0x6070
leaq 0x101e9(%rip), %rax     # 0x2d8a3
movb %bl, (%rax)
subq 0xc84d(%rip), %r14      # 0x29f10
shrq $0x3, %r14
imull $0xc4ec4ec5, %r14d, %eax # imm = 0xC4EC4EC5
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq