// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movl %edi, %ebx
leaq 0x1ada5(%rip), %r14     # 0x2a2f0
movl (%r14), %eax
leaq 0x1ada7(%rip), %rcx     # 0x2a2fc
cmpl (%rcx), %eax
jle 0xf55b
movl %eax, (%rcx)
leaq 0x2147e(%rip), %rax     # 0x309e0
movq (%rax), %rdi
callq 0x6120
leaq 0x2147f(%rip), %rax     # 0x309f0
movq (%rax), %rdi
callq 0x6120
movq 0x1a9b0(%rip), %r15     # 0x29f30
movq (%r15), %rdi
callq 0x6120
leaq 0x1e309(%rip), %rax     # 0x2d898
movb $0x0, (%rax)
leaq 0x1e2cb(%rip), %r12     # 0x2d864
movl %ebx, (%r12)
leaq 0x1e29c(%rip), %rdi     # 0x2d840
callq 0xbd9a
cmpl $0x1, (%r12)
jne 0xf5b9
xorl %eax, %eax
callq 0x1ba10
jmp 0xf5ec
xorl %eax, %eax
callq 0xd5c5
cmpl $0x2, (%r12)
jne 0xf5d0
xorl %eax, %eax
callq 0x1c121
jmp 0xf5de
xorl %eax, %eax
callq 0x1391c
xorl %eax, %eax
callq 0x10c18
leaq 0x1e29b(%rip), %rax     # 0x2d880
incl (%rax)
callq 0xf95b
callq 0xf913
cltq
imulq $0x68, %rax, %rdi
addq 0x1a912(%rip), %rdi     # 0x29f10
callq 0x13f09
movq (%rax), %rdx
leaq 0x20e5f(%rip), %r13     # 0x3046c
movq %rdx, (%r13)
movq (%r15), %rdi
movq %rdx, %rsi
shrq $0x20, %rsi
callq 0x6490
cmpl $-0x1, %eax
je 0xf632
movq (%r15), %rdi
movl $0x25, %esi
callq 0x64c0
leaq 0x1e82f(%rip), %rbx     # 0x2de68
movl $0x0, (%rbx)
cmpl $0x0, (%r12)
jne 0xf844
movl $0xa, %edi
xorl %eax, %eax
callq 0xc674
movl (%r14), %ecx
cmpl %ecx, %eax
jge 0xf844
leal 0x3(%rcx), %edi
testl %ecx, %ecx
cmovnsl %ecx, %edi
sarl $0x2, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x9, %eax
movl $0x9, %ecx
cmovll %eax, %ecx
incl %ecx
movl %ecx, (%rbx)
testl %eax, %eax
js 0xf844
movslq %ecx, %rax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq 0x1a924(%rip), %rax     # 0x29fc0
movq %rax, 0x10(%rsp)
addq $-0x18, %rax
movq %rax, 0x8(%rsp)
leaq 0x1e6bf(%rip), %r12     # 0x2dd70
leaq 0x11d7c(%rip), %r15     # 0x21434
movl $0xa, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x9, %eax
ja 0xf721
movl %eax, %eax
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x50, %eax
jg 0xf6b8
movb $0x22, %r14b
jmp 0xf721
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x19, %eax
jg 0xf6b8
movb $0x5e, %r14b
jmp 0xf721
movb $0x7d, %r14b
jmp 0xf721
movb $0x7e, %r14b
jmp 0xf721
movb $0x7b, %r14b
jmp 0xf721
movb $0x24, %r14b
jmp 0xf721
movb $0x3e, %r14b
jmp 0xf721
movb $0x60, %r14b
jmp 0xf721
movb $0x5c, %r14b
movl $0x0, 0x10(%r12)
callq 0xf913
cltq
imulq $0x68, %rax, %rdi
addq 0x1a7d4(%rip), %rdi     # 0x29f10
callq 0x13f09
movl (%rax), %ebx
movl 0x4(%rax), %ebp
movq 0x1a7e3(%rip), %r13     # 0x29f30
movq (%r13), %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0xf76c
movq (%r13), %rdi
movsbl %r14b, %esi
callq 0x64c0
movb %r14b, 0x14(%r12)
movl %ebx, (%r12)
movl %ebp, 0x4(%r12)
cmpb $0x22, %r14b
je 0xf78e
movzbl %r14b, %eax
cmpl $0x7e, %eax
je 0xf7be
cmpl $0x5e, %eax
jne 0xf794
orb $0x8, 0x10(%r12)
leaq 0x1ac15(%rip), %rax     # 0x2a3b0
movq (%rax), %rax
movq %rax, 0x8(%r12)
leaq 0x20cc2(%rip), %r13     # 0x3046c
addq $0x18, %r12
cmpq 0x10(%rsp), %r12
jb 0xf6b8
jmp 0xf844
movl $0x64, %edi
xorl %eax, %eax
callq 0xc674
cmpl $0x13, %eax
jg 0xf794
cmpq 0x8(%rsp), %r12
jae 0xf794
callq 0xf913
cltq
imulq $0x68, %rax, %rdi
addq 0x1a728(%rip), %rdi     # 0x29f10
callq 0x13f09
movl (%rax), %edx
movl 0x4(%rax), %esi
movl %edx, 0x8(%r12)
movl %esi, 0xc(%r12)
leaq 0x18(%r12), %r13
movl %ebx, 0x20(%r12)
movl %ebp, 0x24(%r12)
movb $0x7e, 0x2c(%r12)
movl %edx, 0x18(%r12)
movl %esi, 0x1c(%r12)
movq 0x1a70e(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
callq 0x6490
cmpl $-0x1, %eax
je 0xf83c
movq (%rbx), %rdi
movl $0x7e, %esi
callq 0x64c0
movq %r13, %r12
jmp 0xf7a3
leaq 0x1e065(%rip), %r15     # 0x2d8b0
leaq 0x1e40e(%rip), %r14     # 0x2dc60
leaq 0x1e00b(%rip), %r12     # 0x2d864
callq 0xf913
cltq
imulq $0x68, %rax, %rbx
addq %r15, %rbx
movq %rbx, %rdi
callq 0x13f09
movq (%rax), %rdx
movq %rdx, 0x50(%r14)
movq %rdx, %rsi
shrq $0x20, %rsi
cmpl $0x2, (%r12)
jne 0xf89d
movl (%r13), %eax
movl 0x4(%r13), %ecx
subl %edx, %eax
imull %eax, %eax
subl %esi, %ecx
imull %ecx, %ecx
addl %eax, %ecx
cmpl $0xa, %ecx
jb 0xf859
movq %rbx, 0x70(%r14)
movq 0x1a688(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
callq 0x6490
cmpl $-0x1, %eax
je 0xf8bf
movq (%rbx), %rdi
callq 0x6330
jmp 0xf8c1
movb $-0x1, %al
leaq 0x21118(%rip), %rbx     # 0x309e0
movb %al, 0x8f(%r14)
leaq 0x50(%r14), %rdi
callq 0xeba8
movq (%rbx), %rdi
movl 0x50(%r14), %edx
movl 0x54(%r14), %esi
callq 0x6490
cmpl $-0x1, %eax
je 0xf8fa
movq (%rbx), %rdi
movl $0x40, %esi
callq 0x64c0
leaq 0x1dfa2(%rip), %rax     # 0x2d8a3
movb $0x0, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq