// File: /workspace/github_c_makefile_star2_O3/ajpaulson[P]srogue11/pack.c
// Function: add_pack
bool add_pack(struct linked_list *item,bool silent)
{
	struct linked_list *ip, *lp;
	struct object *obj, *op;
	bool from_floor;
	char delchar;

	if (player.t_room == NULL)
		delchar = PASSAGE;
	else
		delchar = FLOOR;
	if (item == NULL) {
		from_floor = TRUE;
		if ((item = find_obj(hero.y, hero.x)) == NULL) {
			mpos = 0;
			msg("That object must have been an illusion.");
			mvaddch(hero.y, hero.x, delchar);
			return FALSE;
		}
		/*
		 * Check for scare monster scrolls
		 */
		obj = OBJPTR(item);
		if (obj->o_type == SCROLL && obj->o_which == S_SCARE) {
			if (o_on(obj,ISFOUND)) {
				msg("The scroll turns to dust as you pick it up.");
				detach(lvl_obj, item);
				discard(item);
				mvaddch(hero.y, hero.x, delchar);	
				return FALSE;
			}
		}
	}
	else
		from_floor = FALSE;
	obj = OBJPTR(item);
	/*
	 * See if this guy can carry any more weight
	 */
	if (itemweight(obj) + him->s_pack > him->s_carry) {
		msg("You can't carry that %s.", obj->o_typname);
		return FALSE;
	}
	/*
	 * Check if there is room
	 */
	if (packvol + obj->o_vol > V_PACK) {
		msg("That %s won't fit in your pack.", obj->o_typname);
		return FALSE;
	}
	if (from_floor) {
		detach(lvl_obj, item);
		mvaddch(hero.y, hero.x, delchar);
	}
	item->l_prev = NULL;
	item->l_next = NULL;
	setoflg(obj, ISFOUND);
	/*
	 * start looking thru pack to find the start of items
	 * with the same type.
	 */
	lp = pack;
	for (ip = pack; ip != NULL; ip = next(ip)) {
		op = OBJPTR(ip);
		/*
		 * If we find a matching type then quit.
		 */
		if (op->o_type == obj->o_type)
			break;
		if (next(ip) != NULL)
			lp = next(lp);		/* update "previous" entry */
	}
	/*
	 * If the pack was empty, just stick the item in it.
	 */
	if (pack == NULL) {
		pack = item;
		item->l_prev = NULL;
	}
	/*
	 * If we looked thru the pack, but could not find an
	 * item of the same type, then stick it at the end,
	 * unless it was food, then put it in front.
	 */
	else if (ip == NULL) {
		if (obj->o_type == FOOD) {	/* insert food at front */
			item->l_next = pack;
			pack->l_prev = item;
			pack = item;
			item->l_prev = NULL;
		}
		else {						/* insert other stuff at back */
			lp->l_next = item;
			item->l_prev = lp;
		}
	}
	/*
	 * Here, we found at least one item of the same type.
	 * Look thru these items to see if there is one of the
	 * same group. If so, increment the count and throw the
	 * new item away. If not, stick it at the end of the
	 * items with the same type. Also keep all similar
	 * objects near each other, like all identify scrolls, etc.
	 */
	else {
		struct linked_list **save;

		while (ip != NULL && op->o_type == obj->o_type) {
			if (op->o_group == obj->o_group) {
				if (op->o_flags == obj->o_flags) {
					op->o_count++;
					discard(item);
					item = ip;
					goto picked_up;
				}
				else {
					goto around;
				}
			}
			if (op->o_which == obj->o_which) {
				if (obj->o_type == FOOD)
					ip = next(ip);
				break;
			}
around:
			ip = next(ip);
			if (ip != NULL) {
				op = OBJPTR(ip);
				lp = next(lp);
			}
		}
		/*
		 * If inserting into last of group at end of pack,
		 * just tack on the end.
		 */
		if (ip == NULL) {
			lp->l_next = item;
			item->l_prev = lp;
		}
		/*
		 * Insert into the last of a group of objects
		 * not at the end of the pack.
		 */
		else {
			save = &((ip->l_prev)->l_next);
			item->l_next = ip;
			item->l_prev = ip->l_prev;
			ip->l_prev = item;
			*save = item;
		}
	}
picked_up:
	obj = OBJPTR(item);
	if (!silent)
		msg("%s (%c)",inv_name(obj,FALSE),pack_char(obj));
	if (obj->o_type == AMULET)
		amulet = TRUE;
	updpack();				/* new pack weight & volume */
	return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r12
leaq 0x1dac9(%rip), %r13     # 0x2dc60
cmpq $0x0, 0x70(%r13)
movl $0x23, %eax
movl $0x2e, %ebp
cmovel %eax, %ebp
movq %rdi, %r14
testq %rdi, %rdi
je 0x1020e
movq 0x10(%r14), %r15
movq %r15, %rdi
callq 0x96b8
leaq 0x1db9c(%rip), %rcx     # 0x2dd60
movq (%rcx), %rcx
addl 0x38(%rcx), %eax
cmpl 0x3c(%rcx), %eax
jle 0x101dc
movq 0x18(%r15), %rsi
leaq 0x1133a(%rip), %rdi     # 0x21514
jmp 0x10200
leaq 0x1d691(%rip), %rax     # 0x2d874
movl 0x44(%r15), %ecx
addl (%rax), %ecx
cmpl $0xe11, %ecx            # imm = 0xE11
jl 0x1027f
movq 0x18(%r15), %rsi
leaq 0x1132d(%rip), %rdi     # 0x2152d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xb620
jmp 0x10471
movl 0x50(%r13), %esi
movl 0x54(%r13), %edi
xorl %eax, %eax
callq 0xd104
testq %rax, %rax
je 0x102f5
movq %rax, %r14
movq 0x10(%rax), %rdi
cmpl $0x3f, 0x20(%rdi)
jne 0x101b1
cmpl $0x7, 0x28(%rdi)
jne 0x101b1
movl $0x8, %esi
callq 0x9531
testb %al, %al
je 0x101b1
leaq 0x1128e(%rip), %rdi     # 0x214e8
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xb620
leaq 0x1d5de(%rip), %rdi     # 0x2d848
movq %r14, %rsi
callq 0xbd4c
movq %r14, %rdi
callq 0xbdda
jmp 0x10312
testq %r12, %r12
jne 0x102bb
leaq 0x1d5bd(%rip), %rdi     # 0x2d848
movq %r14, %rsi
callq 0xbd4c
movq 0x19c96(%rip), %r12     # 0x29f30
movq (%r12), %rdi
movl 0x50(%r13), %edx
movl 0x54(%r13), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x102bb
movq (%r12), %rdi
movl %ebp, %esi
callq 0x64c0
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movl $0x8, %esi
movq %r15, %rdi
callq 0x9553
movq 0x68(%r13), %rdx
testq %rdx, %rdx
je 0x103cb
movl 0x20(%r15), %edi
movq 0x10(%rdx), %rcx
cmpl %edi, 0x20(%rcx)
sete %sil
jne 0x10343
movq %rdx, %rax
movq %rdx, %r12
jmp 0x10368
leaq 0x1d574(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
leaq 0x111b7(%rip), %rdi     # 0x214c0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xb620
movq 0x19c17(%rip), %r14     # 0x29f30
movq (%r14), %rdi
movl 0x50(%r13), %edx
movl 0x54(%r13), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x10471
movq (%r14), %rdi
movl %ebp, %esi
callq 0x64c0
xorl %ebx, %ebx
jmp 0x10471
movq %rdx, %r12
movq %rdx, %rax
movq (%r12), %r12
testq %r12, %r12
je 0x10365
movq (%rax), %rax
movq 0x10(%r12), %rcx
cmpl %edi, 0x20(%rcx)
sete %sil
jne 0x10349
jmp 0x10368
xorl %r12d, %r12d
testq %rdx, %rdx
je 0x103cb
testb $0x1, %sil
je 0x103bd
testq %r12, %r12
je 0x103fd
movl 0x20(%r15), %edx
cmpl %edx, 0x20(%rcx)
jne 0x103e7
movl 0x3c(%r15), %esi
cmpl %esi, 0x3c(%rcx)
jne 0x1039c
movl 0x38(%rcx), %edi
cmpl 0x38(%r15), %edi
jne 0x103a5
jmp 0x10482
movl 0x28(%rcx), %ecx
cmpl 0x28(%r15), %ecx
je 0x103d9
movq (%r12), %r12
testq %r12, %r12
je 0x103fd
movq 0x10(%r12), %rcx
movq (%rax), %rax
cmpl %edx, 0x20(%rcx)
je 0x10389
jmp 0x103e7
cmpl $0x3a, 0x20(%r15)
jne 0x103fd
movq %rdx, (%r14)
movq %r14, 0x8(%rdx)
movq %r14, 0x68(%r13)
movq $0x0, 0x8(%r14)
jmp 0x10404
cmpl $0x3a, %edx
jne 0x103e7
movq (%r12), %r12
testq %r12, %r12
je 0x103fd
movq 0x8(%r12), %rax
movq %r12, (%r14)
movq %rax, 0x8(%r14)
movq %r14, 0x8(%r12)
movq %r14, (%rax)
jmp 0x10404
movq %r14, (%rax)
movq %rax, 0x8(%r14)
movq 0x10(%r14), %r14
testb %bl, %bl
jne 0x10457
movq %r14, %rdi
xorl %esi, %esi
callq 0x1aa04
movq %rax, %rbx
movq 0x68(%r13), %r15
testq %r15, %r15
je 0x10441
movb $0x61, %al
cmpq %r14, 0x10(%r15)
je 0x1043c
movsbl %al, %edi
callq 0xbd39
movq (%r15), %r15
testq %r15, %r15
jne 0x10424
movb $0x25, %al
movsbl %al, %edx
jmp 0x10446
movl $0x25, %edx
leaq 0x11100(%rip), %rdi     # 0x2154d
movq %rbx, %rsi
xorl %eax, %eax
callq 0xb620
cmpl $0x2c, 0x20(%r14)
jne 0x10468
leaq 0x1d43c(%rip), %rax     # 0x2d8a1
movb $0x1, (%rax)
xorl %eax, %eax
callq 0x9560
movb $0x1, %bl
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl 0x24(%rcx)
movq %r14, %rdi
callq 0xbdda
movq %r12, %r14
jmp 0x10404