// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movl %esi, %r15d
movl %edi, %r12d
pushq $0x50
popq %rdi
callq 0xb877
movq %rax, %rbx
movq 0x10(%rax), %r14
movq %r14, %rdi
callq 0x19ee1
pushq $0x2
popq %r13
cmpl $-0x1, %r15d
je 0x19cce
movsbl %r15b, %edi
callq 0xc2af
jmp 0x19cfa
leaq 0x13b9b(%rip), %rax     # 0x2d870
movl (%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, (%rax)
cmpl $0x4, %ecx
setge %al
xorb $0x1, %r12b
movl %r13d, %r15d
testb %r12b, %al
jne 0x19cfd
leaq 0x120cb(%rip), %rdi     # 0x2bdc0
callq 0x19f2a
movl %eax, %r15d
movslq %r15d, %r12
cmpl $-0x1, %ebp
jne 0x19d25
imulq $0x18, %r12, %rax
leaq 0x12c50(%rip), %rcx     # 0x2c960
movq 0x10(%rcx,%rax), %rdi
testq %rdi, %rdi
je 0x19d23
callq 0x19f2a
movl %eax, %ebp
jmp 0x19d25
xorl %ebp, %ebp
shlq $0x4, %r12
leaq 0x12090(%rip), %rax     # 0x2bdc0
movq (%rax,%r12), %rcx
movq %rcx, 0x18(%r14)
movl 0xc(%rax,%r12), %eax
movl %eax, 0x40(%r14)
cmpl $0x7, %r15d
ja 0x19d64
movl %r15d, %eax
leaq 0x773b(%rip), %rcx      # 0x2148c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x21, 0x20(%r14)
jmp 0x19d90
movl %ebp, 0x28(%r14)
movq %r14, %rdi
callq 0x17cbc
jmp 0x19ecf
movl %ebp, 0x28(%r14)
movq %r14, %rdi
xorl %esi, %esi
callq 0x11ea2
jmp 0x19ecf
movl $0x3f, 0x20(%r14)
movl %ebp, 0x28(%r14)
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
xorl %ecx, %ecx
cmpl $0xb, %eax
setl %cl
cmpl $0x4, %eax
cmovll %r13d, %ecx
addl %ecx, 0x24(%r14)
jmp 0x19dd0
movl $0x2c, 0x20(%r14)
movl $0x1f4, 0x2c(%r14)      # imm = 0x1F4
movl $0x38643038, 0x10(%r14) # imm = 0x38643038
movb $0x0, 0x14(%r14)
movq %r14, %rdi
callq 0x953d
movl %eax, 0x44(%r14)
jmp 0x19ecf
leaq 0x13a88(%rip), %rax     # 0x2d870
andl $0x0, (%rax)
movq %r14, %rdi
callq 0xcce8
jmp 0x19ecf
movl %ebp, 0x28(%r14)
movq %r14, %rdi
movl %ebp, %esi
callq 0x1b009
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
cmpl $0x9, %eax
jg 0x19e86
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x936c
pushq $0x3
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0xc004
notl %eax
addl %eax, 0x2c(%r14)
movl %ebp, %edi
xorl %eax, %eax
callq 0xc004
notl %eax
addl %eax, 0x30(%r14)
jmp 0x19ecf
movl %ebp, 0x28(%r14)
movq %r14, %rdi
movl %ebp, %esi
callq 0x67a9
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
cmpl $0x13, %eax
jg 0x19eba
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x936c
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0xc004
movl 0x34(%r14), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x34(%r14)
jmp 0x19ecf
cmpl $0xe, %eax
ja 0x19ecf
pushq $0x3
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0xc004
movl 0x2c(%r14), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x2c(%r14)
movl %ebp, %edi
xorl %eax, %eax
callq 0xc004
movl 0x30(%r14), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x30(%r14)
jmp 0x19ecf
cmpl $0x1d, %eax
ja 0x19ecf
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0xc004
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