// File: /workspace/github_c_makefile_star2_O1/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 0x1d3cd(%rip), %rbx     # 0x2dc60
movq 0x68(%rbx), %rcx
testq %rcx, %rcx
je 0x10c64
movl %esi, %ebp
movq %rdi, %r12
cmpl $0x29, %esi
movq %rdi, (%rsp)
je 0x10a85
testl %ebp, %ebp
jne 0x108c0
cmpq $0x0, (%rcx)
jne 0x10a85
movb $0x61, %al
xorl %ebx, %ebx
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 0xbdeb
movq %r15, %rcx
testq %r15, %r15
jne 0x108c4
testl %ebx, %ebx
je 0x10c9a
cmpl $0x1, %ebx
leaq 0x1d35a(%rip), %rbx     # 0x2dc60
jne 0x10a85
leaq 0x10c5e(%rip), %r15     # 0x21571
movq 0x10(%r14), %rbp
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xb6e0
xorl %eax, %eax
callq 0xb9fd
movsbq %al, %r13
cmpb $0x1b, %al
je 0x1097b
movl %eax, %r12d
movzbl %al, %eax
cmpl $0x2a, %eax
jne 0x1099d
leaq 0x1cf2b(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
movq 0x68(%rbx), %rbx
testq %rbx, %rbx
je 0x10a1e
movb $0x61, %al
cmpq %rbp, 0x10(%rbx)
je 0x10972
movsbl %al, %edi
callq 0xbdeb
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x1095a
movb $0x25, %al
movsbl %al, %r12d
jmp 0x10a24
leaq 0x12f8f(%rip), %rdi     # 0x23911
xorl %eax, %eax
callq 0xb6e0
leaq 0x1997d(%rip), %rax     # 0x2a30d
movb $0x0, (%rax)
movl $0x1, %ebx
jmp 0x10a47
callq 0x65b0
movq (%rax), %rax
xorl %ebx, %ebx
testb $0x4, 0x1(%rax,%r13,2)
je 0x10a47
leaq 0x1d2a6(%rip), %rax     # 0x2dc60
movq 0x68(%rax), %r15
movb $0x25, %al
testq %r15, %r15
je 0x109df
movb $0x61, %al
cmpq %rbp, 0x10(%r15)
je 0x109df
movsbl %al, %edi
callq 0xbdeb
movq (%r15), %r15
testq %r15, %r15
jne 0x109c7
movb $0x25, %al
cmpb %al, %r12b
movq (%rsp), %r12
leaq 0x10b84(%rip), %r15     # 0x21571
je 0x10a4b
leaq 0x1ce7a(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
leaq 0x10b88(%rip), %rdi     # 0x2158b
movq %r12, %rsi
xorl %eax, %eax
callq 0xb6e0
leaq 0x198f9(%rip), %rax     # 0x2a30d
movb $0x0, (%rax)
movl $0x1, %ebx
jmp 0x10a4b
movl $0x25, %r12d
movq %rbp, %rdi
xorl %esi, %esi
callq 0x1aaa4
leaq 0xe636(%rip), %rdi      # 0x1f06b
movl %r12d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0xb6e0
movl $0x6, %ebx
movq (%rsp), %r12
cmpl $0x6, %ebx
je 0x10a58
testl %ebx, %ebx
jne 0x10cba
callq 0x65b0
movq (%rax), %rax
testb $0x4, 0x1(%rax,%r13,2)
leaq 0x1d1f3(%rip), %rbx     # 0x2dc60
je 0x10913
leaq 0x1cdf6(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
jmp 0x10c88
movl $0x1, %r13d
leaq 0x10b0e(%rip), %rdi     # 0x215a0
movq %r12, %rsi
xorl %eax, %eax
callq 0xb6e0
xorl %eax, %eax
callq 0xb9fd
movl %eax, %r15d
leaq 0x1cdc3(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
cmpb $0x2a, %r15b
je 0x10acb
movzbl %r15b, %eax
cmpl $0x1b, %eax
jne 0x10c08
jmp 0x10c6d
leaq 0x1ff16(%rip), %rax     # 0x309e8
movq (%rax), %rdi
callq 0x6120
movq 0x68(%rbx), %r12
testq %r12, %r12
je 0x10b83
movl $0x61, %r14d
xorl %ebx, %ebx
movq 0x10(%r12), %rdi
testl %ebp, %ebp
je 0x10afd
cmpl %ebp, 0x20(%rdi)
jne 0x10b63
leaq 0x1fee4(%rip), %rax     # 0x309e8
movq (%rax), %r15
xorl %esi, %esi
callq 0x1aaa4
movq %r15, %rdi
leaq 0x109ee(%rip), %rsi     # 0x21506
movl %r14d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x6510
leal 0x1(%rbx), %r15d
movq 0x19480(%rip), %rax     # 0x29fb0
movl (%rax), %eax
addl $-0x2, %eax
cmpl %eax, %ebx
jl 0x10b66
cmpq $0x0, (%r12)
je 0x10b66
leaq 0x1fea1(%rip), %rbx     # 0x309e8
movq (%rbx), %rdi
leaq 0x197dd(%rip), %rsi     # 0x2a32e
callq 0xbd6d
movq (%rbx), %rdi
callq 0x6120
xorl %r15d, %r15d
jmp 0x10b66
movl %ebx, %r15d
movq (%r12), %r12
movsbl %r14b, %edi
callq 0xbdeb
movsbl %al, %r14d
movl %r15d, %ebx
testq %r12, %r12
jne 0x10aef
leaq 0x1fe5e(%rip), %r14     # 0x309e8
movq (%r14), %rdi
movq 0x1941c(%rip), %rax     # 0x29fb0
movl (%rax), %esi
decl %esi
xorl %ebx, %ebx
xorl %edx, %edx
callq 0x6490
movq (%r14), %rdi
leaq 0x10a0d(%rip), %rsi     # 0x215b8
movq (%rsp), %r12
movq %r12, %rdx
xorl %eax, %eax
callq 0x6510
movq (%r14), %rdi
callq 0x6200
xorl %eax, %eax
callq 0xb9fd
movl %eax, %r15d
callq 0x65b0
movq (%rax), %rax
movsbq %r15b, %rcx
testb $0x4, 0x1(%rax,%rcx,2)
cmovnel %r13d, %ebx
cmpb $0x1b, %r15b
cmovel %r13d, %ebx
testl %ebx, %ebx
je 0x10bc1
leaq 0x1fded(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0xbdbb
cmpb $0x1b, %r15b
je 0x10c6d
leaq 0x1d058(%rip), %rbx     # 0x2dc60
movq 0x68(%rbx), %r14
testq %r14, %r14
sete %cl
cmpb $0x61, %r15b
sete %al
orb %cl, %al
movl $0x61, %eax
jne 0x10c3f
movb $0x61, %al
movq (%r14), %r14
movsbl %al, %edi
callq 0xbdeb
testq %r14, %r14
sete %cl
je 0x10c3c
cmpb %r15b, %al
jne 0x10c24
movsbl %al, %eax
testb %cl, %cl
je 0x10c88
leal -0x1(%rax), %esi
cmpl $0x41, %eax
movl $0x7a, %eax
cmovel %eax, %esi
leaq 0x1096a(%rip), %rdi     # 0x215c2
xorl %eax, %eax
callq 0xb6e0
jmp 0x10a8b
leaq 0x108be(%rip), %rdi     # 0x21529
jmp 0x10c7e
leaq 0x19699(%rip), %rax     # 0x2a30d
movb $0x0, (%rax)
leaq 0x12c93(%rip), %rdi     # 0x23911
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xb6e0
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x108c2(%rip), %rdi     # 0x21563
xorl %r14d, %r14d
movq %r12, %rsi
xorl %eax, %eax
callq 0xb6e0
leaq 0x19658(%rip), %rax     # 0x2a30d
movb $0x0, (%rax)
jmp 0x10c88
xorl %r14d, %r14d
jmp 0x10c88