// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/paging.c
// Function: pt_iter_next
struct pt_iter *pt_iter_next(struct pt_iter *iter)
{
	int level = iter->level;
	int idx = iter->idx[level];

	while (idx == PT_SIZE - 1 && level != PT_MAX_LEVEL)
		idx = iter->idx[++level];

	if (idx == PT_SIZE - 1)
		return 0;

	pte_t pte = iter->pt[level][++idx];

	iter->idx[level] = idx;

	while (pte_present(pte) && level != 0 && !pte_large(pte)) {
		const phys_t paddr = pte_phys(pte);
		pte_t *pt = va(paddr);

		iter->idx[--level] = 0;
		iter->pt[level] = pt;
		pte = pt[0];
	}
	iter->level = level;

	while (level != 0) {
		iter->pt[--level] = 0;
		iter->idx[level] = 0;
	}
	iter->addr = pt_iter_addr(iter);

	return iter;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x28(%rax,%rcx,4), %eax
movl %eax, -0x18(%rbp)
movslq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpq $0x1ff, %rcx            # imm = 0x1FF
movb %al, -0x31(%rbp)
jne 0xffffffff80105360
cmpl $0x3, -0x14(%rbp)
setne %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0xffffffff80105369
jmp 0xffffffff80105382
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %ecx, %rcx
movl 0x28(%rax,%rcx,4), %eax
movl %eax, -0x18(%rbp)
jmp 0xffffffff80105344
movslq -0x18(%rbp), %rax
cmpq $0x1ff, %rax            # imm = 0x1FF
jne 0xffffffff8010539b
movq $0x0, -0x8(%rbp)
jmp 0xffffffff801054ad
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x18(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl %edx, 0x28(%rax,%rcx,4)
movq -0x20(%rbp), %rdi
callq 0xffffffff801051c0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x32(%rbp)
jne 0xffffffff801053e2
jmp 0xffffffff801053fb
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x32(%rbp)
je 0xffffffff801053fb
movq -0x20(%rbp), %rdi
callq 0xffffffff801051e0
xorb $-0x1, %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
testb $0x1, %al
jne 0xffffffff80105404
jmp 0xffffffff80105457
movq -0x20(%rbp), %rdi
callq 0xffffffff80105200
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0xffffffff80105220
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %ecx, %rcx
movl $0x0, 0x28(%rax,%rcx,4)
movq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0xffffffff801053cb
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x14(%rbp)
je 0xffffffff80105491
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %ecx, %rcx
movq $0x0, 0x8(%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl $0x0, 0x28(%rax,%rcx,4)
jmp 0xffffffff80105460
movq -0x10(%rbp), %rdi
callq 0xffffffff801052c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)