// File: /workspace/github_c_makefile_star2_O3/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
leaq 0x1fa0a(%rip), %rax     # 0x2de68
movslq (%rax), %rcx
testq %rcx, %rcx
jle 0xe49d
movq %rsi, %rbx
movq %rdi, %r15
movl (%rdi), %eax
movl 0x4(%rdi), %edi
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x1bb40(%rip), %rcx     # 0x29fc0
leaq 0x1f8e9(%rip), %r12     # 0x2dd70
cmpl %edi, 0x4(%r12)
jne 0xe494
cmpl %eax, (%r12)
je 0xe4a4
addq $0x18, %r12
cmpq %rcx, %r12
jb 0xe487
xorl %ebp, %ebp
jmp 0xeac6
cmpq 0x1baad(%rip), %rbx     # 0x29f58
je 0xe4da
movslq 0x80(%rbx), %rax
imulq $0x70, %rax, %rax
leaq 0x1bf01(%rip), %rcx     # 0x2a3c0
movq (%rcx,%rax), %rdx
leaq 0x12c70(%rip), %rsi     # 0x2113a
movq %rsp, %rdi
xorl %eax, %eax
callq 0x64f0
movl 0x4(%r15), %edi
jmp 0xe4f8
movl $0x756f59, (%rsp)       # imm = 0x756F59
leaq 0x1f3b4(%rip), %rax     # 0x2d89c
movb $0x0, (%rax)
leaq 0x1f392(%rip), %rax     # 0x2d884
movl $0x0, (%rax)
movl (%r15), %esi
callq 0x6f96
movl %eax, %r14d
testb %al, %al
je 0xe532
leaq 0x224d2(%rip), %r13     # 0x309e0
movq (%r13), %rdi
movl (%r15), %edx
movl 0x4(%r15), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0xe532
movq (%r13), %rdi
movsbl 0x14(%r12), %esi
callq 0x64c0
movl 0x10(%r12), %ecx
orl $0x8, %ecx
movl %ecx, 0x10(%r12)
movb 0x14(%r12), %bpl
movzbl %bpl, %eax
cmpl $0x5d, %eax
jle 0xe590
cmpl $0x7a, %eax
jle 0xe615
cmpl $0x7b, %eax
je 0xe774
cmpl $0x7d, %eax
je 0xe89c
cmpl $0x7e, %eax
jne 0xeac1
leaq 0x1f321(%rip), %rax     # 0x2d899
movb $0x1, (%rax)
movq 0x8(%r12), %rdi
movq %rbx, %rsi
callq 0x1d502
movb $0x7e, %bpl
jmp 0xeac1
cmpl $0x3d, %eax
jg 0xe5c0
cmpl $0x22, %eax
je 0xe708
cmpl $0x24, %eax
jne 0xeac1
cmpq 0x1b9aa(%rip), %rbx     # 0x29f58
je 0xe8e9
addl $0x5, 0x84(%rbx)
jmp 0xea8f
cmpl $0x3e, %eax
je 0xe74c
cmpl $0x5c, %eax
jne 0xeac1
movb $0x2, %bpl
cmpq 0x1b97c(%rip), %rbx     # 0x29f58
jne 0xe87d
leaq 0x1f2b0(%rip), %rax     # 0x2d899
movb $0x1, (%rax)
leaq 0x1bcfd(%rip), %rax     # 0x2a2f0
incl (%rax)
movl $0x2, %edi
callq 0xf534
leaq 0x12b3b(%rip), %rdi     # 0x21141
xorl %eax, %eax
callq 0xb620
movb $0x5c, %bpl
jmp 0xeac1
cmpl $0x5e, %eax
je 0xe86d
cmpl $0x60, %eax
jne 0xeac1
leaq 0x1f632(%rip), %r15     # 0x2dc60
callq 0x65a0
leaq 0x1f21e(%rip), %rcx     # 0x2d858
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 0x11f6b
movl %eax, %ebp
addl %r12d, %ebp
cmpq %r15, %rbx
jne 0xe68c
movl $0x8, %edi
callq 0x9513
testb %al, %al
movl $0xffffff9c, %eax       # imm = 0xFFFFFF9C
cmovnel %eax, %ebp
leaq 0x1bc5d(%rip), %rax     # 0x2a2f0
movl (%rax), %eax
leal 0x3(%rax), %edi
testl %eax, %eax
cmovnsl %eax, %edi
sarl $0x2, %edi
addl $0x3, %edi
movl %ebp, %esi
xorl %edx, %edx
callq 0xae72
testl %eax, %eax
je 0xe911
testb %r14b, %r14b
je 0xe6ca
leaq 0x12b5b(%rip), %rdi     # 0x2121b
movq %rsp, %rsi
xorl %eax, %eax
callq 0xb620
xorl %edi, %edi
cmpq 0x1b885(%rip), %rbx     # 0x29f58
je 0xea09
movq %rbx, %rsi
callq 0xaf65
testl %eax, %eax
jne 0xe6e8
decl 0x10(%rbx)
movl $0x1, %edi
movl $0x4, %esi
callq 0xc695
subl %eax, 0x30(%rbx)
movb $0x60, %bpl
jg 0xeac1
jmp 0xe85b
cmpq 0x1b849(%rip), %rbx     # 0x29f58
je 0xe9ae
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0xa, %eax
jge 0xe9a9
testb %r14b, %r14b
je 0xe85b
leaq 0x12b17(%rip), %rdi     # 0x21251
movq %rsp, %rsi
xorl %eax, %eax
callq 0xb620
movb $0x2, %bpl
jmp 0xe87d
movb $0x2, %bpl
cmpq 0x1b802(%rip), %rbx     # 0x29f58
jne 0xe87d
leaq 0x1bb8d(%rip), %rax     # 0x2a2f0
incl (%rax)
xorl %edi, %edi
callq 0xf534
movb $0x3e, %bpl
jmp 0xe87d
leaq 0x1f4e5(%rip), %r15     # 0x2dc60
callq 0x65a0
leaq 0x1f0d1(%rip), %rcx     # 0x2d858
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 0x11f6b
movl %eax, %ebp
addl %r12d, %ebp
cmpq %r15, %rbx
jne 0xe7d9
movl $0x8, %edi
callq 0x9513
testb %al, %al
movl $0xffffff9c, %eax       # imm = 0xFFFFFF9C
cmovnel %eax, %ebp
leaq 0x1bb10(%rip), %rax     # 0x2a2f0
movl (%rax), %eax
leal 0x3(%rax), %edi
testl %eax, %eax
cmovnsl %eax, %edi
sarl $0x2, %edi
addl $0x3, %edi
movl %ebp, %esi
movl $0x1, %edx
callq 0xae72
testl %eax, %eax
je 0xe929
testb %r14b, %r14b
je 0xe833
cmpq 0x1b748(%rip), %rbx     # 0x29f58
leaq 0x129e3(%rip), %rax     # 0x211fa
leaq 0x1516b(%rip), %rsi     # 0x23989
cmoveq %rax, %rsi
leaq 0x129bd(%rip), %rdi     # 0x211e6
movq %rsp, %rdx
xorl %eax, %eax
callq 0xb620
movl $0x1, %edi
movl $0x6, %esi
callq 0xc695
cmpq 0x1b70f(%rip), %rbx     # 0x29f58
je 0xea6c
subl %eax, 0x30(%rbx)
movb $0x7b, %bpl
jg 0xeac1
leaq 0x1f037(%rip), %rax     # 0x2d899
movb $0x1, (%rax)
movb $0x2, %bpl
jmp 0xeac1
movb $0x2, %bpl
cmpq 0x1b6e1(%rip), %rbx     # 0x29f58
je 0xe98d
leaq 0x1f015(%rip), %rax     # 0x2d899
movb $0x1, (%rax)
testb %r14b, %r14b
je 0xeac1
leaq 0x128d1(%rip), %rdi     # 0x21168
movq %rsp, %rsi
jmp 0xe8dd
addl $0x3, 0x84(%rbx)
movb $0x7d, %bpl
testb %r14b, %r14b
je 0xeac1
cmpq 0x1b6a2(%rip), %rbx     # 0x29f58
leaq 0x128c0(%rip), %rax     # 0x2117d
leaq 0x128be(%rip), %rsi     # 0x21182
cmoveq %rax, %rsi
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x64d0
leaq 0x128ac(%rip), %rdi     # 0x21186
movq %rbx, %rsi
xorl %eax, %eax
callq 0xb620
jmp 0xeac1
movl $0x8, %edi
callq 0x9513
testb %al, %al
je 0xea81
leaq 0x1289e(%rip), %rdi     # 0x211a0
xorl %eax, %eax
callq 0xb620
movb $0x24, %bpl
jmp 0xeac1
movb $0x60, %bpl
testb %r14b, %r14b
je 0xeac1
leaq 0x12911(%rip), %rdi     # 0x21235
jmp 0xe897
testb %r14b, %r14b
je 0xe93f
leaq 0x128cd(%rip), %rdi     # 0x21202
movq %rsp, %rsi
xorl %eax, %eax
callq 0xb620
xorl %edi, %edi
movl $0x29, %esi
movl $0x3, %edx
callq 0x1b640
movq %rax, %r14
movq 0x10(%rax), %r15
movl $0x3, 0x2c(%r15)
movl $0x2, %edi
xorl %eax, %eax
callq 0xc674
movl %eax, 0x30(%r15)
movl $0x1, 0x24(%r15)
movq 0x50(%rbx), %rax
movq %rax, (%r15)
movq %r14, %rdi
xorl %esi, %esi
callq 0x1c9f8
jmp 0xea7c
leaq 0x1ef05(%rip), %rax     # 0x2d899
movb $0x1, (%rax)
movl $0x1, %edi
callq 0xf534
movb $0x5e, %bpl
jmp 0xeac1
movl 0x10(%r12), %ecx
movb $0x22, %bpl
testb $0x2, %cl
je 0xeac1
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x9, %eax
jg 0xeac1
leaq 0x1eec3(%rip), %rbx     # 0x2d899
movb $0x1, (%rbx)
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0xe, %eax
jg 0xead7
leaq 0x1b9bb(%rip), %rax     # 0x2a3b0
movq (%rax), %rdi
leaq 0x1f261(%rip), %rsi     # 0x2dc60
callq 0x1d502
jmp 0xeac1
callq 0xad9d
testl %eax, %eax
jne 0xea26
movl $0x3, %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x11d8e
movl $0x2, %edi
callq 0x12c34
testb %al, %al
jne 0xea48
movl $0x1, %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x11d8e
movl $0x1, %edi
movl $0x4, %esi
callq 0xc695
negl %eax
movl %eax, %edi
xorl %esi, %esi
movl $0xfffffff1, %edx       # imm = 0xFFFFFFF1
callq 0x11d3c
movb $0x60, %bpl
jmp 0xeac1
negl %eax
movl %eax, %edi
xorl %esi, %esi
movl $0xfffffff0, %edx       # imm = 0xFFFFFFF0
callq 0x11d3c
movb $0x7b, %bpl
jmp 0xeac1
leaq 0x1f1d8(%rip), %rax     # 0x2dc60
addl $0x5, 0x88(%rax)
movb $0x24, %bpl
testb %r14b, %r14b
je 0xeac1
cmpq 0x1b4ba(%rip), %rbx     # 0x29f58
leaq 0x14ee4(%rip), %rax     # 0x23989
leaq 0x10b3d(%rip), %rdx     # 0x1f5e9
cmoveq %rax, %rdx
leaq 0x12705(%rip), %rdi     # 0x211bc
movq %rsp, %rsi
xorl %eax, %eax
callq 0xb620
callq 0x6070
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
leaq 0x1b806(%rip), %r14     # 0x2a2f0
cmpl $0xe, %eax
jg 0xeb16
cmpl $0x3, (%r14)
jl 0xeb16
movl $0x2, %edi
xorl %eax, %eax
callq 0xc674
notl %eax
addl %eax, (%r14)
xorl %edi, %edi
callq 0xf534
leaq 0x1274e(%rip), %rdi     # 0x21262
jmp 0xeb44
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x27, %eax
jg 0xeb50
movl $0x4, %edi
xorl %eax, %eax
callq 0xc674
addl %eax, (%r14)
xorl %edi, %edi
callq 0xf534
leaq 0x12741(%rip), %rdi     # 0x21285
xorl %eax, %eax
callq 0xb620
jmp 0xeac1
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x5, %eax
jg 0xeba0
movl $0x8, %edi
callq 0x9522
testb %al, %al
je 0xeba0
leaq 0x1273a(%rip), %rdi     # 0x212b0
xorl %eax, %eax
callq 0xb620
leaq 0x21e5c(%rip), %rax     # 0x309e0
movq (%rax), %rdi
movl $0x20, %esi
callq 0xb89e
movl $0xfffffff3, %edi       # imm = 0xFFFFFFF3
callq 0x12c60
jmp 0xeac1
movb $0x0, (%rbx)
jmp 0xeac1