// File: /workspace/github_c_makefile_star2_O2/ajpaulson[P]srogue11/pack.c
// Function: get_item
struct linked_list *get_item(char *purpose,int type)
{
	struct linked_list *obj, *pit, *savepit;
	struct object *pob;
	int ch, och, anr, cnt;

	if (pack == NULL) {
		msg("You aren't carrying anything.");
		return NULL;
	}
	if (type != WEAPON && (type != 0 || next(pack) == NULL)) {
		/*
		 * see if we have any of the type requested
		 */
		pit = pack;
		anr = 0;
		for (ch = 'a'; pit != NULL; pit = next(pit), ch = npch(ch)) {
			pob = OBJPTR(pit);
			if (type == pob->o_type || type == 0) {
				++anr;
				savepit = pit;	/* save in case of only 1 */
			}
		}
		if (anr == 0) {
			msg("Nothing to %s",purpose);
			after = FALSE;
			return NULL;
		}
		else if (anr == 1) {	/* only found one of 'em */
			do {
				struct object *opb;

				opb = OBJPTR(savepit);
				msg("%s what (* for the item)?",purpose);
				och = readchar();
				if (och == '*') {
					mpos = 0;
					msg("%c) %s",pack_char(opb),inv_name(opb,FALSE));
					continue;
				}
				if (och == ESCAPE) {
					msg("");
					after = FALSE;
					return NULL;
				}
				if (isalpha(och) && och != pack_char(opb)) {
					mpos = 0;
					msg("You can't %s that !!", purpose);
					after = FALSE;
					return NULL;
				}
			} while(!isalpha(och));
			mpos = 0;
			return savepit;		/* return this item */
		}
	}
	for (;;) {
		msg("%s what? (* for list): ",purpose);
		ch = readchar();
		mpos = 0;
		if (ch == ESCAPE) {		/* abort if escape hit */
			after = FALSE;
			msg("");			/* clear display */
			return NULL;
		}
		if (ch == '*') {
			wclear(hw);
			pit = pack;		/* point to pack */
			cnt = 0;
			for (ch='a'; pit != NULL; pit=next(pit), ch=npch(ch)) {
				pob = OBJPTR(pit);
				if (type == 0 || type == pob->o_type) {
					wprintw(hw,"%c) %s\n\r",ch,inv_name(pob,FALSE));
					if (++cnt > LINES - 2 && next(pit) != NULL) {
						cnt = 0;
						dbotline(hw, morestr);
						wclear(hw);
					}
				}
			}
			wmove(hw, LINES - 1,0);
			wprintw(hw,"%s what? ",purpose);
			draw(hw);		/* write screen */
			anr = FALSE;
			do {
				ch = readchar();
				if (isalpha(ch) || ch == ESCAPE)
					anr = TRUE; 
			} while(!anr);		/* do till we got it right */
			restscr(cw);		/* redraw orig screen */
			if (ch == ESCAPE) {
				after = FALSE;
				msg("");		/* clear top line */
				return NULL;	/* all done if abort */
			}
			/* ch has item to get from pack */
		}
		for (obj=pack,och='a';obj!=NULL;obj=next(obj),och=npch(och))
			if (ch == och)
				break;
		if (obj == NULL) {
			if (och == 'A')
				och = 'z';
			else
				och -= 1;
			msg("Please specify a letter between 'a' and '%c'",och);
			continue;
		}
		else 
			return obj;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x1df36(%rip), %r13     # 0x2dc50
movq 0x68(%r13), %rcx
testq %rcx, %rcx
je 0xfd79
movl %esi, %ebp
movq %rdi, %r12
cmpl $0x29, %esi
movq %rdi, (%rsp)
je 0xfe4f
testl %ebp, %ebp
jne 0xfd43
cmpq $0x0, (%rcx)
jne 0xfe4f
xorl %ebx, %ebx
movb $0x61, %al
testq %rcx, %rcx
je 0xfd85
testl %ebp, %ebp
sete %dl
movq (%rcx), %r15
movq 0x10(%rcx), %rsi
cmpl %ebp, 0x20(%rsi)
sete %sil
orb %dl, %sil
cmovneq %rcx, %r14
movzbl %sil, %ecx
addl %ecx, %ebx
movsbl %al, %edi
callq 0xb7e0
movq %r15, %rcx
jmp 0xfd47
leaq 0xf821(%rip), %rdi      # 0x1f5a1
jmp 0x10004
testl %ebx, %ebx
je 0x10020
cmpl $0x1, %ebx
jne 0xfe4f
leaq 0xf84c(%rip), %r15      # 0x1f5e9
movq 0x10(%r14), %r13
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xb178
xorl %eax, %eax
callq 0xb447
cmpb $0x2a, %al
je 0xfdf0
movl %eax, %r12d
movzbl %al, %eax
cmpl $0x1b, %eax
je 0x10036
callq 0x6590
movq %rax, %rbp
movq (%rax), %rax
movsbq %r12b, %rbx
testb $0x4, 0x1(%rax,%rbx,2)
je 0xfe2d
movq %r13, %rdi
callq 0xfa6c
cmpb %al, %r12b
je 0xfe2d
jmp 0x10053
leaq 0x1da69(%rip), %rax     # 0x2d860
andl $0x0, (%rax)
movq %r13, %rdi
callq 0xfa6c
movsbl %al, %ebp
movq %r13, %rdi
xorl %esi, %esi
callq 0x1908c
leaq 0xd255(%rip), %rdi      # 0x1d06b
movl %ebp, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0xb178
callq 0x6590
movq %rax, %rbp
pushq $0x2a
popq %rbx
movq (%rbp), %rax
testb $0x4, 0x1(%rax,%rbx,2)
movq (%rsp), %r12
je 0xfd9d
leaq 0x1da19(%rip), %rax     # 0x2d860
andl $0x0, (%rax)
jmp 0x1000e
leaq 0x20b82(%rip), %rbx     # 0x309d8
leaq 0xf7bb(%rip), %rdi      # 0x1f618
movq %r12, %rsi
xorl %eax, %eax
callq 0xb178
xorl %eax, %eax
callq 0xb447
movl %eax, %r14d
leaq 0x1d9e8(%rip), %rax     # 0x2d860
andl $0x0, (%rax)
cmpb $0x2a, %r14b
je 0xfe93
movzbl %r14b, %eax
cmpl $0x1b, %eax
jne 0xffaa
jmp 0xfff3
movq (%rbx), %rdi
callq 0x6120
movq 0x68(%r13), %r13
xorl %r12d, %r12d
pushq $0x61
popq %r14
testq %r13, %r13
je 0xff32
movq 0x10(%r13), %rdi
testl %ebp, %ebp
je 0xfebc
cmpl %ebp, 0x20(%rdi)
jne 0xff16
movq (%rbx), %r15
xorl %esi, %esi
callq 0x1908c
movq %r15, %rdi
leaq 0xf6ae(%rip), %rsi      # 0x1f57e
movl %r14d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x64f0
leal 0x1(%r12), %r15d
movq 0x1a0d7(%rip), %rax     # 0x29fc0
movl (%rax), %eax
addl $-0x2, %eax
cmpl %eax, %r12d
jl 0xff19
cmpq $0x0, (%r13)
je 0xff19
movq (%rbx), %rdi
leaq 0x1a41a(%rip), %rsi     # 0x2a31e
callq 0xb76d
movq (%rbx), %rdi
callq 0x6120
xorl %r15d, %r15d
jmp 0xff19
movl %r12d, %r15d
movq (%r13), %r13
movsbl %r14b, %edi
callq 0xb7e0
movsbl %al, %r14d
movl %r15d, %r12d
jmp 0xfea6
movq (%rbx), %rdi
movq 0x1a084(%rip), %rax     # 0x29fc0
movl (%rax), %esi
decl %esi
xorl %edx, %edx
callq 0x6470
movq (%rbx), %rdi
leaq 0xf6df(%rip), %rsi      # 0x1f630
movq (%rsp), %r12
movq %r12, %rdx
xorl %eax, %eax
callq 0x64f0
movq (%rbx), %rdi
callq 0x6200
xorl %eax, %eax
callq 0xb447
movl %eax, %r14d
callq 0x6590
cmpb $0x1b, %r14b
je 0xff8e
movq (%rax), %rax
movsbq %r14b, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
je 0xff67
leaq 0x20a3b(%rip), %rax     # 0x309d0
movq (%rax), %rdi
callq 0xb7b6
cmpb $0x1b, %r14b
leaq 0x1dca8(%rip), %r13     # 0x2dc50
je 0xfff3
movsbl %r14b, %r15d
movq 0x68(%r13), %r14
pushq $0x61
popq %rax
testq %r14, %r14
je 0xffcf
cmpl %r15d, %eax
je 0xffcf
movq (%r14), %r14
movsbl %al, %edi
callq 0xb7e0
movsbl %al, %eax
jmp 0xffb5
testq %r14, %r14
jne 0x1000e
leal -0x1(%rax), %esi
cmpl $0x41, %eax
pushq $0x7a
popq %rax
cmovel %eax, %esi
leaq 0xf653(%rip), %rdi      # 0x1f63a
xorl %eax, %eax
callq 0xb178
jmp 0xfe56
leaq 0x1a303(%rip), %rax     # 0x2a2fd
movb $0x0, (%rax)
leaq 0x11985(%rip), %rdi     # 0x21989
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xb178
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf5b4(%rip), %rdi      # 0x1f5db
xorl %r14d, %r14d
movq %r12, %rsi
xorl %eax, %eax
callq 0xb178
jmp 0x10047
leaq 0x1194c(%rip), %rdi     # 0x21989
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xb178
leaq 0x1a2af(%rip), %rax     # 0x2a2fd
movb $0x0, (%rax)
jmp 0x1000e
leaq 0x1d806(%rip), %rax     # 0x2d860
andl $0x0, (%rax)
leaq 0xf59f(%rip), %rdi      # 0x1f603
xorl %r14d, %r14d
movq (%rsp), %rsi
jmp 0x1002d