// File: /workspace/github_c_makefile_star2_O2/ajpaulson[P]srogue11/monsters.c
// Function: new_monster
struct linked_list *new_monster(char type,struct coord *cp,bool treas)
{
	struct linked_list *item;
	struct thing *tp;
	struct monster *mp;
	struct stats *st;
	float killexp;		/* experience gotten for killing him */

	item = new_item(sizeof(struct thing));
	attach(mlist, item);
	tp = THINGPTR(item);
	st = &tp->t_stats;
	mp = &monsters[type];		/* point to this monsters structure */
	tp->t_type = mp->m_show;
	tp->t_indx = type;
	tp->t_pos = *cp;
	tp->t_room = roomin(cp);
	tp->t_oldch = mvwinch(cw, cp->y, cp->x);
	tp->t_nomove = 0;
	tp->t_nocmd = 0;
	mvwaddch(mw, cp->y, cp->x, tp->t_type);

	/*
	 * copy monster data
	 */
	tp->t_stats = mp->m_stats;

	/*
	 * If below amulet level, make the monsters meaner the
	 * deeper the hero goes.
	 */
	if (level > AMLEVEL)
		st->s_lvl += ((level - AMLEVEL) / 4);

	/*
	 * If monster in treasure room, then tougher.
	 */
	if (treas)
		st->s_lvl += 1;
	if (levtype == MAZELEV)
		st->s_lvl += 1;
	/*
	 * If the hero is going back up, then the monsters are more
	 * prepared for him, so tougher.
	 */
	if (goingup())
		st->s_lvl += 1;

	/*
	 * Get hit points for monster depending on his experience
	 */
	st->s_hpt = roll(st->s_lvl, 8);
	st->s_maxhp = st->s_hpt;
	/*
	 * Adjust experience point we get for killing it by the
	 *  strength of this particular monster by ~~ +- 50%
	 */
	killexp = mp->m_stats.s_exp * (0.47 + (float)st->s_hpt /
		(8 * (float)st->s_lvl));

	st->s_exp = killexp;			/* use float for accuracy */
	if(st->s_exp < 1)
		st->s_exp = 1;				/* minimum 1 experience point */
	tp->t_flags = mp->m_flags;
	/*
	 * If monster in treasure room, then MEAN
	 */
	if (treas || levtype == MAZELEV)
		tp->t_flags |= ISMEAN;
	tp->t_turn = TRUE;
	tp->t_pack = NULL;
	/*
	 * Dont wander if treas room
	 */
	if (iswearing(R_AGGR) && !treas)
		runto(cp, &hero);
	if (tp->t_type == 'M') {
		char mch;

		if (tp->t_pack != NULL)
			mch = (OBJPTR(tp->t_pack))->o_type;
		else {
			switch (rnd(level >= AMLEVEL ? 9 : 8)) {
				case 0: mch = GOLD;
				when 1: mch = POTION;
				when 2: mch = SCROLL;
				when 3: mch = STAIRS;
				when 4: mch = WEAPON;
				when 5: mch = ARMOR;
				when 6: mch = RING;
				when 7: mch = STICK;
				when 8: mch = AMULET;
			}
		}
		if (treas)
			mch = 'M';		/* no disguise in treasure room */
		tp->t_disguise = mch;
	}
	return item;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r15
movl %edi, %r12d
movl $0x98, %edi
callq 0xb877
movq %rax, %rbx
leaq 0x20980(%rip), %rdi     # 0x2d830
movq %rax, %rsi
callq 0xb81b
movq %rbx, (%rsp)
movq 0x10(%rbx), %r14
movslq %r12d, %rax
imulq $0x70, %rax, %r13
leaq 0x1d4e2(%rip), %r12     # 0x2a3b0
movb 0x8(%r12,%r13), %cl
movb %cl, 0x8d(%r14)
movl %eax, 0x80(%r14)
movq (%r15), %rax
movq %rax, 0x50(%r14)
movq %r15, %rdi
callq 0x6f44
movq %rax, 0x70(%r14)
leaq 0x23ad5(%rip), %rbx     # 0x309d0
movq (%rbx), %rdi
movl (%r15), %edx
movl 0x4(%r15), %esi
callq 0x6470
cmpl $-0x1, %eax
je 0xcf19
movq (%rbx), %rdi
callq 0x6320
jmp 0xcf1b
movb $-0x1, %al
addq %r13, %r12
movb %al, 0x8f(%r14)
andq $0x0, 0x84(%r14)
leaq 0x23aac(%rip), %r13     # 0x309e0
movq (%r13), %rdi
movl (%r15), %edx
movl 0x4(%r15), %esi
callq 0x6470
cmpl $-0x1, %eax
je 0xcf5a
movq (%r13), %rdi
movsbl 0x8d(%r14), %esi
callq 0x64a0
leaq 0x20(%r12), %rsi
pushq $0xa
popq %rcx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x1d371(%rip), %rbx     # 0x2a2e0
movl (%rbx), %eax
cmpl $0x24, %eax
jl 0xcf80
leal -0x23(%rax), %ecx
shrl $0x2, %ecx
addl %ecx, 0x28(%r14)
testb %bpl, %bpl
je 0xcf89
incl 0x28(%r14)
leaq 0x208c4(%rip), %r13     # 0x2d854
cmpl $0x2, (%r13)
jne 0xcf9b
incl 0x28(%r14)
leaq 0x1d34a(%rip), %rcx     # 0x2a2ec
movl 0x28(%r14), %edi
cmpl (%rcx), %eax
jge 0xcfb0
incl %edi
movl %edi, 0x28(%r14)
pushq $0x8
popq %rsi
callq 0xc025
movl %eax, 0x30(%r14)
movl %eax, 0x34(%r14)
cvtsi2sdq 0x40(%r12), %xmm0
cvtsi2ss %eax, %xmm1
cvtsi2ssl 0x28(%r14), %xmm2
mulss 0x12027(%rip), %xmm2    # 0x1f000
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
addsd 0x1201f(%rip), %xmm1    # 0x1f008
mulsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
cvttss2si %xmm0, %rax
cmpq $0x2, %rax
pushq $0x1
popq %rcx
cmovgeq %rax, %rcx
movq %rcx, 0x20(%r14)
movq 0x18(%r12), %rax
movq %rax, 0x78(%r14)
testb %bpl, %bpl
jne 0xd01a
cmpl $0x2, (%r13)
jne 0xd022
orq $0x20, %rax
movq %rax, 0x78(%r14)
movb $0x1, 0x8c(%r14)
andq $0x0, 0x68(%r14)
pushq $0x6
popq %rdi
callq 0x11fa5
xorb $0x1, %al
orb %bpl, %al
jne 0xd051
leaq 0x20c0b(%rip), %rsi     # 0x2dc50
addq $0x50, %rsi
movq %r15, %rdi
callq 0x7427
cmpb $0x4d, 0x8d(%r14)
jne 0xd0ae
movq 0x68(%r14), %rax
testq %rax, %rax
je 0xd06d
movq 0x10(%rax), %rax
movb 0x20(%rax), %dl
jmp 0xd09b
xorl %edi, %edi
cmpl $0x23, (%rbx)
setge %dil
orl $0x8, %edi
xorl %eax, %eax
callq 0xc004
decl %eax
movb $0x2a, %dl
cmpl $0x7, %eax
ja 0xd09b
shll $0x3, %eax
movabsq $0x2c2f3d5d29253f21, %rdx # imm = 0x2C2F3D5D29253F21
movl %eax, %ecx
shrq %cl, %rdx
movzbl %dl, %eax
testb %bpl, %bpl
pushq $0x4d
popq %rcx
cmovel %eax, %ecx
movb %cl, 0x8e(%r14)
movq (%rsp), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq