// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/mm.c
// Function: _munmap_pages
void __munmap_pages(struct mm *mm, virt_t addr, pfn_t count)
{
	DBG_ASSERT((addr & PAGE_MASK) == 0);

	const virt_t from = addr;
	const virt_t to = from + ((virt_t)count << PAGE_BITS);

	struct pt_iter iter;

	for_each_slot_in_range(page_addr(mm->pt), from, to, iter) {
		DBG_ASSERT(iter.level == 0);
		DBG_ASSERT(iter.pt[iter.level] != 0);

		const int index = iter.idx[iter.level];
		pte_t *pt = iter.pt[iter.level];
		const pte_t pte = pt[index];

		pt[index] = 0;
		if (pte_present(pte)) {
			const phys_t phys = pte_phys(pte);
			const pfn_t pfn = phys >> PAGE_BITS;
			struct page *page = pfn2page(pfn);

			put_page(page);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
andq $0xfff, %rax            # imm = 0xFFF
cmpq $0x0, %rax
je 0xffffffff801101d6
leaq 0x1fcb(%rip), %rdi      # 0xffffffff80112179
leaq 0x2d8b(%rip), %rsi      # 0xffffffff80112f40
movl $0x19d, %edx            # imm = 0x19D
leaq 0x1fbc(%rip), %rcx      # 0xffffffff8011217d
leaq 0x2d7d(%rip), %r8       # 0xffffffff80112f45
movb $0x0, %al
callq 0xffffffff80101e60
callq 0xffffffff80111cd0
jmp 0xffffffff801101d4
jmp 0xffffffff801101d8
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0xc, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xffffffff8010fdc0
movq %rax, %rsi
movq -0x20(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0xffffffff80105050
movq %rax, -0x70(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x70(%rbp)
movb %al, -0xa1(%rbp)
je 0xffffffff80110238
movq -0x70(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x28(%rbp), %rax
setb %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0xffffffff80110247
jmp 0xffffffff80110364
jmp 0xffffffff80110249
cmpl $0x0, -0x68(%rbp)
je 0xffffffff8011027e
leaq 0x1f23(%rip), %rdi      # 0xffffffff80112179
leaq 0x2ce3(%rip), %rsi      # 0xffffffff80112f40
movl $0x1a5, %edx            # imm = 0x1A5
leaq 0x1f14(%rip), %rcx      # 0xffffffff8011217d
leaq 0x2ced(%rip), %r8       # 0xffffffff80112f5d
movb $0x0, %al
callq 0xffffffff80101e60
callq 0xffffffff80111cd0
jmp 0xffffffff8011027c
jmp 0xffffffff80110280
jmp 0xffffffff80110282
movslq -0x68(%rbp), %rax
cmpq $0x0, -0x60(%rbp,%rax,8)
jne 0xffffffff801102bd
leaq 0x1ee4(%rip), %rdi      # 0xffffffff80112179
leaq 0x2ca4(%rip), %rsi      # 0xffffffff80112f40
movl $0x1a6, %edx            # imm = 0x1A6
leaq 0x1ed5(%rip), %rcx      # 0xffffffff8011217d
leaq 0x2cbe(%rip), %r8       # 0xffffffff80112f6d
movb $0x0, %al
callq 0xffffffff80101e60
callq 0xffffffff80111cd0
jmp 0xffffffff801102bb
jmp 0xffffffff801102bf
movslq -0x68(%rbp), %rax
movl -0x40(%rbp,%rax,4), %eax
movl %eax, -0x74(%rbp)
movslq -0x68(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movslq -0x74(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movslq -0x74(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movq -0x88(%rbp), %rdi
callq 0xffffffff80110ab0
testb $0x1, %al
jne 0xffffffff8011030c
jmp 0xffffffff80110350
movq -0x88(%rbp), %rdi
callq 0xffffffff80110ad0
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
shrq $0xc, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0xffffffff80103ce0
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
callq 0xffffffff80110af0
jmp 0xffffffff80110352
movq -0x70(%rbp), %rdi
callq 0xffffffff80105320
movq %rax, -0x70(%rbp)
jmp 0xffffffff80110214
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)