// File: /workspace/github_c_makefile_star2_O1/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 0x1d9c1(%rip), %r13     # 0x2dc60
cmpq $0x0, 0x70(%r13)
movl $0x23, %eax
movl $0x2e, %ebp
cmovel %eax, %ebp
movq %rdi, %r14
testq %rdi, %rdi
je 0x10317
movq 0x10(%r14), %r15
movq %r15, %rdi
callq 0x9730
leaq 0x1da94(%rip), %rcx     # 0x2dd60
movq (%rcx), %rcx
addl 0x38(%rcx), %eax
cmpl 0x3c(%rcx), %eax
jle 0x102e4
movq 0x18(%r15), %rsi
leaq 0x111ba(%rip), %rdi     # 0x2149c
jmp 0x10308
leaq 0x1d589(%rip), %rax     # 0x2d874
movl 0x44(%r15), %ecx
addl (%rax), %ecx
cmpl $0xe11, %ecx            # imm = 0xE11
jl 0x10389
movq 0x18(%r15), %rsi
leaq 0x111ad(%rip), %rdi     # 0x214b5
xorl %r15d, %r15d
xorl %eax, %eax
callq 0xb6e0
jmp 0x1057f
movl 0x50(%r13), %esi
movl 0x54(%r13), %edi
xorl %eax, %eax
callq 0xd15e
testq %rax, %rax
je 0x103fb
movq %rax, %r14
movq 0x10(%rax), %rdi
cmpl $0x3f, 0x20(%rdi)
jne 0x102b9
cmpl $0x7, 0x28(%rdi)
jne 0x102b9
movl $0x8, %esi
callq 0x95b3
testb %al, %al
je 0x102b9
leaq 0x1110d(%rip), %rdi     # 0x21470
xorl %r15d, %r15d
xorl %eax, %eax
callq 0xb6e0
leaq 0x1d4d4(%rip), %rdi     # 0x2d848
movq %r14, %rsi
callq 0xbe00
movq %r14, %rdi
callq 0xbe93
jmp 0x10419
testq %r12, %r12
jne 0x103c5
leaq 0x1d4b3(%rip), %rdi     # 0x2d848
movq %r14, %rsi
callq 0xbe00
movq 0x19b8c(%rip), %r12     # 0x29f30
movq (%r12), %rdi
movl 0x50(%r13), %edx
movl 0x54(%r13), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x103c5
movq (%r12), %rdi
movl %ebp, %esi
callq 0x64c0
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movl $0x8, %esi
movq %r15, %rdi
callq 0x95d5
movq 0x68(%r13), %rdx
testq %rdx, %rdx
sete %sil
je 0x1044b
movl 0x20(%r15), %edi
movq 0x10(%rdx), %rcx
cmpl %edi, 0x20(%rcx)
jne 0x10453
movq %rdx, %r12
movq %rdx, %rax
jmp 0x10478
leaq 0x1d46e(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
leaq 0x11039(%rip), %rdi     # 0x21448
xorl %r15d, %r15d
xorl %eax, %eax
callq 0xb6e0
movq 0x19b10(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
movl 0x50(%r13), %edx
movl 0x54(%r13), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x1057f
movq (%rbx), %rdi
movl %ebp, %esi
callq 0x64c0
xorl %r15d, %r15d
jmp 0x1057f
movq %rdx, %r12
movq %rdx, %rax
jmp 0x10478
movq %rdx, %r12
movq %rdx, %rax
movq (%r12), %r12
testq %r12, %r12
je 0x10465
movq (%rax), %rax
testq %r12, %r12
sete %sil
je 0x10478
movq 0x10(%r12), %rcx
cmpl %edi, 0x20(%rcx)
jne 0x10459
leaq 0x68(%r13), %rdi
testq %rdx, %rdx
je 0x10497
testb %sil, %sil
je 0x104e8
cmpl $0x3a, 0x20(%r15)
movq %rax, %rcx
jne 0x1049c
movq %rdx, (%r14)
movq %r14, 0x8(%rdx)
xorl %ecx, %ecx
movq %rdi, %rax
movq %r14, (%rax)
movq %rcx, 0x8(%r14)
movq 0x10(%r14), %r14
testb %bl, %bl
jne 0x10564
movq %r14, %rdi
xorl %esi, %esi
callq 0x1aaa4
movq %rax, %rbx
movq 0x68(%r13), %r15
testq %r15, %r15
je 0x1054e
movb $0x61, %al
cmpq %r14, 0x10(%r15)
je 0x104e3
movsbl %al, %edi
callq 0xbdeb
movq (%r15), %r15
testq %r15, %r15
jne 0x104cb
movb $0x25, %al
movsbl %al, %edx
jmp 0x10553
testq %r12, %r12
je 0x10530
movl 0x20(%r15), %edx
cmpl %edx, 0x20(%rcx)
jne 0x10533
movl 0x3c(%rcx), %esi
cmpl 0x3c(%r15), %esi
jne 0x1050d
movl 0x38(%rcx), %esi
cmpl 0x38(%r15), %esi
jne 0x1051a
jmp 0x105c3
movl 0x28(%rcx), %esi
cmpl 0x28(%r15), %esi
je 0x105b1
movq (%r12), %r12
testq %r12, %r12
je 0x1052b
movq 0x10(%r12), %rcx
movq (%rax), %rax
testq %r12, %r12
jne 0x104f1
xorl %r12d, %r12d
testq %r12, %r12
je 0x10595
movq 0x8(%r12), %rax
movq %r12, (%r14)
movq %rax, 0x8(%r14)
movq %r14, 0x8(%r12)
movq %r14, (%rax)
jmp 0x1059c
movl $0x25, %edx
leaq 0x10f7b(%rip), %rdi     # 0x214d5
movq %rbx, %rsi
xorl %eax, %eax
callq 0xb6e0
cmpl $0x2c, 0x20(%r14)
jne 0x10575
leaq 0x1d32f(%rip), %rax     # 0x2d8a1
movb $0x1, (%rax)
xorl %eax, %eax
callq 0x95e0
movb $0x1, %r15b
andb $0x1, %r15b
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, (%rax)
movq %rax, 0x8(%r14)
xorl %eax, %eax
testl %eax, %eax
je 0x104a3
cmpl $0x7, %eax
je 0x104a3
jmp 0x1057f
cmpl $0x3a, %edx
jne 0x10533
movq (%r12), %r12
jmp 0x10533
incl 0x24(%rcx)
movq %r14, %rdi
callq 0xbe93
movl $0x7, %eax
movq %r12, %r14
jmp 0x1059e