// File: /workspace/github_c_makefile_star2_O2/ajpaulson[P]srogue11/move.c
// Function: be_trapped
char be_trapped(struct coord *tc,struct thing *th)
{
	struct trap *trp;
	int ch, ishero;
	struct linked_list *mon;
	char stuckee[35], seeit, sayso;

	if ((trp = trap_at(tc->y, tc->x)) == NULL)
		return 0;
	ishero = (th == &player);
	if (ishero) {
		strcpy(stuckee, "You");
		count = running = FALSE;
	}
	else {
		sprintf(stuckee, "The %s", monsters[th->t_indx].m_name);
	}
	seeit = cansee(tc->y, tc->x);
	if (seeit)
		mvwaddch(cw, tc->y, tc->x, trp->tr_type);
	trp->tr_flags |= ISFOUND;
	sayso = TRUE;
	switch (ch = trp->tr_type) {
		case POST:
			if (ishero) {
				nlmove = TRUE;
				new_level(POSTLEV);
			}
			else
				goto goner;
		when MAZETRAP:
			if (ishero) {
				nlmove = TRUE;
				level += 1;
				new_level(MAZELEV);
				msg("You are surrounded by twisty passages!");
			}
			else
				goto goner;
		when TELTRAP:
			nlmove = TRUE;
			teleport(trp->tr_goto, th);
		when TRAPDOOR:
			if (ishero) {
				level += 1;
				new_level(NORMLEV);
			}
			else {		/* monsters get lost */
goner:
				ch = GONER;
			}
			nlmove = TRUE;
			if (seeit && sayso)
				msg("%s fell into a trap!", stuckee);
		when BEARTRAP:
			th->t_nomove += BEARTIME;
			if (seeit) {
				strcat(stuckee, (ishero ? " are" : " is"));
				msg("%s caught in a bear trap.", stuckee);
			}
		when SLEEPTRAP:
			if (ishero && pl_on(ISINVINC))
				msg("You feel momentarily dizzy.");
			else {
				if (ishero)
					th->t_nocmd += SLEEPTIME;
				else
					th->t_nomove += SLEEPTIME;
				if (seeit)
					msg("%s fall%s asleep in a strange white mist.",
					  stuckee, (ishero ? "":"s"));
			}
		when ARROWTRAP: {
			int resist, ac;
			struct stats *it;

			stuckee[0] = tolower(stuckee[0]);
			it = &th->t_stats;
			if (ishero && cur_armor != NULL)
				ac = cur_armor->o_ac;
			else
				ac = it->s_arm;
			resist = ac + getpdex(it, FALSE);
			if (ishero && pl_on(ISINVINC))
				resist = -100;		/* invincible is impossible to hit */
			if (swing(3 + (level / 4), resist, 1)) {
				if (seeit)
					msg("%sAn arrow shot %s.", (ishero ? "Oh no! " : ""),
					  stuckee);
				if (ishero)
					chg_hpt(-roll(1,6),FALSE,K_ARROW);
				else {
					it->s_hpt -= roll(1,6);
					if (it->s_hpt < 1) {
						sayso = FALSE;
						goto goner;
					}
				}
			}
			else {
				struct linked_list *item;
				struct object *arrow;

				if (seeit)
					msg("An arrow shoots past %s.", stuckee);
				item = new_thing(FALSE, WEAPON, ARROW);
				arrow = OBJPTR(item);
				arrow->o_hplus = 3;
				arrow->o_dplus = rnd(2);
				arrow->o_count = 1;
		 		arrow->o_pos = th->t_pos;
				fall(item, FALSE);
			}
		}
		when DARTTRAP: {
			int resist, ac;
			struct stats *it;

			stuckee[0] = tolower(stuckee[0]);
			it = &th->t_stats;
			if (ishero && cur_armor != NULL)
				ac = cur_armor->o_ac;
			else
				ac = it->s_arm;
			resist = ac + getpdex(it, FALSE);
			if (ishero && pl_on(ISINVINC))
				resist = -100;		/* invincible is impossible to hit */
			if (swing(3 + (level / 4), resist, 0)) {
				if (seeit)
					msg("A small dart just hit %s.", stuckee);
				if (ishero) {
					if (!save(VS_POISON))
						chg_abil(CON,-1,TRUE);
					if (!iswearing(R_SUSTSTR))
						chg_abil(STR,-1,TRUE);
					chg_hpt(-roll(1, 4),FALSE,K_DART);
				}
				else {
					if (!save_throw(VS_POISON, th))
						it->s_ef.a_str -= 1;
					it->s_hpt -= roll(1, 4);
					if (it->s_hpt < 1) {
						sayso = FALSE;
						goto goner;
					}
				}
			}
			else if (seeit)
				msg("A small dart whizzes by %s.", stuckee);
		}
	    when POOL:
			if (!ishero && rnd(100) < 10) {
				if (seeit)
					msg("The %s drowns !!", stuckee);
				goto goner;
			}
			if ((trp->tr_flags & ISGONE) && rnd(100) < 10) {
				nlmove = TRUE;
				if (rnd(100) < 15)
					teleport(rndspot, &player);	   /* teleport away */
				else if(rnd(100) < 15 && level > 2) {
					level -= rnd(2) + 1;
					new_level(NORMLEV);
					msg("You here a faint groan from below.");
				}
				else if(rnd(100) < 40) {
					level += rnd(4);
					new_level(NORMLEV);
					msg("You find yourself in strange surroundings.");
				}
				else if(rnd(100) < 6 && pl_off(ISINVINC)) {
					msg("Oh no!!! You drown in the pool!!! --More--");
					wait_for(cw, ' ');
					death(K_POOL);
				}
				else
					 nlmove = FALSE;
		}
	}
	flushinp();		/* flush typeahead */
	return ch;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r12
movl (%rdi), %esi
movl 0x4(%rdi), %ebp
movl %ebp, %edi
callq 0xea05
testq %rax, %rax
je 0xdc45
movq %rax, %r15
cmpq 0x1c34b(%rip), %rbx     # 0x29f60
je 0xdc4c
movslq 0x80(%rbx), %rax
imulq $0x70, %rax, %rax
leaq 0x1c787(%rip), %rcx     # 0x2a3b0
movq (%rcx,%rax), %rdx
leaq 0x11506(%rip), %rsi     # 0x1f13a
movq %rsp, %rdi
xorl %eax, %eax
callq 0x64d0
movl 0x4(%r12), %ebp
jmp 0xdc67
xorl %ebp, %ebp
jmp 0xe1cd
movl $0x756f59, (%rsp)       # imm = 0x756F59
leaq 0x1fc32(%rip), %rax     # 0x2d88c
movb $0x0, (%rax)
leaq 0x1fc10(%rip), %rax     # 0x2d874
andl $0x0, (%rax)
movl (%r12), %esi
movl %ebp, %edi
callq 0x6ec2
movl %eax, %r14d
testb %al, %al
je 0xdca5
leaq 0x22d50(%rip), %r13     # 0x309d0
movq (%r13), %rdi
movl (%r12), %edx
movl 0x4(%r12), %esi
callq 0x6470
cmpl $-0x1, %eax
je 0xdca5
movq (%r13), %rdi
movsbl 0x14(%r15), %esi
callq 0x64a0
movl 0x10(%r15), %eax
orl $0x8, %eax
movl %eax, 0x10(%r15)
movzbl 0x14(%r15), %ebp
cmpl $0x22, %ebp
je 0xddcd
cmpl $0x24, %ebp
je 0xe015
cmpl $0x3e, %ebp
je 0xdfcd
cmpl $0x5c, %ebp
je 0xdd28
cmpl $0x7e, %ebp
je 0xddaf
cmpl $0x60, %ebp
je 0xdeec
cmpl $0x7b, %ebp
je 0xde0f
cmpl $0x7d, %ebp
je 0xdd69
cmpl $0x5e, %ebp
jne 0xe1c8
movb $0x2, %bpl
cmpq 0x1c258(%rip), %rbx     # 0x29f60
jne 0xdfec
leaq 0x1fb74(%rip), %rax     # 0x2d889
movb $0x1, (%rax)
pushq $0x1
popq %rdi
callq 0xeb48
movb $0x5e, %bpl
jmp 0xe1c8
movb $0x2, %bpl
cmpq 0x1c22e(%rip), %rbx     # 0x29f60
jne 0xdfec
leaq 0x1fb4a(%rip), %rax     # 0x2d889
movb $0x1, (%rax)
leaq 0x1c597(%rip), %rax     # 0x2a2e0
incl (%rax)
pushq $0x2
popq %rdi
callq 0xeb48
leaq 0x113e7(%rip), %rdi     # 0x1f141
xorl %eax, %eax
callq 0xb178
movb $0x5c, %bpl
jmp 0xe1c8
addl $0x3, 0x84(%rbx)
movb $0x7d, %bpl
testb %r14b, %r14b
je 0xe1c8
cmpq 0x1c1dd(%rip), %rbx     # 0x29f60
leaq 0x113f3(%rip), %rax     # 0x1f17d
leaq 0x113f1(%rip), %rsi     # 0x1f182
cmoveq %rax, %rsi
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x64b0
leaq 0x113df(%rip), %rdi     # 0x1f186
movq %rbx, %rsi
jmp 0xe009
leaq 0x1fad3(%rip), %rax     # 0x2d889
movb $0x1, (%rax)
movq 0x8(%r15), %rdi
movq %rbx, %rsi
callq 0x1b91f
movb $0x7e, %bpl
jmp 0xe1c8
cmpq 0x1c18c(%rip), %rbx     # 0x29f60
je 0xe0ce
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
cmpl $0xa, %eax
jge 0xe0ca
testb %r14b, %r14b
je 0xdfbb
leaq 0x11454(%rip), %rdi     # 0x1f251
movq %rsp, %rsi
xorl %eax, %eax
callq 0xb178
movb $0x2, %bpl
jmp 0xdfec
leaq 0x1fe3a(%rip), %r15     # 0x2dc50
callq 0x6580
leaq 0x1fa26(%rip), %rcx     # 0x2d848
movq (%rcx), %rcx
leaq 0x34(%rcx), %rdx
leaq 0x2c(%rbx), %rsi
testq %rcx, %rcx
cmoveq %rsi, %rdx
cmpq %r15, %rbx
movq (%rax), %rax
movsbq (%rsp), %rcx
movb (%rax,%rcx,4), %al
movb %al, (%rsp)
cmovneq %rsi, %rdx
movl (%rdx), %r12d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x11364
movl %eax, %ebp
addl %r12d, %ebp
cmpq %r15, %rbx
jne 0xde70
pushq $0x8
popq %rdi
callq 0x932c
testb %al, %al
pushq $-0x64
popq %rax
cmovnel %eax, %ebp
leaq 0x1c469(%rip), %rax     # 0x2a2e0
movl (%rax), %eax
pushq $0x4
popq %rcx
cltd
idivl %ecx
leal 0x3(%rax), %edi
pushq $0x1
popq %rdx
movl %ebp, %esi
callq 0xa9d4
testl %eax, %eax
je 0xe02e
testb %r14b, %r14b
je 0xdec3
cmpq 0x1c0c0(%rip), %rbx     # 0x29f60
leaq 0x11353(%rip), %rax     # 0x1f1fa
leaq 0x13adb(%rip), %rsi     # 0x21989
cmoveq %rax, %rsi
leaq 0x1132d(%rip), %rdi     # 0x1f1e6
movq %rsp, %rdx
xorl %eax, %eax
callq 0xb178
pushq $0x1
popq %rdi
pushq $0x6
popq %rsi
callq 0xc025
cmpq 0x1c08b(%rip), %rbx     # 0x29f60
je 0xe124
subl %eax, 0x30(%rbx)
movb $0x7b, %bpl
jg 0xe1c8
jmp 0xdfbb
leaq 0x1fd5d(%rip), %r15     # 0x2dc50
callq 0x6580
leaq 0x1f949(%rip), %rcx     # 0x2d848
movq (%rcx), %rcx
leaq 0x34(%rcx), %rdx
leaq 0x2c(%rbx), %rsi
testq %rcx, %rcx
cmoveq %rsi, %rdx
cmpq %r15, %rbx
movq (%rax), %rax
movsbq (%rsp), %rcx
movb (%rax,%rcx,4), %al
movb %al, (%rsp)
cmovneq %rsi, %rdx
movl (%rdx), %r12d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x11364
movl %eax, %ebp
addl %r12d, %ebp
cmpq %r15, %rbx
jne 0xdf4d
pushq $0x8
popq %rdi
callq 0x932c
testb %al, %al
pushq $-0x64
popq %rax
cmovnel %eax, %ebp
leaq 0x1c38c(%rip), %rax     # 0x2a2e0
movl (%rax), %eax
pushq $0x4
popq %rcx
cltd
idivl %ecx
leal 0x3(%rax), %edi
movl %ebp, %esi
xorl %edx, %edx
callq 0xa9d4
testl %eax, %eax
je 0xe08c
testb %r14b, %r14b
je 0xdf86
leaq 0x1129f(%rip), %rdi     # 0x1f21b
movq %rsp, %rsi
xorl %eax, %eax
callq 0xb178
xorl %edi, %edi
cmpq 0x1bfd1(%rip), %rbx     # 0x29f60
je 0xe13a
movq %rbx, %rsi
callq 0xaab7
testl %eax, %eax
jne 0xdfa4
decl 0x10(%rbx)
pushq $0x1
popq %rdi
pushq $0x4
popq %rsi
callq 0xc025
subl %eax, 0x30(%rbx)
movb $0x60, %bpl
jg 0xe1c8
leaq 0x1f8c7(%rip), %rax     # 0x2d889
movb $0x1, (%rax)
movb $0x2, %bpl
jmp 0xe1c8
movb $0x2, %bpl
cmpq 0x1bf89(%rip), %rbx     # 0x29f60
jne 0xdfec
leaq 0x1c300(%rip), %rax     # 0x2a2e0
incl (%rax)
xorl %edi, %edi
callq 0xeb48
movb $0x3e, %bpl
leaq 0x1f896(%rip), %rax     # 0x2d889
movb $0x1, (%rax)
testb %r14b, %r14b
je 0xe1c8
leaq 0x11162(%rip), %rdi     # 0x1f168
movq %rsp, %rsi
xorl %eax, %eax
callq 0xb178
jmp 0xe1c8
cmpq 0x1bf44(%rip), %rbx     # 0x29f60
je 0xe0a4
addl $0x5, 0x84(%rbx)
jmp 0xe196
testb %r14b, %r14b
je 0xe044
leaq 0x111c8(%rip), %rdi     # 0x1f202
movq %rsp, %rsi
xorl %eax, %eax
callq 0xb178
pushq $0x29
popq %rsi
pushq $0x3
popq %rdx
xorl %edi, %edi
callq 0x19c8f
movq %rax, %r14
movq 0x10(%rax), %r15
movl $0x3, 0x2c(%r15)
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0xc004
movl %eax, 0x30(%r15)
movl $0x1, 0x24(%r15)
movq 0x50(%rbx), %rax
movq %rax, (%r15)
movq %r14, %rdi
xorl %esi, %esi
callq 0x1ae63
jmp 0xe132
movb $0x60, %bpl
testb %r14b, %r14b
je 0xe1c8
leaq 0x11196(%rip), %rdi     # 0x1f235
jmp 0xe006
pushq $0x8
popq %rdi
callq 0x932c
testb %al, %al
je 0xe188
leaq 0x110e5(%rip), %rdi     # 0x1f1a0
xorl %eax, %eax
callq 0xb178
movb $0x24, %bpl
jmp 0xe1c8
movl 0x10(%r15), %eax
movb $0x22, %bpl
testb $0x2, %al
je 0xe1c8
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
cmpl $0x9, %eax
jg 0xe1c8
leaq 0x1f796(%rip), %rbx     # 0x2d889
movb $0x1, (%rbx)
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
cmpl $0xe, %eax
jg 0xe1de
leaq 0x1c290(%rip), %rax     # 0x2a3a0
movq (%rax), %rdi
leaq 0x1fb36(%rip), %rsi     # 0x2dc50
callq 0x1b91f
jmp 0xe1c8
negl %eax
pushq $-0x10
popq %rdx
movl %eax, %edi
xorl %esi, %esi
callq 0x11158
movb $0x7b, %bpl
jmp 0xe1c8
callq 0xa933
testl %eax, %eax
jne 0xe151
pushq $0x3
popq %rdi
pushq $-0x1
popq %rsi
pushq $0x1
popq %rdx
callq 0x111a5
pushq $0x2
popq %rdi
callq 0x11fa5
testb %al, %al
jne 0xe16a
pushq $-0x1
popq %rsi
pushq $0x1
popq %rdi
movl %edi, %edx
callq 0x111a5
pushq $0x1
popq %rdi
pushq $0x4
popq %rsi
callq 0xc025
negl %eax
pushq $-0xf
popq %rdx
movl %eax, %edi
xorl %esi, %esi
callq 0x11158
movb $0x60, %bpl
jmp 0xe1c8
leaq 0x1fac1(%rip), %rax     # 0x2dc50
addl $0x5, 0x88(%rax)
movb $0x24, %bpl
testb %r14b, %r14b
je 0xe1c8
cmpq 0x1bdbb(%rip), %rbx     # 0x29f60
leaq 0x137dd(%rip), %rax     # 0x21989
leaq 0xf436(%rip), %rdx      # 0x1d5e9
cmoveq %rax, %rdx
leaq 0x10ffe(%rip), %rdi     # 0x1f1bc
movq %rsp, %rsi
xorl %eax, %eax
callq 0xb178
callq 0x6070
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
leaq 0x1c0f1(%rip), %r14     # 0x2a2e0
cmpl $0xe, %eax
jg 0xe219
cmpl $0x3, (%r14)
jl 0xe219
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0xc004
notl %eax
addl %eax, (%r14)
xorl %edi, %edi
callq 0xeb48
leaq 0x1104b(%rip), %rdi     # 0x1f262
jmp 0xe243
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
cmpl $0x27, %eax
jg 0xe24f
pushq $0x4
popq %rdi
xorl %eax, %eax
callq 0xc004
addl %eax, (%r14)
xorl %edi, %edi
callq 0xeb48
leaq 0x11042(%rip), %rdi     # 0x1f285
xorl %eax, %eax
callq 0xb178
jmp 0xe1c8
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
cmpl $0x5, %eax
jg 0xe297
pushq $0x8
popq %rdi
callq 0x933b
testb %al, %al
je 0xe297
leaq 0x1103f(%rip), %rdi     # 0x1f2b0
xorl %eax, %eax
callq 0xb178
leaq 0x22751(%rip), %rax     # 0x309d0
movq (%rax), %rdi
pushq $0x20
popq %rsi
callq 0xb399
pushq $-0xd
popq %rdi
callq 0x11fd0
jmp 0xe1c8
movb $0x0, (%rbx)
jmp 0xe1c8