// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
leaq 0xe0(%rsi), %rax
movq %rax, 0x18(%rsp)
leaq 0x100(%rsi), %rax
movq %rax, 0x10(%rsp)
leaq 0x118(%rsi), %rax
movq %rax, 0x98(%rsp)
leaq 0x40(%rdi), %rax
movq %rax, 0x80(%rsp)
leaq 0x158(%rsi), %rax
movq %rax, 0x8(%rsp)
leaq 0x30(%rsp), %rbp
leaq 0x60(%rsi), %rax
movq %rax, 0xa0(%rsp)
leaq 0x128(%rsi), %r13
leaq 0x120(%rsi), %rax
movq %rax, 0x90(%rsp)
leaq 0x10(%rdi), %r15
movq 0x727a(%rip), %rdx      # 0xbfc0
movq %rsi, 0x78(%rsp)
movq %rdi, 0x88(%rsp)
movl 0x168(%r14), %eax
cmpl $0x1, %eax
je 0x4e6e
testl %eax, %eax
jne 0x5266
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x5860
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0xd8(%r14), %rdi
movups %xmm0, 0xd0(%r14)
testq %rdi, %rdi
je 0x4d9e
callq 0x413a
movups (%rbp), %xmm0
movq 0x18(%rsp), %rax
movups %xmm0, (%rax)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4db9
callq 0x413a
leaq 0x20(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x5860
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0xf8(%r14), %rdi
movups %xmm0, 0xf0(%r14)
testq %rdi, %rdi
je 0x4df1
callq 0x413a
movups (%rbp), %xmm0
movq 0x10(%rsp), %rax
movups %xmm0, (%rax)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4e0c
callq 0x413a
movq 0x18(%rsp), %rax
movq (%rax), %rcx
movq 0x10(%rsp), %rax
movq (%rax), %rax
cmpq %rax, %rcx
jne 0x5285
movq 0xe8(%r14), %rdx
movq 0x108(%r14), %rsi
movq %rdx, %rdi
subq %rcx, %rdi
movq %rsi, %r8
subq %rax, %r8
cmpq %r8, %rdi
jne 0x520c
xorq %rcx, %rdx
xorq %rax, %rsi
orq %rdx, %rsi
setne %r12b
movq 0x7164(%rip), %rdx      # 0xbfc0
je 0x4ea6
movl $0x1, 0x168(%r14)
jmp 0x4f92
movq 0xd0(%r14), %rax
movq %rax, 0xc8(%rsp)
movq 0xd8(%r14), %rax
movq %rax, 0xd0(%rsp)
testq %rax, %rax
je 0x4fa4
cmpb $0x0, (%rdx)
je 0x4fa0
incl 0x8(%rax)
jmp 0x4fa4
xorl %eax, %eax
movq -0x10(%r13,%rax), %rcx
movq %rcx, -0x10(%r15,%rax)
movq -0x8(%r13,%rax), %rcx
movq %rcx, -0x8(%r15,%rax)
testq %rcx, %rcx
je 0x4ecf
cmpb $0x0, (%rdx)
je 0x4ecb
incl 0x8(%rcx)
jmp 0x4ecf
lock
incl 0x8(%rcx)
movups (%r13,%rax), %xmm0
movups %xmm0, (%r15,%rax)
addq $0x20, %rax
cmpq $0x40, %rax
jne 0x4ea8
movq 0x8(%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 %ebp, %ebp
movups 0x20(%rsp,%rbp), %xmm0
xorps %xmm1, %xmm1
movups %xmm1, 0x20(%rsp,%rbp)
movq -0x8(%r13,%rbp), %rdi
movups %xmm0, -0x10(%r13,%rbp)
testq %rdi, %rdi
je 0x4f43
callq 0x413a
movups 0x30(%rsp,%rbp), %xmm0
movups %xmm0, (%r13,%rbp)
addq $0x20, %rbp
cmpq $0x40, %rbp
jne 0x4f21
leaq 0x60(%rsp), %rax
movups (%rax), %xmm0
movq 0x8(%rsp), %rax
movups %xmm0, (%rax)
movl $0x28, %ebp
movq 0x20(%rsp,%rbp), %rdi
testq %rdi, %rdi
je 0x4f7c
callq 0x413a
addq $-0x20, %rbp
cmpq $-0x18, %rbp
jne 0x4f6d
leaq 0x30(%rsp), %rbp
movq 0x702e(%rip), %rdx      # 0xbfc0
testb %r12b, %r12b
jne 0x4d53
jmp 0x51f7
lock
incl 0x8(%rax)
movq 0x18(%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 0x4fe8
cmpb $0x0, (%rdx)
je 0x4fe4
incl 0x8(%rax)
jmp 0x4fe8
lock
incl 0x8(%rax)
movq 0x10(%rsp), %rax
movups (%rax), %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 0x58fc
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x5031
callq 0x413a
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x5043
callq 0x413a
movq 0x68(%rsp), %rax
movq %rax, 0x110(%r14)
cmpq 0x60(%rsp), %rax
jne 0x50ac
movq 0xd8(%r14), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0xd0(%r14)
testq %rdi, %rdi
je 0x5072
callq 0x413a
movq 0x18(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0xf8(%r14), %rdi
movups %xmm0, 0xf0(%r14)
testq %rdi, %rdi
je 0x5096
callq 0x413a
movq 0x10(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0x0, 0x168(%r14)
movq 0xc0(%r14), %rcx
movq 0xc8(%r14), %rdx
movq 0x98(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x4372
movb $0x1, %cl
movl %ecx, 0x4(%rsp)
testl %eax, %eax
jne 0x51c2
xorl %eax, %eax
movq 0x6edd(%rip), %rdx      # 0xbfc0
movq -0x10(%r13,%rax), %rcx
movq %rcx, (%rbx,%rax)
movq -0x8(%r13,%rax), %rcx
movq %rcx, 0x8(%rbx,%rax)
testq %rcx, %rcx
je 0x5109
cmpb $0x0, (%rdx)
je 0x5105
incl 0x8(%rcx)
jmp 0x5109
lock
incl 0x8(%rcx)
movups (%r13,%rax), %xmm0
movups %xmm0, 0x10(%rbx,%rax)
addq $0x20, %rax
cmpq $0x40, %rax
jne 0x50e3
movq 0x8(%rsp), %rax
movups (%rax), %xmm0
movq 0x80(%rsp), %rax
movups %xmm0, (%rax)
movq %rbp, %r12
xorl %ebp, %ebp
leaq 0x28(%rsp), %r14
movq 0x90(%rsp), %rbx
movq 0x20(%rsp,%rbp), %rax
movq %rax, -0x10(%r13,%rbp)
leaq (%rbx,%rbp), %rdi
leaq (%r14,%rbp), %rsi
callq 0x57e4
movups (%r12,%rbp), %xmm0
movups %xmm0, (%r13,%rbp)
addq $0x20, %rbp
cmpq $0x40, %rbp
jne 0x5143
leaq 0x60(%rsp), %rax
movups (%rax), %xmm0
movq 0x8(%rsp), %rax
movups %xmm0, (%rax)
movq 0x88(%rsp), %rbx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rax
jne 0x51b5
movl $0x28, %ebp
movq 0x78(%rsp), %r14
movq (%rbx,%rbp), %rdi
testq %rdi, %rdi
je 0x51a9
callq 0x413a
addq $-0x20, %rbp
cmpq $-0x18, %rbp
jne 0x519b
jmp 0x51c2
movl $0x0, 0x4(%rsp)
movq 0x78(%rsp), %r14
movl $0x28, %ebp
movq 0x20(%rsp,%rbp), %rdi
testq %rdi, %rdi
je 0x51d6
callq 0x413a
addq $-0x20, %rbp
cmpq $-0x18, %rbp
jne 0x51c7
cmpb $0x0, 0x4(%rsp)
leaq 0x30(%rsp), %rbp
movq 0x6dcf(%rip), %rdx      # 0xbfc0
jne 0x4d53
movq %rbx, %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 %rbp, (%rdi)
leaq 0x32dd(%rip), %rsi      # 0x8505
leaq 0x3309(%rip), %rdx      # 0x8538
callq 0x41c2
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x32d0
leaq 0x6a35(%rip), %rax      # 0xbc80
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x6a01(%rip), %rsi      # 0xbc58
movq 0x6d52(%rip), %rdx      # 0xbfb0
movq %r14, %rdi
callq 0x3360
leaq 0x32cc(%rip), %rdi      # 0x8539
leaq 0x30f9(%rip), %rsi      # 0x836d
leaq 0x326a(%rip), %rcx      # 0x84e5
movl $0x121, %edx            # imm = 0x121
callq 0x3160
leaq 0x322a(%rip), %rdi      # 0x84b6
leaq 0x30da(%rip), %rsi      # 0x836d
leaq 0x324b(%rip), %rcx      # 0x84e5
movl $0xf8, %edx
callq 0x3160
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x52cb
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3240
jmp 0x52cb
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x5325
movq %r14, %rdi
callq 0x3190
jmp 0x5325
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x52ef
callq 0x413a
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x5325
callq 0x413a
jmp 0x5325
movq %rax, %rbx
movl $0x28, %r14d
movq 0x20(%rsp,%r14), %rdi
testq %rdi, %rdi
je 0x531b
callq 0x413a
addq $-0x20, %r14
cmpq $-0x18, %r14
jne 0x530c
movq %rbx, %rdi
callq 0x3370
nop