// File: /workspace/github_c_makefile_star2_O1/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 0xbeb3
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 0xeba9(%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 0x1b79a
movsbl %r12b, %edi
callq 0xcaa3
movl %eax, %r12d
jmp 0x1b801
leaq 0x120df(%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 0x1b801
movl $0x3e8, %edi            # imm = 0x3E8
xorl %eax, %eax
callq 0xc72d
leaq 0x10600(%rip), %r12     # 0x2bdd0
cmpq $0x0, (%r12)
je 0x1b7f6
leaq 0x105f2(%rip), %rcx     # 0x2bdd0
cmpl 0x8(%rcx), %eax
jl 0x1b7f3
leaq 0x10(%rcx), %r12
cmpq $0x0, 0x10(%rcx)
movq %r12, %rcx
jne 0x1b7de
jmp 0x1b7f6
movq %rcx, %r12
subq 0xe7bb(%rip), %r12      # 0x29fb8
shrq $0x4, %r12
movslq %r12d, %r13
cmpl $-0x1, %r15d
jne 0x1b863
leaq (,%r13,2), %rax
addq %r13, %rax
leaq 0x11154(%rip), %rcx     # 0x2c970
movq 0x10(%rcx,%rax,8), %rbp
testq %rbp, %rbp
je 0x1b854
movl $0x3e8, %edi            # imm = 0x3E8
xorl %eax, %eax
callq 0xc72d
cmpq $0x0, (%rbp)
movq %rbp, %r15
je 0x1b85c
movq %rbp, %rcx
cmpl 0x8(%rcx), %eax
jl 0x1b859
leaq 0x10(%rcx), %r15
cmpq $0x0, 0x10(%rcx)
movq %r15, %rcx
jne 0x1b83f
jmp 0x1b85c
xorl %r15d, %r15d
jmp 0x1b863
movq %rcx, %r15
subq %rbp, %r15
shrq $0x4, %r15
shlq $0x4, %r13
leaq 0x10562(%rip), %rax     # 0x2bdd0
movq (%rax,%r13), %rcx
movq %rcx, 0x18(%r14)
movl 0xc(%rax,%r13), %eax
movl %eax, 0x40(%r14)
cmpl $0x7, %r12d
ja 0x1b8a2
movl %r12d, %eax
leaq 0x7b85(%rip), %rcx      # 0x23414
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x21, 0x20(%r14)
jmp 0x1b8ce
movl %r15d, 0x28(%r14)
movq %r14, %rdi
callq 0x19698
jmp 0x1ba2b
movl %r15d, 0x28(%r14)
movq %r14, %rdi
xorl %esi, %esi
callq 0x12c8e
jmp 0x1ba2b
movl $0x3f, 0x20(%r14)
movl %r15d, 0x28(%r14)
movl $0x64, %edi
xorl %eax, %eax
callq 0xc72d
xorl %ecx, %ecx
cmpl $0xb, %eax
setl %cl
cmpl $0x4, %eax
movl $0x2, %eax
cmovgel %ecx, %eax
addl %eax, 0x24(%r14)
jmp 0x1b915
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 0x9804
movl %eax, 0x44(%r14)
jmp 0x1ba2b
leaq 0x11f53(%rip), %rax     # 0x2d880
movl $0x0, (%rax)
movq %r14, %rdi
callq 0xd4de
jmp 0x1ba2b
movl %r15d, 0x28(%r14)
movq %r14, %rdi
movl %r15d, %esi
callq 0x1cc7c
movl $0x64, %edi
xorl %eax, %eax
callq 0xc72d
cmpl $0x9, %eax
jg 0x1b9dd
movl $0x1, %esi
movq %r14, %rdi
callq 0x95d5
movl $0x3, %edi
xorl %eax, %eax
callq 0xc72d
notl %eax
addl %eax, 0x2c(%r14)
movl $0x3, %edi
xorl %eax, %eax
callq 0xc72d
notl %eax
addl %eax, 0x30(%r14)
jmp 0x1ba2b
movl %r15d, 0x28(%r14)
movq %r14, %rdi
movl %r15d, %esi
callq 0x6832
movl $0x64, %edi
xorl %eax, %eax
callq 0xc72d
cmpl $0x13, %eax
jg 0x1ba14
movl $0x1, %esi
movq %r14, %rdi
callq 0x95d5
movl $0x3, %edi
xorl %eax, %eax
callq 0xc72d
movl 0x34(%r14), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x34(%r14)
jmp 0x1ba2b
cmpl $0xe, %eax
jg 0x1ba2b
movl $0x3, %edi
xorl %eax, %eax
callq 0xc72d
movl 0x2c(%r14), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x2c(%r14)
movl $0x3, %edi
xorl %eax, %eax
callq 0xc72d
movl 0x30(%r14), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x30(%r14)
jmp 0x1ba2b
cmpl $0x1d, %eax
jg 0x1ba2b
movl $0x3, %edi
xorl %eax, %eax
callq 0xc72d
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