// File: /workspace/github_cpp_makefile_star2_O3/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 $0xe8, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq %rdi, 0x88(%rsp)
leaq 0xe0(%rsi), %rax
movq %rax, 0x8(%rsp)
leaq 0x100(%rsi), %rax
movq %rax, 0x18(%rsp)
leaq 0x118(%rsi), %rax
movq %rax, 0x98(%rsp)
leaq 0x40(%rdi), %rax
movq %rax, 0x80(%rsp)
leaq 0x158(%rsi), %rax
movq %rax, 0x10(%rsp)
leaq 0x30(%rsp), %r13
leaq 0x60(%rsi), %rax
movq %rax, 0xa0(%rsp)
leaq 0x128(%rsi), %rbx
leaq 0x28(%rsp), %rbp
leaq 0x120(%rsi), %rax
movq %rax, 0x90(%rsp)
movq 0x726f(%rip), %rdx      # 0xbfc0
movq %rsi, 0x78(%rsp)
movl 0x168(%r14), %eax
cmpl $0x1, %eax
je 0x4dbe
testl %eax, %eax
jne 0x5258
movq %rdx, %r12
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x5858
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0xd8(%r14), %rdi
movups %xmm0, 0xd0(%r14)
testq %rdi, %rdi
je 0x4df6
callq 0x4130
movq 0x28(%rsp), %rdi
movups (%r13), %xmm0
movq 0x8(%rsp), %rax
movups %xmm0, (%rax)
testq %rdi, %rdi
je 0x4e03
callq 0x4130
jmp 0x4e03
movq 0xd0(%r14), %rax
movq %rax, 0xc8(%rsp)
movq 0xd8(%r14), %rax
movq %rax, 0xd0(%rsp)
testq %rax, %rax
je 0x4eb3
cmpb $0x0, (%rdx)
je 0x4eaf
incl 0x8(%rax)
jmp 0x4eb3
movups (%r13), %xmm0
movq 0x8(%rsp), %rax
movups %xmm0, (%rax)
leaq 0x20(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x5858
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0xf8(%r14), %rdi
movups %xmm0, 0xf0(%r14)
testq %rdi, %rdi
je 0x4e5a
callq 0x4130
movq 0x28(%rsp), %rdi
movups (%r13), %xmm0
movq 0x18(%rsp), %rbp
movups %xmm0, (%rbp)
testq %rdi, %rdi
je 0x4e68
callq 0x4130
jmp 0x4e68
movups (%r13), %xmm0
movq 0x18(%rsp), %rbp
movups %xmm0, (%rbp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
cmpq (%rbp), %rax
jne 0x5277
movq 0xe8(%r14), %rcx
cmpq 0x108(%r14), %rcx
leaq 0x28(%rsp), %rbp
jne 0x51fe
movq %r12, %rdx
cmpq %rax, %rcx
je 0x50ff
movl $0x1, 0x168(%r14)
jmp 0x4d56
lock
incl 0x8(%rax)
movq 0x8(%rsp), %rax
movups (%rax), %xmm0
leaq 0xd8(%rsp), %rax
movups %xmm0, (%rax)
movq 0xf0(%r14), %rax
movq %rax, 0xa8(%rsp)
movq 0xf8(%r14), %rax
movq %rax, 0xb0(%rsp)
testq %rax, %rax
je 0x4ef7
cmpb $0x0, (%rdx)
je 0x4ef3
incl 0x8(%rax)
jmp 0x4ef7
lock
incl 0x8(%rax)
movq 0x18(%rsp), %r12
movups (%r12), %xmm0
leaq 0xb8(%rsp), %rax
movups %xmm0, (%rax)
movq 0x110(%r14), %r8
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
leaq 0xc8(%rsp), %rdx
leaq 0xa8(%rsp), %rcx
callq 0x58fe
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x4f42
callq 0x4130
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x4f54
callq 0x4130
movq 0x68(%rsp), %rax
movq %rax, 0x110(%r14)
cmpq 0x60(%rsp), %rax
jne 0x4fba
movq 0xd8(%r14), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0xd0(%r14)
testq %rdi, %rdi
je 0x4f83
callq 0x4130
movq 0x8(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0xf8(%r14), %rdi
movups %xmm0, 0xf0(%r14)
testq %rdi, %rdi
je 0x4fa7
callq 0x4130
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movl $0x0, 0x168(%r14)
movq 0xc0(%r14), %rcx
movq 0xc8(%r14), %rdx
movq 0x98(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x435e
movb $0x1, %r12b
testl %eax, %eax
jne 0x50c2
xorl %eax, %eax
movq 0x6fd2(%rip), %rdx      # 0xbfc0
movq -0x10(%rbx,%rax), %rcx
movq %rcx, (%r15,%rax)
movq -0x8(%rbx,%rax), %rcx
movq %rcx, 0x8(%r15,%rax)
testq %rcx, %rcx
je 0x5014
cmpb $0x0, (%rdx)
je 0x5010
incl 0x8(%rcx)
jmp 0x5014
lock
incl 0x8(%rcx)
movups (%rbx,%rax), %xmm0
movups %xmm0, 0x10(%r15,%rax)
addq $0x20, %rax
cmpq $0x40, %rax
jne 0x4fee
movq 0x10(%rsp), %rax
movups (%rax), %xmm0
movq 0x80(%rsp), %rax
movups %xmm0, (%rax)
movq 0x90(%rsp), %r13
movq %rbp, %r14
xorl %ebp, %ebp
leaq 0x30(%rsp), %r12
movq 0x20(%rsp,%rbp), %rax
movq %rax, -0x10(%rbx,%rbp)
movq %r13, %rdi
addq %rbp, %rdi
leaq (%r14,%rbp), %rsi
callq 0x57d8
movups (%r12,%rbp), %xmm0
movups %xmm0, (%rbx,%rbp)
addq $0x20, %rbp
cmpq $0x40, %rbp
jne 0x504d
leaq 0x60(%rsp), %rax
movups (%rax), %xmm0
movq 0x10(%rsp), %rax
movups %xmm0, (%rax)
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rax
jne 0x50ba
movl $0x28, %ebp
movq 0x78(%rsp), %r14
movb $0x1, %r12b
movq (%r15,%rbp), %rdi
testq %rdi, %rdi
je 0x50ae
callq 0x4130
addq $-0x20, %rbp
cmpq $-0x18, %rbp
jne 0x50a0
jmp 0x50c2
xorl %r12d, %r12d
movq 0x78(%rsp), %r14
movl $0x28, %ebp
movq 0x20(%rsp,%rbp), %rdi
testq %rdi, %rdi
je 0x50d6
callq 0x4130
addq $-0x20, %rbp
cmpq $-0x18, %rbp
jne 0x50c7
testb %r12b, %r12b
movq 0x6ed6(%rip), %rdx      # 0xbfc0
leaq 0x30(%rsp), %r13
leaq 0x28(%rsp), %rbp
jne 0x4d56
jmp 0x51e4
addq $0x10, %r15
xorl %eax, %eax
movq -0x10(%rbx,%rax), %rcx
movq %rcx, -0x10(%r15,%rax)
movq -0x8(%rbx,%rax), %rcx
movq %rcx, -0x8(%r15,%rax)
testq %rcx, %rcx
je 0x512c
cmpb $0x0, (%rdx)
je 0x5128
incl 0x8(%rcx)
jmp 0x512c
lock
incl 0x8(%rcx)
movups (%rbx,%rax), %xmm0
movups %xmm0, (%r15,%rax)
addq $0x20, %rax
cmpq $0x40, %rax
jne 0x5105
movq 0x10(%rsp), %rax
movups (%rax), %xmm0
movq 0x80(%rsp), %rax
movups %xmm0, (%rax)
movq 0x110(%r14), %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq %rax, 0x60(%rsp)
movq %rax, 0x68(%rsp)
xorl %r14d, %r14d
movups 0x20(%rsp,%r14), %xmm0
xorps %xmm1, %xmm1
movups %xmm1, 0x20(%rsp,%r14)
movq -0x8(%rbx,%r14), %rdi
movups %xmm0, -0x10(%rbx,%r14)
testq %rdi, %rdi
je 0x51a1
callq 0x4130
movups 0x30(%rsp,%r14), %xmm0
movups %xmm0, (%rbx,%r14)
addq $0x20, %r14
cmpq $0x40, %r14
jne 0x517d
leaq 0x60(%rsp), %rax
movups (%rax), %xmm0
movq 0x10(%rsp), %rax
movups %xmm0, (%rax)
movl $0x28, %ebx
movq 0x20(%rsp,%rbx), %rdi
testq %rdi, %rdi
je 0x51da
callq 0x4130
addq $-0x20, %rbx
cmpq $-0x18, %rbx
jne 0x51cb
movq 0x88(%rsp), %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x3130
movq %rax, %r14
leaq 0x20(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x32eb(%rip), %rsi      # 0x8505
leaq 0x3317(%rip), %rdx      # 0x8538
callq 0x41b8
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x32d0
leaq 0x6a43(%rip), %rax      # 0xbc80
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x6a0f(%rip), %rsi      # 0xbc58
movq 0x6d60(%rip), %rdx      # 0xbfb0
movq %r14, %rdi
callq 0x3360
leaq 0x32da(%rip), %rdi      # 0x8539
leaq 0x3107(%rip), %rsi      # 0x836d
leaq 0x3278(%rip), %rcx      # 0x84e5
movl $0x121, %edx            # imm = 0x121
callq 0x3160
leaq 0x3238(%rip), %rdi      # 0x84b6
leaq 0x30e8(%rip), %rsi      # 0x836d
leaq 0x3259(%rip), %rcx      # 0x84e5
movl $0xf8, %edx
callq 0x3160
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x52b5
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3240
testb %bpl, %bpl
jne 0x52bf
jmp 0x5314
movq %rax, %rbx
movq %r14, %rdi
callq 0x3190
jmp 0x5314
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x52de
callq 0x4130
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x5314
callq 0x4130
jmp 0x5314
movq %rax, %rbx
movl $0x28, %r14d
movq 0x20(%rsp,%r14), %rdi
testq %rdi, %rdi
je 0x530a
callq 0x4130
addq $-0x20, %r14
cmpq $-0x18, %r14
jne 0x52fb
movq %rbx, %rdi
callq 0x3370