// File: /workspace/github_cpp_makefile_star2_O2/jansucan[P]diff-dd/src/create.cpp
// Function: DiffFinder::findNextDiff()
Diff findNextDiff()
    {
        for (;;) {
            if (m_search_state == SearchState::ReadPages) {
                m_old_page = m_old_page_reader.getNextPage();
                m_new_page = m_new_page_reader.getNextPage();
                assert(m_old_page.getStart() == m_new_page.getStart());

                if (m_old_page.getSize() != m_new_page.getSize()) {
                    throw CreateError(
                        "cannot read the same amount of data from both files");
                }

                const bool end_of_stream{m_old_page.isEmpty() &&
                                         m_new_page.isEmpty()};
                if (end_of_stream) {
                    const Diff return_diff{m_diff};
                    m_diff = Diff{m_offset_in_stream};
                    return return_diff;
                }

                m_search_state = SearchState::FindDiff;

            } else if (m_search_state == SearchState::FindDiff) {
                Diff diff{findDiffInPages(m_old_page, m_new_page,
                                          m_offset_in_stream)};
                m_offset_in_stream = diff.getEnd();

                if (diff.isEmpty()) {
                    // End of pages. On the next call, read new pages.
                    m_old_page = Page{};
                    m_new_page = Page{};
                    m_search_state = SearchState::ReadPages;
                }

                const MergeState merge_state{diffsTryMerge(
                    m_diff, diff, m_max_merge_gap, m_diff_max_size)};

                if (merge_state == MergeState::Finished) {
                    const Diff return_diff{m_diff};
                    m_diff = diff;
                    if (!return_diff.isEmpty()) {
                        return return_diff;
                    }
                }

            } else {
                assert(false);
            }
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
leaq 0xd0(%rsi), %rbp
leaq 0xf0(%rsi), %r12
leaq 0x118(%rsi), %rax
movq %rax, (%rsp)
leaq 0x60(%rsi), %rax
movq %rax, 0x38(%rsp)
leaq 0x40(%rsp), %r13
movl 0x168(%r15), %eax
cmpl $0x1, %eax
je 0x4b83
testl %eax, %eax
jne 0x4d0e
movq %r13, %rdi
movq %r15, %rsi
callq 0x51d8
movq %rbp, %rdi
movq %r13, %rsi
callq 0x5250
leaq 0x48(%rsp), %rdi
callq 0x3ed0
movq %r13, %rdi
movq 0x38(%rsp), %rsi
callq 0x51d8
movq %r12, %rdi
movq %r13, %rsi
callq 0x5250
leaq 0x48(%rsp), %rdi
callq 0x3ed0
movq 0xe0(%r15), %rax
cmpq 0x100(%r15), %rax
jne 0x4d2d
movq 0xe8(%r15), %rcx
cmpq 0x108(%r15), %rcx
jne 0x4d4c
cmpq %rax, %rcx
je 0x4ca1
movl $0x1, 0x168(%r15)
jmp 0x4ae8
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x5424
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x5424
movq 0x110(%r15), %r8
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x52ce
leaq 0xa0(%rsp), %rdi
callq 0x3ed0
leaq 0xc0(%rsp), %rdi
callq 0x3ed0
movq 0x88(%rsp), %rax
movq %rax, 0x110(%r15)
cmpq 0x80(%rsp), %rax
jne 0x4c45
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x5250
leaq 0x18(%rsp), %rdi
callq 0x3ed0
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5250
leaq 0x18(%rsp), %rdi
callq 0x3ed0
andl $0x0, 0x168(%r15)
movq 0xc0(%r15), %rcx
movq 0xc8(%r15), %rdx
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x4352
testl %eax, %eax
jne 0x4c94
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq (%rsp), %r14
movq %r14, %rsi
callq 0x528a
movq %r14, %rdi
movq %r13, %rsi
callq 0x5444
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rax
jne 0x4cef
movq %rbx, %rdi
callq 0x580c
movq %r13, %rdi
callq 0x580c
jmp 0x4ae8
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq (%rsp), %r14
movq %r14, %rsi
callq 0x528a
movq 0x110(%r15), %rax
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %r15
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movq %rax, 0x40(%r15)
movq %rax, 0x48(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x52aa
movq %r15, %rdi
jmp 0x4cf4
leaq 0x40(%rsp), %rdi
callq 0x580c
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3808(%rip), %rdi      # 0x851d
leaq 0x3635(%rip), %rsi      # 0x8351
leaq 0x37a6(%rip), %rcx      # 0x84c9
movl $0x121, %edx            # imm = 0x121
callq 0x3160
leaq 0x3766(%rip), %rdi      # 0x849a
leaq 0x3616(%rip), %rsi      # 0x8351
leaq 0x3787(%rip), %rcx      # 0x84c9
movl $0xf8, %edx
callq 0x3160
pushq $0x10
popq %rdi
callq 0x3130
movq %rax, %rbx
leaq 0x378b(%rip), %rsi      # 0x84e9
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3e0e
movb $0x1, %bpl
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x5274
xorl %ebp, %ebp
leaq 0x7eda(%rip), %rsi      # 0xcc60
movq 0x8223(%rip), %rdx      # 0xcfb0
movq %rbx, %rdi
callq 0x3330
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x3398
testb %bpl, %bpl
jne 0x4dac
jmp 0x4de2
movq %rax, %r14
movq %rbx, %rdi
callq 0x3180
jmp 0x4de2
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x580c
jmp 0x4de2
movq %rax, %r14
leaq 0xa0(%rsp), %rdi
callq 0x3ed0
leaq 0xc0(%rsp), %rdi
callq 0x3ed0
movq %r14, %rdi
callq 0x3340