// File: /workspace/github_c_makefile_star2_O2/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 0x1e48d(%rip), %r13     # 0x2dc50
cmpq $0x0, 0x70(%r13)
pushq $0x23
popq %rax
pushq $0x2e
popq %rbp
cmovel %eax, %ebp
movq %rdi, %r14
testq %rdi, %rdi
je 0xf836
movq 0x10(%r14), %r15
movq %r15, %rdi
callq 0x948c
leaq 0x1e564(%rip), %rcx     # 0x2dd50
movq (%rcx), %rcx
addl 0x38(%rcx), %eax
cmpl 0x3c(%rcx), %eax
jle 0xf804
movq 0x18(%r15), %rsi
leaq 0xfd12(%rip), %rdi      # 0x1f514
jmp 0xf828
leaq 0x1e059(%rip), %rax     # 0x2d864
movl 0x44(%r15), %ecx
addl (%rax), %ecx
cmpl $0xe11, %ecx            # imm = 0xE11
jl 0xf8a5
movq 0x18(%r15), %rsi
leaq 0xfd05(%rip), %rdi      # 0x1f52d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xb178
jmp 0xfa4b
movl 0x50(%r13), %esi
movl 0x54(%r13), %edi
xorl %eax, %eax
callq 0xc996
testq %rax, %rax
je 0xf91e
movq %rax, %r14
movq 0x10(%rax), %rdi
cmpl $0x3f, 0x20(%rdi)
jne 0xf7d9
cmpl $0x7, 0x28(%rdi)
jne 0xf7d9
pushq $0x8
popq %rsi
callq 0x934a
testb %al, %al
je 0xf7d9
leaq 0xfc68(%rip), %rdi      # 0x1f4e8
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xb178
leaq 0x1dfa8(%rip), %rdi     # 0x2d838
movq %r14, %rsi
callq 0xb7f4
movq %r14, %rdi
callq 0xb857
jmp 0xf938
testq %r12, %r12
jne 0xf8e1
leaq 0x1df87(%rip), %rdi     # 0x2d838
movq %r14, %rsi
callq 0xb7f4
movq 0x1a678(%rip), %r12     # 0x29f38
movq (%r12), %rdi
movl 0x50(%r13), %edx
movl 0x54(%r13), %esi
callq 0x6470
cmpl $-0x1, %eax
je 0xf8e1
movq (%r12), %rdi
movl %ebp, %esi
callq 0x64a0
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x936c
movq 0x68(%r13), %rdx
movq %rdx, %r12
movq %rdx, %rax
testq %r12, %r12
je 0xf969
movq 0x10(%r12), %rcx
movl 0x20(%rcx), %esi
cmpl 0x20(%r15), %esi
je 0xf982
movq (%r12), %r12
testq %r12, %r12
je 0xf8fd
movq (%rax), %rax
jmp 0xf8fd
leaq 0x1df3b(%rip), %rax     # 0x2d860
andl $0x0, (%rax)
leaq 0xfb91(%rip), %rdi      # 0x1f4c0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xb178
movq 0x1a5f9(%rip), %r14     # 0x29f38
movq (%r14), %rdi
movl 0x50(%r13), %edx
movl 0x54(%r13), %esi
callq 0x6470
cmpl $-0x1, %eax
je 0xfa4b
movq (%r14), %rdi
movl %ebp, %esi
callq 0x64a0
xorl %ebx, %ebx
jmp 0xfa4b
testq %rdx, %rdx
je 0xf9ca
cmpl $0x3a, 0x20(%r15)
jne 0xf9f9
movq %rdx, (%r14)
movq %r14, 0x8(%rdx)
jmp 0xf9ca
testq %rdx, %rdx
je 0xf9ca
movl 0x20(%r15), %edx
movl 0x20(%rcx), %esi
testq %r12, %r12
je 0xf9f9
cmpl %edx, %esi
jne 0xf9e3
movl 0x3c(%rcx), %edi
cmpl 0x3c(%r15), %edi
jne 0xf9ae
movl 0x38(%rcx), %edi
cmpl 0x38(%r15), %edi
jne 0xf9b7
jmp 0xfa5c
movl 0x28(%rcx), %edi
cmpl 0x28(%r15), %edi
je 0xf9d5
movq (%r12), %r12
testq %r12, %r12
je 0xf98e
movq 0x10(%r12), %rcx
movq (%rax), %rax
jmp 0xf98b
movq %r14, 0x68(%r13)
andq $0x0, 0x8(%r14)
jmp 0xfa00
cmpl $0x3a, %esi
jne 0xf9e3
movq (%r12), %r12
testq %r12, %r12
je 0xf9f9
movq 0x8(%r12), %rax
movq %r12, (%r14)
movq %rax, 0x8(%r14)
movq %r14, 0x8(%r12)
movq %r14, (%rax)
jmp 0xfa00
movq %r14, (%rax)
movq %rax, 0x8(%r14)
movq 0x10(%r14), %r14
testb %bl, %bl
jne 0xfa31
movq %r14, %rdi
xorl %esi, %esi
callq 0x1908c
movq %rax, %rbx
movq %r14, %rdi
callq 0xfa6c
movsbl %al, %edx
leaq 0xfb26(%rip), %rdi      # 0x1f54d
movq %rbx, %rsi
xorl %eax, %eax
callq 0xb178
cmpl $0x2c, 0x20(%r14)
jne 0xfa42
leaq 0x1de52(%rip), %rax     # 0x2d891
movb $0x1, (%rax)
xorl %eax, %eax
callq 0x9378
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 0xb857
movq %r12, %r14
jmp 0xfa00