// File: /workspace/github_c_makefile_star2_O3/ajpaulson[P]srogue11/things.c
// Function: new_thing
struct linked_list *new_thing(bool treas,int type,int which)
{
	struct linked_list *item;
	struct magic_item *mi;
	struct object *cur;
	int chance, whi;

	item = new_item(sizeof *cur);
	cur = OBJPTR(item);
	basic_init(cur);
	if (type == DONTCARE) {
		if (++no_food > 4 && !treas)
			whi = TYP_FOOD;
		else
			whi = pick_one(things);
	}
	else {
		whi = getindex(type);
	}
	mi = thnginfo[whi].mf_magic;
	if (which == DONTCARE) {
		which = 0;
		if (mi != NULL)
			which = pick_one(mi);
	}
	cur->o_typname = things[whi].mi_name;
	cur->o_weight = things[whi].mi_wght;
	switch (whi) {
		case TYP_AMULET:
			cur->o_type = AMULET;
			cur->o_hplus = 500;
			strcpy(cur->o_hurldmg,"80d8");	/* if thrown, WOW!!! */
			cur->o_vol = itemvol(cur);
		when TYP_POTION:
			cur->o_type = POTION;
			cur->o_which = which;
			cur->o_count += extras();
			cur->o_vol = itemvol(cur);
		when TYP_SCROLL:
			cur->o_type = SCROLL;
			cur->o_which = which;
			cur->o_count += extras();
			cur->o_vol = itemvol(cur);
		when TYP_FOOD:
			no_food = 0;
			initfood(cur);
		when TYP_WEAPON:
			cur->o_which = which;
			init_weapon(cur, which);
			if ((chance = rnd(100)) < 10) {
				setoflg(cur,ISCURSED);
				cur->o_hplus -= rnd(3)+1;
				cur->o_dplus -= rnd(3)+1;
			}
			else if (chance < 15) {
				cur->o_hplus += rnd(3)+1;
				cur->o_dplus += rnd(3)+1;
			}
		when TYP_ARMOR:
			cur->o_which = which;
			initarmor(cur, which);
			if ((chance = rnd(100)) < 20) {
				setoflg(cur,ISCURSED);
				cur->o_ac += rnd(3)+1;
			}
			else if (chance < 30)
				cur->o_ac -= rnd(3)+1;
		when TYP_RING:
			cur->o_which = which;
			init_ring(cur, FALSE);
		when TYP_STICK:
		default:
			cur->o_which = which;
			fix_stick(cur);
	}
	return item;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r15d
movl %esi, %r12d
movl %edi, %ebp
movl $0x50, %edi
callq 0xbdfa
movq %rax, %rbx
movq 0x10(%rax), %r14
movl $0xb, 0x34(%r14)
movl $0x1, 0x24(%r14)
movb $0x0, 0x48(%r14)
xorl %eax, %eax
movq %rax, 0x18(%r14)
leaq 0xec7e(%rip), %rcx      # 0x2a304
movl (%rcx), %edx
incl %edx
movl %edx, (%rcx)
movl %edx, 0x3c(%r14)
movq %rax, 0x40(%r14)
movl %eax, 0x30(%r14)
movl $0x306430, %ecx         # imm = 0x306430
movl %ecx, 0x8(%r14)
movl %ecx, 0x10(%r14)
movq %rax, 0x28(%r14)
movl %eax, 0x20(%r14)
movl %eax, 0x38(%r14)
cmpl $-0x1, %r12d
je 0x1b6c5
movsbl %r12b, %edi
callq 0xc9eb
movl %eax, %r12d
jmp 0x1b72c
leaq 0x121b4(%rip), %rax     # 0x2d880
movl (%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, (%rax)
cmpl $0x4, %ecx
setge %al
xorb $0x1, %bpl
movl $0x2, %r12d
testb %bpl, %al
jne 0x1b72c
movl $0x3e8, %edi            # imm = 0x3E8
xorl %eax, %eax
callq 0xc674
leaq 0x106d5(%rip), %r12     # 0x2bdd0
cmpq $0x0, (%r12)
je 0x1b721
leaq 0x106c7(%rip), %rcx     # 0x2bdd0
cmpl 0x8(%rcx), %eax
jl 0x1b71e
leaq 0x10(%rcx), %r12
cmpq $0x0, 0x10(%rcx)
movq %r12, %rcx
jne 0x1b709
jmp 0x1b721
movq %rcx, %r12
subq 0xe890(%rip), %r12      # 0x29fb8
shrq $0x4, %r12
movslq %r12d, %r13
cmpl $-0x1, %r15d
jne 0x1b78e
leaq (,%r13,2), %rax
addq %r13, %rax
leaq 0x11229(%rip), %rcx     # 0x2c970
movq 0x10(%rcx,%rax,8), %rbp
testq %rbp, %rbp
je 0x1b77f
movl $0x3e8, %edi            # imm = 0x3E8
xorl %eax, %eax
callq 0xc674
cmpq $0x0, (%rbp)
movq %rbp, %r15
je 0x1b787
movq %rbp, %rcx
cmpl 0x8(%rcx), %eax
jl 0x1b784
leaq 0x10(%rcx), %r15
cmpq $0x0, 0x10(%rcx)
movq %r15, %rcx
jne 0x1b76a
jmp 0x1b787
xorl %r15d, %r15d
jmp 0x1b78e
movq %rcx, %r15
subq %rbp, %r15
shrq $0x4, %r15
shlq $0x4, %r13
leaq 0x10637(%rip), %rax     # 0x2bdd0
movq (%rax,%r13), %rcx
movq %rcx, 0x18(%r14)
movl 0xc(%rax,%r13), %eax
movl %eax, 0x40(%r14)
cmpl $0x7, %r12d
ja 0x1b7cd
movl %r12d, %eax
leaq 0x7cd2(%rip), %rcx      # 0x2348c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x21, 0x20(%r14)
jmp 0x1b7f9
movl %r15d, 0x28(%r14)
movq %r14, %rdi
callq 0x19530
jmp 0x1b956
movl %r15d, 0x28(%r14)
movq %r14, %rdi
xorl %esi, %esi
callq 0x12b26
jmp 0x1b956
movl $0x3f, 0x20(%r14)
movl %r15d, 0x28(%r14)
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
xorl %ecx, %ecx
cmpl $0xb, %eax
setl %cl
cmpl $0x4, %eax
movl $0x2, %eax
cmovgel %ecx, %eax
addl %eax, 0x24(%r14)
jmp 0x1b840
leaq 0x10(%r14), %rax
movl $0x2c, 0x20(%r14)
movl $0x1f4, 0x2c(%r14)      # imm = 0x1F4
movb $0x0, 0x4(%rax)
movl $0x38643038, (%rax)     # imm = 0x38643038
movq %r14, %rdi
callq 0x978c
movl %eax, 0x44(%r14)
jmp 0x1b956
leaq 0x12028(%rip), %rax     # 0x2d880
movl $0x0, (%rax)
movq %r14, %rdi
callq 0xd485
jmp 0x1b956
movl %r15d, 0x28(%r14)
movq %r14, %rdi
movl %r15d, %esi
callq 0x1cbac
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x9, %eax
jg 0x1b908
movl $0x1, %esi
movq %r14, %rdi
callq 0x9553
movl $0x3, %edi
xorl %eax, %eax
callq 0xc674
notl %eax
addl %eax, 0x2c(%r14)
movl $0x3, %edi
xorl %eax, %eax
callq 0xc674
notl %eax
addl %eax, 0x30(%r14)
jmp 0x1b956
movl %r15d, 0x28(%r14)
movq %r14, %rdi
movl %r15d, %esi
callq 0x6832
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x13, %eax
jg 0x1b93f
movl $0x1, %esi
movq %r14, %rdi
callq 0x9553
movl $0x3, %edi
xorl %eax, %eax
callq 0xc674
movl 0x34(%r14), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x34(%r14)
jmp 0x1b956
cmpl $0xe, %eax
ja 0x1b956
movl $0x3, %edi
xorl %eax, %eax
callq 0xc674
movl 0x2c(%r14), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x2c(%r14)
movl $0x3, %edi
xorl %eax, %eax
callq 0xc674
movl 0x30(%r14), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x30(%r14)
jmp 0x1b956
cmpl $0x1d, %eax
ja 0x1b956
movl $0x3, %edi
xorl %eax, %eax
callq 0xc674
notl %eax
addl %eax, 0x34(%r14)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq