// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
leaq 0x22e35(%rip), %rax     # 0x370d0
cmpq $0x0, 0x70(%rax)
jne 0x142a8
movb $0x23, -0x3a(%rbp)
jmp 0x142ac
movb $0x2e, -0x3a(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x143ee
movb $0x1, -0x39(%rbp)
leaq 0x22e0e(%rip), %rax     # 0x370d0
movl 0x54(%rax), %edi
leaq 0x22e04(%rip), %rax     # 0x370d0
movl 0x50(%rax), %esi
movb $0x0, %al
callq 0xfcb0
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x14341
leaq 0x229f9(%rip), %rax     # 0x36ce0
movl $0x0, (%rax)
leaq 0x17740(%rip), %rdi     # 0x2ba34
movb $0x0, %al
callq 0xd8f0
movq 0x1ecbe(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
leaq 0x22dc4(%rip), %rax     # 0x370d0
movl 0x54(%rax), %esi
leaq 0x22dba(%rip), %rax     # 0x370d0
movl 0x50(%rax), %edx
callq 0x6490
cmpl $-0x1, %eax
jne 0x14325
jmp 0x14338
movq 0x1ec94(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movsbl -0x3a(%rbp), %esi
callq 0x64c0
movb $0x0, -0x1(%rbp)
jmp 0x14780
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x3f, 0x20(%rax)
jne 0x143ec
movq -0x30(%rbp), %rax
cmpl $0x7, 0x28(%rax)
jne 0x143ec
movq -0x30(%rbp), %rdi
movl $0x8, %esi
callq 0xaac0
testb $0x1, %al
jne 0x1437d
jmp 0x143ea
leaq 0x176d8(%rip), %rdi     # 0x2ba5c
movb $0x0, %al
callq 0xd8f0
movq -0x10(%rbp), %rsi
leaq 0x22922(%rip), %rdi     # 0x36cb8
callq 0xe360
movq -0x10(%rbp), %rdi
callq 0xe490
movq 0x1ec15(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
leaq 0x22d1b(%rip), %rax     # 0x370d0
movl 0x54(%rax), %esi
leaq 0x22d11(%rip), %rax     # 0x370d0
movl 0x50(%rax), %edx
callq 0x6490
cmpl $-0x1, %eax
jne 0x143ce
jmp 0x143e1
movq 0x1ebeb(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movsbl -0x3a(%rbp), %esi
callq 0x64c0
movb $0x0, -0x1(%rbp)
jmp 0x14780
jmp 0x143ec
jmp 0x143f2
movb $0x0, -0x39(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0xad50
leaq 0x22dc2(%rip), %rcx     # 0x371d0
movq (%rcx), %rcx
addl 0x38(%rcx), %eax
leaq 0x22db5(%rip), %rcx     # 0x371d0
movq (%rcx), %rcx
cmpl 0x3c(%rcx), %eax
jle 0x14442
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0x17656(%rip), %rdi     # 0x2ba88
movb $0x0, %al
callq 0xd8f0
movb $0x0, -0x1(%rbp)
jmp 0x14780
leaq 0x2289b(%rip), %rax     # 0x36ce4
movl (%rax), %eax
movq -0x30(%rbp), %rcx
addl 0x44(%rcx), %eax
cmpl $0xe10, %eax            # imm = 0xE10
jle 0x14478
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0x17639(%rip), %rdi     # 0x2baa1
movb $0x0, %al
callq 0xd8f0
movb $0x0, -0x1(%rbp)
jmp 0x14780
testb $0x1, -0x39(%rbp)
je 0x144cb
movq -0x10(%rbp), %rsi
leaq 0x2282f(%rip), %rdi     # 0x36cb8
callq 0xe360
movq 0x1eb2b(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
leaq 0x22c31(%rip), %rax     # 0x370d0
movl 0x54(%rax), %esi
leaq 0x22c27(%rip), %rax     # 0x370d0
movl 0x50(%rax), %edx
callq 0x6490
cmpl $-0x1, %eax
jne 0x144b8
jmp 0x144cb
movq 0x1eb01(%rip), %rax     # 0x32fc0
movq (%rax), %rdi
movsbl -0x3a(%rbp), %esi
callq 0x64c0
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rdi
movl $0x8, %esi
callq 0xab50
leaq 0x22bd9(%rip), %rax     # 0x370d0
movq 0x68(%rax), %rax
movq %rax, -0x28(%rbp)
leaq 0x22bca(%rip), %rax     # 0x370d0
movq 0x68(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x14557
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x14533
jmp 0x14557
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x14548
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x1454a
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x1450e
leaq 0x22b72(%rip), %rax     # 0x370d0
cmpq $0x0, 0x68(%rax)
jne 0x14585
movq -0x10(%rbp), %rcx
leaq 0x22b60(%rip), %rax     # 0x370d0
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x14720
cmpq $0x0, -0x20(%rbp)
jne 0x145f4
movq -0x30(%rbp), %rax
cmpl $0x3a, 0x20(%rax)
jne 0x145d8
leaq 0x22b33(%rip), %rax     # 0x370d0
movq 0x68(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
leaq 0x22b1d(%rip), %rax     # 0x370d0
movq 0x68(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rcx
leaq 0x22b0a(%rip), %rax     # 0x370d0
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x145ef
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x1471e
jmp 0x145f6
xorl %eax, %eax
cmpq $0x0, -0x20(%rbp)
movb %al, -0x49(%rbp)
je 0x14616
movq -0x38(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x20(%rcx), %eax
sete %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x14622
jmp 0x146be
movq -0x38(%rbp), %rax
movl 0x3c(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jne 0x14667
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jne 0x14665
movq -0x38(%rbp), %rax
movl 0x24(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rdi
callq 0xe490
movq -0x20(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x14722
jmp 0x14690
movq -0x38(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jne 0x1468e
movq -0x30(%rbp), %rax
cmpl $0x3a, 0x20(%rax)
jne 0x1468c
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x146be
jmp 0x14690
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x146b9
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x145f6
cmpq $0x0, -0x20(%rbp)
jne 0x146de
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x1471c
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
jmp 0x1471e
jmp 0x14720
jmp 0x14722
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
testb $0x1, -0x11(%rbp)
jne 0x14761
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x23060
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x14790
movq -0x58(%rbp), %rsi
movsbl %al, %edx
leaq 0x17367(%rip), %rdi     # 0x2bac1
movb $0x0, %al
callq 0xd8f0
movq -0x30(%rbp), %rax
cmpl $0x2c, 0x20(%rax)
jne 0x14775
leaq 0x2259f(%rip), %rax     # 0x36d11
movb $0x1, (%rax)
movb $0x0, %al
callq 0xaba0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)