// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movb %dl, %al
movb %dil, %cl
movb %cl, -0x1(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movl $0x98, %edi
callq 0xe4d0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rsi
leaq 0x2672e(%rip), %rdi     # 0x36cb0
callq 0xe3e0
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movsbq -0x1(%rbp), %rcx
leaq 0x22e19(%rip), %rax     # 0x333c0
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb 0x8(%rax), %cl
movq -0x28(%rbp), %rax
movb %cl, 0x8d(%rax)
movsbl -0x1(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x80(%rax)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rdi
callq 0x7560
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x70(%rax)
leaq 0x29855(%rip), %rax     # 0x39e50
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x10(%rbp), %rax
movl (%rax), %edx
callq 0x6490
cmpl $-0x1, %eax
jne 0x1061f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x44(%rbp)
jmp 0x10631
leaq 0x2982a(%rip), %rax     # 0x39e50
movq (%rax), %rdi
callq 0x6340
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x8f(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x84(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x88(%rax)
leaq 0x297fd(%rip), %rax     # 0x39e60
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x10(%rbp), %rax
movl (%rax), %edx
callq 0x6490
cmpl $-0x1, %eax
jne 0x1067f
jmp 0x10699
leaq 0x297da(%rip), %rax     # 0x39e60
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movsbl 0x8d(%rax), %esi
callq 0x64c0
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x20, %rsi
movl $0x50, %edx
callq 0x62c0
leaq 0x22c3a(%rip), %rax     # 0x332f0
cmpl $0x23, (%rax)
jle 0x106db
leaq 0x22c2e(%rip), %rax     # 0x332f0
movl (%rax), %eax
subl $0x23, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x38(%rbp), %rax
addl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
testb $0x1, -0x11(%rbp)
je 0x106ee
movq -0x38(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
leaq 0x265df(%rip), %rax     # 0x36cd4
cmpl $0x2, (%rax)
jne 0x10707
movq -0x38(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
leaq 0x22be2(%rip), %rax     # 0x332f0
movl (%rax), %eax
leaq 0x22be5(%rip), %rcx     # 0x332fc
cmpl (%rcx), %eax
jge 0x10728
movq -0x38(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq -0x38(%rbp), %rax
movl 0x28(%rax), %edi
movl $0x8, %esi
callq 0xef70
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x38(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x30(%rbp), %rax
cvtsi2sdq 0x40(%rax), %xmm0
movq -0x38(%rbp), %rax
cvtsi2ssl 0x30(%rax), %xmm1
movq -0x38(%rbp), %rax
cvtsi2ssl 0x28(%rax), %xmm3
movss 0x1addc(%rip), %xmm2    # 0x2b550
mulss %xmm3, %xmm2
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x1adc0(%rip), %xmm1    # 0x2b548
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x3c(%rbp)
cvttss2si -0x3c(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rax
cmpq $0x1, 0x20(%rax)
jge 0x107be
movq -0x38(%rbp), %rax
movq $0x1, 0x20(%rax)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x78(%rax)
testb $0x1, -0x11(%rbp)
jne 0x107e0
leaq 0x264f9(%rip), %rax     # 0x36cd4
cmpl $0x2, (%rax)
jne 0x107f0
movq -0x28(%rbp), %rax
movq 0x78(%rax), %rcx
orq $0x20, %rcx
movq %rcx, 0x78(%rax)
movq -0x28(%rbp), %rax
movb $0x1, 0x8c(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x68(%rax)
movl $0x6, %edi
callq 0x18220
testb $0x1, %al
jne 0x10817
jmp 0x10831
testb $0x1, -0x11(%rbp)
jne 0x10831
movq -0x10(%rbp), %rdi
leaq 0x268a8(%rip), %rsi     # 0x370d0
addq $0x50, %rsi
callq 0x7bf0
movq -0x28(%rbp), %rax
movsbl 0x8d(%rax), %eax
cmpl $0x4d, %eax
jne 0x108ec
movq -0x28(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x10864
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movq 0x10(%rax), %rax
movl 0x20(%rax), %eax
movb %al, -0x3d(%rbp)
jmp 0x108d5
leaq 0x22a85(%rip), %rax     # 0x332f0
movl (%rax), %eax
subl $0x23, %eax
setge %al
movzbl %al, %edi
orl $0x8, %edi
xorl %eax, %eax
callq 0xef20
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x8, %eax
ja 0x108d3
movq -0x50(%rbp), %rax
leaq 0x1acbe(%rip), %rcx     # 0x2b554
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x2a, -0x3d(%rbp)
jmp 0x108d3
movb $0x21, -0x3d(%rbp)
jmp 0x108d3
movb $0x3f, -0x3d(%rbp)
jmp 0x108d3
movb $0x25, -0x3d(%rbp)
jmp 0x108d3
movb $0x29, -0x3d(%rbp)
jmp 0x108d3
movb $0x5d, -0x3d(%rbp)
jmp 0x108d3
movb $0x3d, -0x3d(%rbp)
jmp 0x108d3
movb $0x2f, -0x3d(%rbp)
jmp 0x108d3
movb $0x2c, -0x3d(%rbp)
jmp 0x108d5
testb $0x1, -0x11(%rbp)
je 0x108df
movb $0x4d, -0x3d(%rbp)
movb -0x3d(%rbp), %cl
movq -0x28(%rbp), %rax
movb %cl, 0x8e(%rax)
movq -0x20(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)