// File: /workspace/github_cpp_makefile_star2_O2/jansucan[P]diff-dd/src/create.cpp
// Function: DiffFinder::findDiffInPages(Page, Page, unsigned long)
Diff findDiffInPages(Page old_page, Page new_page,
                         uint64_t offset_in_stream)
    {
        const char *old_data{old_page.getData().get()};
        const char *new_data{new_page.getData().get()};
        const uint64_t data_size_bytes{old_page.getSize()};

        assert(offset_in_stream >= new_page.getStart());
        size_t offset_in_pages{offset_in_stream - new_page.getStart()};

        // Find offset of the first different byte
        for (; offset_in_pages < data_size_bytes; ++offset_in_pages) {
            if (new_data[offset_in_pages] != old_data[offset_in_pages]) {
                break;
            }
        }
        const size_t start_in_pages{offset_in_pages};

        if (offset_in_pages < data_size_bytes) {
            // Different byte found. Start searching for a same byte immediately
            // after.
            ++offset_in_pages;
        }

        // Find offset of the first same byte
        for (; offset_in_pages < data_size_bytes; ++offset_in_pages) {
            if (new_data[offset_in_pages] == old_data[offset_in_pages]) {
                break;
            }
        }
        const size_t end_in_pages{offset_in_pages};

        // In the case when no different byte is found, the end offset will be
        // the same as the start offset

        const uint64_t start_in_stream{new_page.getStart() + start_in_pages};
        const uint64_t end_in_stream{new_page.getStart() + end_in_pages};
        if (start_in_stream == end_in_stream) {
            return Diff{start_in_stream};
        } else {
            return Diff{new_page, start_in_stream, end_in_stream};
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r15
movq %rcx, %r14
movq %rdx, %r12
movq %rdi, %rbx
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movq %rdx, %rsi
callq 0x3f8e
movq (%r13), %rbp
leaq 0x10(%rsp), %rdi
callq 0x3ed0
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x3f8e
movq (%r13), %r13
leaq 0x10(%rsp), %rdi
callq 0x3ed0
movq 0x10(%r14), %rax
subq %rax, %r15
jb 0x53f0
movq 0x18(%r12), %rdx
subq 0x10(%r12), %rdx
cmpq %r15, %rdx
movq %r15, %rcx
cmovaq %rdx, %rcx
cmpq %rdx, %r15
jae 0x535e
movb (%r13,%r15), %sil
cmpb (%rbp,%r15), %sil
jne 0x535b
incq %r15
jmp 0x5345
movq %r15, %rcx
cmpq %rdx, %r15
movq %rcx, %rsi
adcq $0x0, %rsi
cmpq %rsi, %rdx
movq %rsi, %r15
cmovaq %rdx, %r15
cmpq %rdx, %rsi
jae 0x538b
movb (%r13,%rsi), %dil
cmpb (%rbp,%rsi), %dil
je 0x5388
incq %rsi
jmp 0x5372
movq %rsi, %r15
leaq (%rcx,%rax), %r12
cmpq %r15, %rcx
jne 0x53b0
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movq %r12, 0x40(%rbx)
movq %r12, 0x48(%rbx)
jmp 0x53de
addq %rax, %r15
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x5424
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x551e
leaq 0x20(%rsp), %rdi
callq 0x3ed0
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3164(%rip), %rdi      # 0x855b
leaq 0x2f53(%rip), %rsi      # 0x8351
leaq 0x317e(%rip), %rcx      # 0x8583
movl $0x13a, %edx            # imm = 0x13A
callq 0x3160
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3ed0
movq %rbx, %rdi
callq 0x3340