// File: /workspace/github_c_makefile_star2_O3/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 0x1d505(%rip), %rax     # 0x2dc60
movq 0x68(%rax), %rcx
testq %rcx, %rcx
je 0x10ac4
movl %esi, %ebp
movq %rdi, %r12
cmpl $0x29, %esi
movq %rdi, (%rsp)
je 0x108ef
testl %ebp, %ebp
jne 0x10788
cmpq $0x0, (%rcx)
jne 0x108ef
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 0xbd39
movq %r15, %rcx
testq %r15, %r15
jne 0x1078c
testl %ebx, %ebx
je 0x10afa
cmpl $0x1, %ebx
jne 0x108ef
leaq 0x10e15(%rip), %r15     # 0x215e9
movq 0x10(%r14), %r13
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xb620
xorl %eax, %eax
callq 0xb94c
cmpb $0x2a, %al
je 0x1081e
movl %eax, %r12d
movzbl %al, %eax
cmpl $0x1b, %eax
je 0x10b10
callq 0x65b0
movq %rax, %rbp
movq (%rax), %rax
movsbq %r12b, %rbx
testb $0x4, 0x1(%rax,%rbx,2)
jne 0x1085a
movq (%rsp), %r12
jmp 0x108ce
leaq 0x1d04b(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
leaq 0x1d42e(%rip), %rax     # 0x2dc60
movq 0x68(%rax), %rbx
testq %rbx, %rbx
je 0x1089b
movb $0x61, %al
cmpq %r13, 0x10(%rbx)
je 0x10855
movsbl %al, %edi
callq 0xbd39
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x1083d
movb $0x25, %al
movsbl %al, %ebp
jmp 0x108a0
leaq 0x1d3ff(%rip), %rax     # 0x2dc60
movq 0x68(%rax), %r15
movb $0x25, %al
testq %r15, %r15
je 0x10886
movb $0x61, %al
cmpq %r13, 0x10(%r15)
je 0x10886
movsbl %al, %edi
callq 0xbd39
movq (%r15), %r15
testq %r15, %r15
jne 0x1086e
movb $0x25, %al
cmpb %al, %r12b
movq (%rsp), %r12
leaq 0x10d55(%rip), %r15     # 0x215e9
je 0x108ce
jmp 0x10b2d
movl $0x25, %ebp
movq (%rsp), %r12
movq %r13, %rdi
xorl %esi, %esi
callq 0x1aa04
leaq 0xe7b6(%rip), %rdi      # 0x1f06b
movl %ebp, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0xb620
movl $0x2a, %ebx
callq 0x65b0
movq %rax, %rbp
movq (%rbp), %rax
testb $0x4, 0x1(%rax,%rbx,2)
je 0x107d4
leaq 0x1cf8c(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
jmp 0x10ae8
leaq 0x10d22(%rip), %r13     # 0x21618
leaq 0x200eb(%rip), %rbx     # 0x309e8
movq %r13, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xb620
xorl %eax, %eax
callq 0xb94c
movl %eax, %r15d
leaq 0x1cf55(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
cmpb $0x2a, %r15b
je 0x10939
movzbl %r15b, %eax
cmpl $0x1b, %eax
jne 0x10a5c
jmp 0x10acd
movq (%rbx), %rdi
callq 0x6120
leaq 0x1d318(%rip), %rax     # 0x2dc60
movq 0x68(%rax), %r13
testq %r13, %r13
je 0x109e4
movl $0x61, %r14d
xorl %r12d, %r12d
movq 0x10(%r13), %rdi
testl %ebp, %ebp
je 0x1096b
cmpl %ebp, 0x20(%rdi)
jne 0x109c3
movq (%rbx), %r15
xorl %esi, %esi
callq 0x1aa04
movq %r15, %rdi
leaq 0x10bff(%rip), %rsi     # 0x2157e
movl %r14d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x6510
movq 0x1961d(%rip), %rax     # 0x29fb0
movl (%rax), %eax
addl $-0x2, %eax
cmpl %eax, %r12d
jge 0x109a2
incl %r12d
jmp 0x109c3
cmpq $0x0, (%r13)
je 0x109db
movq (%rbx), %rdi
leaq 0x1997b(%rip), %rsi     # 0x2a32e
callq 0xbcbb
movq (%rbx), %rdi
callq 0x6120
xorl %r12d, %r12d
movq (%r13), %r13
movsbl %r14b, %edi
callq 0xbd39
movsbl %al, %r14d
testq %r13, %r13
jne 0x1095e
jmp 0x109e4
movsbl %r14b, %edi
callq 0xbd39
movq (%rbx), %rdi
movq 0x195c2(%rip), %rax     # 0x29fb0
movl (%rax), %esi
decl %esi
xorl %edx, %edx
callq 0x6490
movq (%rbx), %rdi
leaq 0x10c2d(%rip), %rsi     # 0x21630
movq (%rsp), %r12
movq %r12, %rdx
xorl %eax, %eax
callq 0x6510
movq (%rbx), %rdi
callq 0x6200
xorl %eax, %eax
callq 0xb94c
movl %eax, %r15d
callq 0x65b0
cmpb $0x1b, %r15b
je 0x10a40
movq (%rax), %rax
movsbq %r15b, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
je 0x10a19
leaq 0x1ff99(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0xbd09
cmpb $0x1b, %r15b
leaq 0x10bbe(%rip), %r13     # 0x21618
je 0x10acd
leaq 0x1d1fd(%rip), %rax     # 0x2dc60
movq 0x68(%rax), %r14
testq %r14, %r14
sete %al
cmpb $0x61, %r15b
sete %cl
orb %al, %cl
je 0x10a84
movl $0x61, %eax
testq %r14, %r14
je 0x10aa3
jmp 0x10ae8
movb $0x61, %al
movq (%r14), %r14
movsbl %al, %edi
callq 0xbd39
testq %r14, %r14
je 0x10a9b
cmpb %r15b, %al
jne 0x10a86
testq %r14, %r14
jne 0x10ae8
movsbl %al, %eax
leal -0x1(%rax), %esi
cmpl $0x41, %eax
movl $0x7a, %eax
cmovel %eax, %esi
leaq 0x10b82(%rip), %rdi     # 0x2163a
xorl %eax, %eax
callq 0xb620
jmp 0x108fd
leaq 0x10ad6(%rip), %rdi     # 0x215a1
jmp 0x10ade
leaq 0x19839(%rip), %rax     # 0x2a30d
movb $0x0, (%rax)
leaq 0x12eab(%rip), %rdi     # 0x23989
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xb620
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10ada(%rip), %rdi     # 0x215db
xorl %r14d, %r14d
movq %r12, %rsi
xorl %eax, %eax
callq 0xb620
jmp 0x10b21
leaq 0x12e72(%rip), %rdi     # 0x23989
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xb620
leaq 0x197e5(%rip), %rax     # 0x2a30d
movb $0x0, (%rax)
jmp 0x10ae8
leaq 0x1cd3c(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
leaq 0x10ac2(%rip), %rdi     # 0x21603
jmp 0x10b01