// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movb %dil, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl $0x50, %edi
callq 0xe4d0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x24380
cmpl $-0x1, -0x8(%rbp)
jne 0x24099
leaq 0x12c8a(%rip), %rax     # 0x36cf0
movl (%rax), %eax
addl $0x1, %eax
leaq 0x12c7e(%rip), %rcx     # 0x36cf0
movl %eax, (%rcx)
cmpl $0x4, %eax
jle 0x24088
testb $0x1, -0x1(%rbp)
jne 0x24088
movl $0x2, -0x30(%rbp)
jmp 0x24097
leaq 0x10d41(%rip), %rdi     # 0x34dd0
callq 0x24450
movl %eax, -0x30(%rbp)
jmp 0x240a7
movl -0x8(%rbp), %eax
movsbl %al, %edi
callq 0xf3b0
movl %eax, -0x30(%rbp)
movslq -0x30(%rbp), %rcx
leaq 0x118be(%rip), %rax     # 0x35970
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpl $-0x1, -0xc(%rbp)
jne 0x240e3
movl $0x0, -0xc(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x240e1
movq -0x20(%rbp), %rdi
callq 0x24450
movl %eax, -0xc(%rbp)
jmp 0x240e3
movslq -0x30(%rbp), %rcx
shlq $0x4, %rcx
leaq 0x10cde(%rip), %rax     # 0x34dd0
movq (%rax,%rcx), %rdx
movq -0x28(%rbp), %rcx
movq %rdx, 0x18(%rcx)
movslq -0x30(%rbp), %rcx
shlq $0x4, %rcx
movl 0xc(%rax,%rcx), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x40(%rax)
movl -0x30(%rbp), %eax
movq %rax, -0x38(%rbp)
subq $0x7, %rax
ja 0x24358
movq -0x38(%rbp), %rax
leaq 0x9a97(%rip), %rcx      # 0x2dbc4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rax
movl $0x2c, 0x20(%rax)
movq -0x28(%rbp), %rax
movl $0x1f4, 0x2c(%rax)      # imm = 0x1F4
movq -0x28(%rbp), %rdi
addq $0x10, %rdi
leaq 0x9c84(%rip), %rsi      # 0x2dddf
callq 0x60d0
movq -0x28(%rbp), %rdi
callq 0xae90
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x44(%rax)
jmp 0x2436b
movq -0x28(%rbp), %rax
movl $0x21, 0x20(%rax)
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
callq 0x24520
movl %eax, %ecx
movq -0x28(%rbp), %rax
addl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x28(%rbp), %rdi
callq 0xae90
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x44(%rax)
jmp 0x2436b
movq -0x28(%rbp), %rax
movl $0x3f, 0x20(%rax)
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
callq 0x24520
movl %eax, %ecx
movq -0x28(%rbp), %rax
addl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x28(%rbp), %rdi
callq 0xae90
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x44(%rax)
jmp 0x2436b
leaq 0x12af8(%rip), %rax     # 0x36cf0
movl $0x0, (%rax)
movq -0x28(%rbp), %rdi
callq 0x10250
jmp 0x2436b
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x25ea0
movl $0x64, %edi
movb $0x0, %al
callq 0xef20
movl %eax, -0x2c(%rbp)
cmpl $0xa, %eax
jge 0x24280
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xab50
movl $0x3, %edi
movb $0x0, %al
callq 0xef20
movl %eax, %edx
addl $0x1, %edx
movq -0x28(%rbp), %rax
movl 0x2c(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x2c(%rax)
movl $0x3, %edi
movb $0x0, %al
callq 0xef20
movl %eax, %edx
addl $0x1, %edx
movq -0x28(%rbp), %rax
movl 0x30(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x30(%rax)
jmp 0x242be
cmpl $0xf, -0x2c(%rbp)
jge 0x242bc
movl $0x3, %edi
movb $0x0, %al
callq 0xef20
movl %eax, %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
addl 0x2c(%rax), %ecx
movl %ecx, 0x2c(%rax)
movl $0x3, %edi
movb $0x0, %al
callq 0xef20
movl %eax, %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
addl 0x30(%rax), %ecx
movl %ecx, 0x30(%rax)
jmp 0x242be
jmp 0x2436b
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x6870
movl $0x64, %edi
movb $0x0, %al
callq 0xef20
movl %eax, -0x2c(%rbp)
cmpl $0x14, %eax
jge 0x24318
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xab50
movl $0x3, %edi
movb $0x0, %al
callq 0xef20
movl %eax, %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
addl 0x34(%rax), %ecx
movl %ecx, 0x34(%rax)
jmp 0x2433d
cmpl $0x1e, -0x2c(%rbp)
jge 0x2433b
movl $0x3, %edi
movb $0x0, %al
callq 0xef20
movl %eax, %edx
addl $0x1, %edx
movq -0x28(%rbp), %rax
movl 0x34(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x34(%rax)
jmp 0x2433d
jmp 0x2436b
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x18010
jmp 0x2436b
jmp 0x24358
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x28(%rbp), %rdi
callq 0x211d0
movq -0x18(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)