// File: /workspace/github_c_makefile_star2_O1/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 0xbeb3
movq %rax, %rbx
leaq 0x2016e(%rip), %rdi     # 0x2d840
movq %rax, %rsi
callq 0xbe2d
movq %rbx, (%rsp)
movq 0x10(%rbx), %r14
movslq %r12d, %rax
imulq $0x70, %rax, %r13
leaq 0x1ccd0(%rip), %r12     # 0x2a3c0
movb 0x8(%r12,%r13), %cl
movb %cl, 0x8d(%r14)
movl %eax, 0x80(%r14)
movq (%r15), %rax
movq %rax, 0x50(%r14)
movq %r15, %rdi
callq 0x7052
movq %rax, 0x70(%r14)
leaq 0x232c3(%rip), %rbx     # 0x309e0
movq (%rbx), %rdi
movl (%r15), %edx
movl 0x4(%r15), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0xd73b
movq (%rbx), %rdi
callq 0x6330
jmp 0xd73d
movb $-0x1, %al
addq %r13, %r12
movb %al, 0x8f(%r14)
movq $0x0, 0x84(%r14)
leaq 0x23297(%rip), %r13     # 0x309f0
movq (%r13), %rdi
movl (%r15), %edx
movl 0x4(%r15), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0xd77f
movq (%r13), %rdi
movsbl 0x8d(%r14), %esi
callq 0x64c0
leaq 0x20(%r12), %rsi
movl $0xa, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x1cb5a(%rip), %rbx     # 0x2a2f0
movl (%rbx), %eax
cmpl $0x24, %eax
jl 0xd7a7
leal -0x23(%rax), %ecx
shrl $0x2, %ecx
addl %ecx, 0x28(%r14)
testb %bpl, %bpl
je 0xd7b0
incl 0x28(%r14)
leaq 0x200ad(%rip), %r13     # 0x2d864
cmpl $0x2, (%r13)
jne 0xd7c2
incl 0x28(%r14)
leaq 0x1cb33(%rip), %rcx     # 0x2a2fc
cmpl (%rcx), %eax
jge 0xd7d1
incl 0x28(%r14)
movl 0x28(%r14), %edi
movl $0x8, %esi
callq 0xc74e
movl %eax, 0x30(%r14)
movl %eax, 0x34(%r14)
cvtsi2sdq 0x40(%r12), %xmm0
cvtsi2ss %eax, %xmm1
cvtsi2ssl 0x28(%r14), %xmm2
mulss 0x1376c(%rip), %xmm2    # 0x20f6c
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
addsd 0x13760(%rip), %xmm1    # 0x20f70
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvttss2si %xmm0, %rax
cmpq $0x2, %rax
movl $0x1, %ecx
cmovgeq %rax, %rcx
movq %rcx, 0x20(%r14)
movq 0x18(%r12), %rax
movq %rax, 0x78(%r14)
testb %bpl, %bpl
jne 0xd846
cmpl $0x2, (%r13)
jne 0xd84e
orq $0x20, %rax
movq %rax, 0x78(%r14)
movb $0x1, 0x8c(%r14)
movq $0x0, 0x68(%r14)
movl $0x6, %edi
callq 0x12d9c
xorb $0x1, %al
orb %bpl, %al
jne 0xd882
leaq 0x203ea(%rip), %rsi     # 0x2dc60
addq $0x50, %rsi
movq %r15, %rdi
callq 0x7571
cmpb $0x4d, 0x8d(%r14)
jne 0xd8e1
movq 0x68(%r14), %rax
testq %rax, %rax
je 0xd89e
movq 0x10(%rax), %rax
movb 0x20(%rax), %dl
jmp 0xd8cc
xorl %edi, %edi
cmpl $0x23, (%rbx)
setge %dil
orl $0x8, %edi
xorl %eax, %eax
callq 0xc72d
decl %eax
movb $0x2a, %dl
cmpl $0x7, %eax
ja 0xd8cc
shll $0x3, %eax
movabsq $0x2c2f3d5d29253f21, %rdx # imm = 0x2C2F3D5D29253F21
movl %eax, %ecx
shrq %cl, %rdx
movzbl %dl, %eax
testb %bpl, %bpl
movl $0x4d, %ecx
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