// File: /workspace/github_c_makefile_star2_O2/ajpaulson[P]srogue11/new_leve.c
// Function: new_level
void new_level(int ltype)
{
	char ch;
	struct coord traploc;
	struct room *rp;

	if (level > max_level)
		max_level = level;

	wclear(cw);
	wclear(mw);
	clear();

	isfight = FALSE;
	levtype = ltype;

	free_list(mlist);			/* free monster list */

	if (levtype == POSTLEV)
		do_post();
	else {
		lev_mon();			/* fill in monster list */

		if (levtype == MAZELEV)
			do_maze();
		else {				/* normal levels */
			do_rooms();		/* Draw rooms */
			do_passages();		/* Draw passages */
		}
		no_food++;
		put_things();			/* Place objects (if any) */
	}
	/*
	 * Place the staircase down.
	 */
	stairs = *rnd_pos(&rooms[rnd_room()]);
	mvaddch(stairs.y, stairs.x, STAIRS);
	ntraps = 0;

	if (levtype == NORMLEV)
	{
		struct trap *trp, *maxtrp;

		/* Place the traps for normal levels only */

		if (rnd(10) < level)
		{
			ntraps = rnd(level / 4) + 1;

			if (ntraps > MAXTRAPS)
				ntraps = MAXTRAPS;

			maxtrp = &traps[ntraps];
			for (trp = &traps[0]; trp < maxtrp; trp++)
			{
again:
				switch(rnd(TYPETRAPS + 1))
				{
					case 0:
						if (rnd(100) > 25)
							goto again;
						else
							ch = POST;

					when 1: ch = TRAPDOOR;
					when 2: ch = BEARTRAP;
					when 3: ch = SLEEPTRAP;
					when 4: ch = ARROWTRAP;
					when 5: ch = TELTRAP;
					when 6: ch = DARTTRAP;
					when 7: ch = MAZETRAP;
					when 8:
					case 9:
						if (rnd(100) > 80)
							goto again;
						else
							ch = POOL;
				}
				trp->tr_flags = 0;
				traploc = *rnd_pos(&rooms[rnd_room()]);
				mvaddch(traploc.y,traploc.x,ch);
				trp->tr_type = ch;
				trp->tr_pos = traploc;

				if (ch == POOL || ch == POST)
					trp->tr_flags |= ISFOUND;

				if (ch==TELTRAP && rnd(100)<20 && trp<maxtrp-1)
				{
					struct coord newloc;

					newloc = *rnd_pos(&rooms[rnd_room()]);
					trp->tr_goto = newloc;
					trp++;
					trp->tr_goto = traploc;
					trp->tr_type = TELTRAP;
					trp->tr_pos = newloc;
					mvaddch(newloc.y, newloc.x, TELTRAP);
				}
				else
					trp->tr_goto = rndspot;
			}
		}
	}
	do
	{
		rp = &rooms[rnd_room()];
		hero = *rnd_pos(rp);
	} while(levtype==MAZELEV&&DISTANCE(hero.y,hero.x,stairs.y,stairs.x)<10);

	player.t_room = rp;
	player.t_oldch = mvinch(hero.y, hero.x);
	light(&hero);
	mvwaddch(cw,hero.y,hero.x,PLAYER);
	nochange = FALSE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, %ebx
leaq 0x1b781(%rip), %r14     # 0x2a2e0
movl (%r14), %eax
leaq 0x1b783(%rip), %rcx     # 0x2a2ec
cmpl (%rcx), %eax
jle 0xeb6f
movl %eax, (%rcx)
leaq 0x21e5a(%rip), %rax     # 0x309d0
movq (%rax), %rdi
callq 0x6120
leaq 0x21e5b(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0x6120
movq 0x1b3a4(%rip), %r15     # 0x29f38
movq (%r15), %rdi
callq 0x6120
leaq 0x1ece5(%rip), %rax     # 0x2d888
movb $0x0, (%rax)
leaq 0x1eca7(%rip), %r12     # 0x2d854
movl %ebx, (%r12)
leaq 0x1ec78(%rip), %rdi     # 0x2d830
callq 0xb83c
cmpl $0x1, (%r12)
jne 0xebcd
xorl %eax, %eax
callq 0x19f78
jmp 0xec00
xorl %eax, %eax
callq 0xce1a
cmpl $0x2, (%r12)
jne 0xebe4
xorl %eax, %eax
callq 0x1a5fc
jmp 0xebf2
xorl %eax, %eax
callq 0x12bf4
xorl %eax, %eax
callq 0x10118
leaq 0x1ec77(%rip), %rax     # 0x2d870
incl (%rax)
callq 0xef86
callq 0xef36
cltq
imulq $0x68, %rax, %rdi
addq 0x1b2fe(%rip), %rdi     # 0x29f10
callq 0x1310e
movq (%rax), %rdx
leaq 0x2183b(%rip), %rbp     # 0x3045c
movq %rdx, (%rbp)
movq (%r15), %rdi
movq %rdx, %rsi
shrq $0x20, %rsi
callq 0x6470
cmpl $-0x1, %eax
je 0xec44
movq (%r15), %rdi
pushq $0x25
popq %rsi
callq 0x64a0
leaq 0x1f20d(%rip), %rbx     # 0x2de58
andl $0x0, (%rbx)
cmpl $0x0, (%r12)
jne 0xee75
pushq $0xa
popq %rdi
xorl %eax, %eax
callq 0xc004
movl %eax, %ecx
movl (%r14), %eax
cmpl %eax, %ecx
jge 0xee75
pushq $0x4
popq %rcx
cltd
idivl %ecx
movl %eax, %edi
xorl %eax, %eax
callq 0xc004
cmpl $0x9, %eax
pushq $0x9
popq %rcx
cmovll %eax, %ecx
incl %ecx
movl %ecx, (%rbx)
movslq %ecx, %rax
imulq $0x18, %rax, %rax
leaq 0x1f0c6(%rip), %r14     # 0x2dd60
leaq (%r14,%rax), %rcx
movq %rcx, 0x20(%rsp)
addq %r14, %rax
addq $-0x18, %rax
movq %rax, 0x18(%rsp)
pushq $0xa
popq %rbx
pushq $0x64
popq %r15
leaq 0x10777(%rip), %r13     # 0x1f434
cmpq 0x20(%rsp), %r14
jae 0xee75
movb %cl, 0xf(%rsp)
movl %ebx, %edi
xorl %eax, %eax
callq 0xc004
cmpl $0x9, %eax
ja 0xed43
movl %eax, %eax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl %r15d, %edi
xorl %eax, %eax
callq 0xc004
cmpl $0x50, %eax
jg 0xeccc
jmp 0xed0d
movl %r15d, %edi
xorl %eax, %eax
callq 0xc004
cmpl $0x19, %eax
jg 0xeccc
movb $0x5e, 0xf(%rsp)
jmp 0xed43
movb $0x22, 0xf(%rsp)
jmp 0xed43
movb $0x7d, 0xf(%rsp)
jmp 0xed43
movb $0x7b, 0xf(%rsp)
jmp 0xed43
movb $0x24, 0xf(%rsp)
jmp 0xed43
movb $0x5c, 0xf(%rsp)
jmp 0xed43
movb $0x7e, 0xf(%rsp)
jmp 0xed43
movb $0x3e, 0xf(%rsp)
jmp 0xed43
movb $0x60, 0xf(%rsp)
andl $0x0, 0x10(%r14)
callq 0xef36
cltq
imulq $0x68, %rax, %rdi
addq 0x1b1b6(%rip), %rdi     # 0x29f10
callq 0x1310e
movl (%rax), %r15d
movl 0x4(%rax), %r12d
movq 0x1b1cb(%rip), %rbp     # 0x29f38
movq (%rbp), %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x6470
cmpl $-0x1, %eax
movb 0xf(%rsp), %bl
je 0xed91
movq (%rbp), %rdi
movsbl %bl, %esi
callq 0x64a0
movb %bl, 0x14(%r14)
movl %r15d, (%r14)
movl %r12d, 0x4(%r14)
cmpb $0x22, %bl
leaq 0x216b6(%rip), %rbp     # 0x3045c
movl %ebx, %ecx
pushq $0xa
popq %rbx
je 0xedba
movzbl %cl, %eax
cmpl $0x7e, %eax
je 0xede1
cmpl $0x5e, %eax
jne 0xedbf
orb $0x8, 0x10(%r14)
leaq 0x1b5da(%rip), %rax     # 0x2a3a0
movq (%rax), %rax
movq %rax, 0x8(%r14)
leaq 0x1ea80(%rip), %r12     # 0x2d854
pushq $0x64
popq %r15
addq $0x18, %r14
jmp 0xecbd
pushq $0x64
popq %rdi
xorl %eax, %eax
callq 0xc004
movb 0xf(%rsp), %cl
cmpl $0x13, %eax
jg 0xedbf
cmpq 0x18(%rsp), %r14
jae 0xedbf
callq 0xef36
cltq
imulq $0x68, %rax, %rdi
addq 0x1b103(%rip), %rdi     # 0x29f10
callq 0x1310e
movl (%rax), %edx
movl 0x4(%rax), %esi
movl %edx, 0x8(%r14)
movl %esi, 0xc(%r14)
leaq 0x18(%r14), %rax
movq %rax, 0x10(%rsp)
movl %r15d, 0x20(%r14)
movl %r12d, 0x24(%r14)
movb $0x7e, 0x2c(%r14)
movl %edx, 0x18(%r14)
movl %esi, 0x1c(%r14)
movq 0x1b0f4(%rip), %r14     # 0x29f38
movq (%r14), %rdi
callq 0x6470
cmpl $-0x1, %eax
je 0xee5c
movq (%r14), %rdi
pushq $0x7e
popq %rsi
callq 0x64a0
movq 0x10(%rsp), %r14
leaq 0x1e9ec(%rip), %r12     # 0x2d854
pushq $0x64
popq %r15
movb 0xf(%rsp), %cl
jmp 0xedd8
callq 0xef36
cltq
imulq $0x68, %rax, %rbx
addq 0x1b089(%rip), %rbx     # 0x29f10
movq %rbx, %rdi
callq 0x1310e
movq (%rax), %rdx
leaq 0x1edb7(%rip), %r14     # 0x2dc50
movq %rdx, 0x50(%r14)
movq %rdx, %rsi
shrq $0x20, %rsi
cmpl $0x2, (%r12)
jne 0xeec2
movl (%rbp), %eax
movl 0x4(%rbp), %ecx
subl %edx, %eax
imull %eax, %eax
subl %esi, %ecx
imull %ecx, %ecx
addl %eax, %ecx
cmpl $0xa, %ecx
jb 0xee75
movq %rbx, 0x70(%r14)
movq 0x1b06b(%rip), %rbx     # 0x29f38
movq (%rbx), %rdi
callq 0x6470
cmpl $-0x1, %eax
je 0xeee4
movq (%rbx), %rdi
callq 0x6320
jmp 0xeee6
movb $-0x1, %al
leaq 0x21ae3(%rip), %rbx     # 0x309d0
movb %al, 0x8f(%r14)
leaq 0x50(%r14), %rdi
callq 0xe29f
movq (%rbx), %rdi
movl 0x50(%r14), %edx
movl 0x54(%r14), %esi
callq 0x6470
cmpl $-0x1, %eax
je 0xef1d
movq (%rbx), %rdi
pushq $0x40
popq %rsi
callq 0x64a0
leaq 0x1e96f(%rip), %rax     # 0x2d893
movb $0x0, (%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq