// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %r8, %r15
movq %rcx, %r14
movq %rdx, %r12
movq %rdi, %rbx
movq (%rdx), %r13
movq 0x8(%rdx), %rdi
testq %rdi, %rdi
je 0x5941
movq 0x6697(%rip), %rax      # 0xbfc0
cmpb $0x0, (%rax)
je 0x5933
incl 0x8(%rdi)
jmp 0x5937
lock
incl 0x8(%rdi)
testq %rdi, %rdi
je 0x5941
callq 0x413a
movq (%r14), %rbp
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x596c
movq 0x666c(%rip), %rax      # 0xbfc0
cmpb $0x0, (%rax)
je 0x595e
incl 0x8(%rdi)
jmp 0x5962
lock
incl 0x8(%rdi)
testq %rdi, %rdi
je 0x596c
callq 0x413a
movq 0x10(%r14), %rax
movq %r15, %rsi
subq %rax, %rsi
jb 0x5a71
movq 0x18(%r12), %rdx
subq 0x10(%r12), %rdx
cmpq %rdx, %rsi
setb %cl
jae 0x59c3
movb (%rbp,%rsi), %dil
cmpb (%r13,%rsi), %dil
jne 0x59c3
subq %rax, %r15
incq %r15
cmpq %rdx, %r15
setb %cl
jae 0x59c0
movb (%rbp,%r15), %dil
leaq 0x1(%r15), %rsi
cmpb (%r13,%r15), %dil
movq %rsi, %r15
je 0x59a0
decq %rsi
jmp 0x59c3
movq %rdx, %rsi
movzbl %cl, %ecx
addq %rsi, %rcx
cmpq %rdx, %rcx
jae 0x59e5
movb (%rbp,%rcx), %dil
cmpb (%r13,%rcx), %dil
je 0x59e5
incq %rcx
cmpq %rdx, %rcx
jb 0x59ce
movq %rdx, %rcx
leaq (%rsi,%rax), %rdx
cmpq %rcx, %rsi
jne 0x5a0a
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movq %rdx, 0x40(%rbx)
movq %rdx, 0x48(%rbx)
jmp 0x5a5f
leaq 0x10(%r14), %rsi
addq %rax, %rcx
movq (%r14), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x5a3c
movq 0x6592(%rip), %rdi      # 0xbfc0
cmpb $0x0, (%rdi)
je 0x5a38
incl 0x8(%rax)
jmp 0x5a3c
lock
incl 0x8(%rax)
movups (%rsi), %xmm0
leaq 0x8(%rsp), %rsi
movups %xmm0, 0x10(%rsi)
movq %rbx, %rdi
callq 0x5b18
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5a5f
callq 0x413a
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2aff(%rip), %rdi      # 0x8577
leaq 0x28ee(%rip), %rsi      # 0x836d
leaq 0x2b19(%rip), %rcx      # 0x859f
movl $0x13a, %edx            # imm = 0x13A
callq 0x3160
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5aa2
callq 0x413a
movq %rbx, %rdi
callq 0x3370