// File: /workspace/github_c_makefile_star2_O3/ajpaulson[P]srogue11/wizard.c
// Function: create_obj
int create_obj(bool fscr)
{
	struct linked_list *item;
	struct object *obj;
	int wh, ch, otype;
	char newitem, newtype, msz, *oname;
	struct magic_info *mf;
	bool nogood = TRUE, inhw = FALSE;

	if (fscr)
		msg(" ");
	else if (wizard) {
		msg("Create what?%s: ", starlist);
		ch = readchar();
		mpos = 0;
		if (ch == ESCAPE)
			return 0;
		else if (ch != '*')
			nogood = FALSE;
	}
	if (nogood) {
		inhw = TRUE;
		wclear(hw);
		wprintw(hw,"Item\tKey\n\n");
		for (otype = 0; otype < NUMTHINGS; otype++) {
			if (otype != TYP_AMULET || wizard) {
				mf = &thnginfo[otype];
				wprintw(hw,"%s\t %c\n",things[otype].mi_name,mf->mf_show);
			}
		}
		if (wizard)
			waddstr(hw,"monster\t (A-z)");
		wprintw(hw,"\n\nWhat do you want to create? ");
		draw(hw);
		do {
			ch = readchar();
			if (ch == ESCAPE) {
				after = FALSE;
				restscr(cw);
				return 0;
			}
			switch (ch) {
				case RING:		case STICK:	case POTION:
				case SCROLL:	case ARMOR:	case WEAPON:
				case FOOD:		case AMULET:
					nogood = FALSE;
					break;
				default:
					if (isalpha(ch))
						nogood = FALSE;
			}
		} while (nogood);
	}
	if (isalpha(ch)) {
		if (inhw)
			restscr(cw);
		makemons(ch);		/* make monster & be done with it */
		return 0;
	}
	otype = getindex(ch);
	if (otype == -1 || (otype == AMULET && !wizard)) {
		if (inhw)
			restscr(cw);
		mpos = 0;
		msg("You can't create that !!");
		return 0;
	}
	newitem = ch;
	mf = &thnginfo[otype];
	oname = things[otype].mi_name;
	msz = mf->mf_max;
	nogood = TRUE;
	if (msz == 1) {		/* if only one type of item */
		ch = 'a';
		nogood = FALSE;
	}
	else if (!fscr && wizard) {
		if (!inhw) {
			msg("Which %s?%s: ", oname, starlist);
			ch = readchar();
			if (ch == ESCAPE)
				return 0;
			if (ch != '*')
				nogood = FALSE;
		}
	}
	if (nogood) {
		struct magic_item *wmi;
		int ii;

		mpos = 0;
		inhw = TRUE;
		switch(newitem) {
			case POTION:	wmi = &p_magic[0];
			when SCROLL:	wmi = &s_magic[0];
			when RING:		wmi = &r_magic[0];
			when STICK:		wmi = &ws_magic[0];
			when WEAPON:	wmi = &w_magic[0];
			otherwise:		wmi = &a_magic[0];
		}
		wclear(hw);
		for (ii = 0 ; ii < msz ; ii++) {
			mvwaddch(hw,ii % 13,ii > 12 ? COLS/2 : 0, ii + 'a');
			waddstr(hw,") ");
			waddstr(hw,wmi->mi_name);
			wmi++;
		}
		sprintf(prbuf,"Which %s? ", oname);
		mvwaddstr(hw,LINES - 1, 0, prbuf);
		draw(hw);
		do {
			ch = readchar();
			if (ch == ESCAPE) {
				restscr(cw);
				msg("");
				return 0;
			}
		} while (!isalpha(ch));
	}
	if (inhw)			/* restore screen if need be */
		restscr(cw);

	newtype = tolower(ch) - 'a';
	if (newtype < 0 || newtype >= msz) {	/* if an illegal value */
		mpos = 0;
		after = FALSE;
		if (inhw)
			restscr(cw);
		msg("There is no such %s", oname);
		return 0;
	}
	mpos = 0;
	item = new_thing(FALSE, newitem, newtype);
	obj = OBJPTR(item);
	wh = obj->o_type;
	if (wh == WEAPON || wh == ARMOR || wh == RING) {
		if (fscr)					/* users get +3 to -3 */
			ch = rnd(7) - 3;
		else {						/* wizard gets to choose */
			if (wh == RING)
				init_ring(obj, TRUE);
			else
				ch = getbless();
		}
		if (wh == WEAPON)
			obj->o_hplus = obj->o_dplus = ch;
		else if (wh == ARMOR)
			obj->o_ac = armors[obj->o_which].a_class - ch;
		if (ch < 0)
			setoflg(obj, ISCURSED);
		else
			resoflg(obj, ISCURSED);
	}
	mpos = 0;
	if (fscr)
		whatis(item);			/* identify for aquirement scroll */
	wh = add_pack(item, FALSE);
	if (wh == FALSE)			/* won't fit in pack */
		discard(item);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, 0x8(%rsp)
testl %edi, %edi
je 0x1ce47
leaq 0x43c2(%rip), %rdi      # 0x21200
xorl %eax, %eax
callq 0xb620
jmp 0x1ce96
leaq 0x10a4f(%rip), %rax     # 0x2d89d
cmpb $0x1, (%rax)
jne 0x1ce96
leaq 0x6b14(%rip), %rdi      # 0x2396e
leaq 0xd53f(%rip), %rsi      # 0x2a3a0
xorl %eax, %eax
callq 0xb620
xorl %eax, %eax
callq 0xb94c
movl %eax, %r12d
leaq 0x109f7(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
cmpb $0x1b, %r12b
je 0x1d24c
movzbl %r12b, %eax
cmpl $0x2a, %eax
jne 0x1cfa1
leaq 0x13b4b(%rip), %rbx     # 0x309e8
movq (%rbx), %rdi
callq 0x6120
movq (%rbx), %rdi
leaq 0x6ad0(%rip), %rsi      # 0x2397f
xorl %eax, %eax
callq 0x6510
movq $-0xc0, %r15
leaq 0xef0c(%rip), %r13      # 0x2bdd0
leaq 0x109d2(%rip), %r12     # 0x2d89d
leaq 0xfa9e(%rip), %rbp      # 0x2c970
leaq 0x6ab1(%rip), %r14      # 0x2398a
cmpq $-0x18, %r15
jne 0x1cee6
cmpb $0x1, (%r12)
jne 0x1cf0a
movq (%rbx), %rdi
movq (%r13), %rdx
movsbl 0xc8(%rbp,%r15), %ecx
movq %r14, %rsi
xorl %eax, %eax
callq 0x6510
addq $0x10, %r13
addq $0x18, %r15
jne 0x1ced9
cmpb $0x1, (%r12)
jne 0x1cf25
movq (%rbx), %rdi
leaq 0x6a77(%rip), %rsi      # 0x23992
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
movq (%rbx), %rdi
leaq 0x6a72(%rip), %rsi      # 0x239a1
xorl %eax, %eax
callq 0x6510
movq (%rbx), %rdi
callq 0x6200
movabsq $0x1000000052004901, %rbx # imm = 0x1000000052004901
xorl %r13d, %r13d
xorl %eax, %eax
callq 0xb94c
movl %eax, %r12d
movzbl %al, %eax
leal -0x21(%rax), %ecx
cmpl $0x3c, %ecx
ja 0x1cf66
btq %rcx, %rbx
jb 0x1cfa4
cmpl $0x1b, %eax
je 0x1cf83
callq 0x65b0
movq (%rax), %rax
movsbq %r12b, %rcx
testb $0x4, 0x1(%rax,%rcx,2)
je 0x1cf4b
xorl %r13d, %r13d
jmp 0x1cfa4
leaq 0xd383(%rip), %rax      # 0x2a30d
movb $0x0, (%rax)
leaq 0x13a4c(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0xbd09
jmp 0x1d24c
movb $0x1, %r13b
movsbl %r12b, %ebp
callq 0x65b0
movq %rax, %r15
movq (%rax), %rax
movsbq %bpl, %rcx
testb $0x4, 0x1(%rax,%rcx,2)
jne 0x1d024
movl %ebp, %edi
callq 0xc9eb
cmpl $-0x1, %eax
je 0x1d044
cmpl $0x2c, %eax
jne 0x1cfdb
leaq 0x108c7(%rip), %rcx     # 0x2d89d
cmpb $0x0, (%rcx)
je 0x1d044
cltq
leaq (%rax,%rax,2), %rcx
leaq 0xf988(%rip), %rdx      # 0x2c970
shlq $0x4, %rax
leaq 0xeddd(%rip), %rsi      # 0x2bdd0
movq (%rsi,%rax), %rbx
movl (%rdx,%rcx,8), %eax
movsbl %al, %r14d
shll $0x18, %eax
cmpl $0x1000000, %eax        # imm = 0x1000000
sete %cl
orb 0x8(%rsp), %cl
je 0x1d071
movl $0x61, %ecx
cmpl $0x1000000, %eax        # imm = 0x1000000
jne 0x1d0b4
jmp 0x1d260
testb %r13b, %r13b
jne 0x1d038
leaq 0x139b0(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0xbd09
movl %ebp, %edi
callq 0x1d3c3
jmp 0x1d24c
testb %r13b, %r13b
jne 0x1d058
leaq 0x13990(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0xbd09
leaq 0x10811(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
leaq 0x6954(%rip), %rdi      # 0x239c0
jmp 0x1d245
leaq 0x10825(%rip), %rax     # 0x2d89d
movb (%rax), %al
andb %r13b, %al
cmpb $0x1, %al
jne 0x1d0b4
leaq 0x6951(%rip), %rdi      # 0x239d9
leaq 0xd311(%rip), %rdx      # 0x2a3a0
movq %rbx, %rsi
xorl %eax, %eax
callq 0xb620
xorl %eax, %eax
callq 0xb94c
cmpb $0x1b, %al
je 0x1d24c
movzbl %al, %ecx
cmpl $0x2a, %ecx
jne 0x1d25d
leaq 0x107b5(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
movzbl %r12b, %eax
cmpl $0x2e, %eax
movl %ebp, 0xc(%rsp)
movq %rbx, 0x10(%rsp)
jle 0x1d0eb
cmpl $0x2f, %eax
je 0x1d0fe
cmpl $0x3d, %eax
je 0x1d107
cmpl $0x3f, %eax
jne 0x1d119
leaq 0xf217(%rip), %rbx      # 0x2c300
jmp 0x1d120
cmpl $0x21, %eax
je 0x1d110
cmpl $0x29, %eax
jne 0x1d119
leaq 0xee94(%rip), %rbx      # 0x2bf90
jmp 0x1d120
leaq 0xf6bb(%rip), %rbx      # 0x2c7c0
jmp 0x1d120
leaq 0xf502(%rip), %rbx      # 0x2c610
jmp 0x1d120
leaq 0xf399(%rip), %rbx      # 0x2c4b0
jmp 0x1d120
leaq 0xed40(%rip), %rbx      # 0x2be60
leaq 0x138c1(%rip), %r13     # 0x309e8
movq (%r13), %rdi
callq 0x6120
testl %r14d, %r14d
jle 0x1d1b3
xorl %ebp, %ebp
leaq 0x68a9(%rip), %r12      # 0x239e7
movl $0x0, %edx
cmpl $0xd, %ebp
jb 0x1d15a
movq 0xce49(%rip), %rax      # 0x29f98
movl (%rax), %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
movl %ebp, %eax
imulq $0x4ec4ec4f, %rax, %rax # imm = 0x4EC4EC4F
shrq $0x22, %rax
imull $-0xd, %eax, %esi
movq (%r13), %rdi
addl %ebp, %esi
callq 0x6490
cmpl $-0x1, %eax
je 0x1d186
movq (%r13), %rdi
leal 0x61(%rbp), %esi
callq 0x64c0
movq (%r13), %rdi
movq %r12, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
movq (%r13), %rdi
movq (%rbx), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
addq $0x10, %rbx
incl %ebp
cmpl %ebp, %r14d
jne 0x1d13e
leaq 0x10cd6(%rip), %rdi     # 0x2de90
leaq 0x6829(%rip), %rsi      # 0x239ea
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x64f0
movq (%r13), %rdi
movq 0xcdd5(%rip), %rax      # 0x29fb0
movl (%rax), %esi
decl %esi
xorl %edx, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0x1d200
movq (%r13), %rdi
leaq 0x10c9a(%rip), %rsi     # 0x2de90
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
movq (%r13), %rdi
callq 0x6200
movl 0xc(%rsp), %ebp
xorl %eax, %eax
callq 0xb94c
cmpb $0x1b, %al
je 0x1d22f
movq (%r15), %rcx
movsbq %al, %rdx
testb $0x4, 0x1(%rcx,%rdx,2)
je 0x1d20d
movq %rbx, %r15
movsbl %al, %r13d
jmp 0x1d272
leaq 0x137aa(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0xbd09
leaq 0x6744(%rip), %rdi      # 0x23989
xorl %eax, %eax
callq 0xb620
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbl %al, %ecx
movq %rbx, %r15
testb %r13b, %r13b
je 0x1d26f
xorl %ebx, %ebx
movl %ecx, %r13d
jmp 0x1d283
movl %ecx, %r13d
leaq 0x13767(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0xbd09
movb $0x1, %bl
movl %r13d, %edi
callq 0x6310
addb $-0x61, %al
movsbl %al, %edx
leaq 0x105d9(%rip), %r12     # 0x2d870
movl $0x0, (%r12)
testl %edx, %edx
js 0x1d2f8
cmpl %r14d, %edx
jge 0x1d2f8
xorl %edi, %edi
movl %ebp, %esi
callq 0x1b640
movq %rax, %r14
movq 0x10(%rax), %r15
movl 0x20(%r15), %ebx
leal -0x29(%rbx), %eax
cmpl $0x34, %eax
ja 0x1d38d
movabsq $0x10000000100001, %rcx # imm = 0x10000000100001
btq %rax, %rcx
jae 0x1d38d
cmpb $0x0, 0x8(%rsp)
je 0x1d32b
movl $0x7, %edi
xorl %eax, %eax
callq 0xc674
movl %eax, %r13d
addl $-0x3, %r13d
jmp 0x1d347
leaq 0xd00e(%rip), %rax      # 0x2a30d
movb $0x0, (%rax)
testb %bl, %bl
je 0x1d315
leaq 0x136d3(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0xbd09
leaq 0x66d9(%rip), %rdi      # 0x239f5
movq %r15, %rsi
xorl %eax, %eax
callq 0xb620
jmp 0x1d24c
cmpl $0x3d, %ebx
jne 0x1d33f
movq %r15, %rdi
movl $0x1, %esi
callq 0x12b26
jmp 0x1d374
callq 0x1d4c5
movl %eax, %r13d
cmpl $0x5d, %ebx
je 0x1d35b
cmpl $0x29, %ebx
jne 0x1d374
movl %r13d, 0x30(%r15)
movl %r13d, 0x2c(%r15)
jmp 0x1d374
movslq 0x28(%r15), %rax
leaq (%rax,%rax,2), %rax
leaq 0xeba6(%rip), %rcx      # 0x2bf10
movl (%rcx,%rax,4), %eax
subl %r13d, %eax
movl %eax, 0x34(%r15)
movl $0x1, %esi
movq %r15, %rdi
testl %r13d, %r13d
js 0x1d388
callq 0x9557
jmp 0x1d38d
callq 0x9553
movl $0x0, (%r12)
cmpb $0x0, 0x8(%rsp)
je 0x1d3a4
movq %r14, %rdi
callq 0x1cd40
movq %r14, %rdi
xorl %esi, %esi
callq 0x10180
testb %al, %al
jne 0x1d24c
movq %r14, %rdi
callq 0xbdda
jmp 0x1d24c