// File: /workspace/github_cpp_makefile_star2_O3/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 0x593e
movq 0x6695(%rip), %rax      # 0xbfc0
cmpb $0x0, (%rax)
je 0x5935
incl 0x8(%rdi)
jmp 0x5939
lock
incl 0x8(%rdi)
callq 0x4130
movq (%r14), %rbp
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x5964
movq 0x666f(%rip), %rax      # 0xbfc0
cmpb $0x0, (%rax)
je 0x595b
incl 0x8(%rdi)
jmp 0x595f
lock
incl 0x8(%rdi)
callq 0x4130
movq 0x10(%r14), %rax
subq %rax, %r15
jb 0x5a51
movq 0x18(%r12), %rdx
subq 0x10(%r12), %rdx
cmpq %rdx, %r15
jae 0x59a4
movb (%rbp,%r15), %sil
movb (%r13,%r15), %dil
cmpb %dil, %sil
jne 0x599a
incq %r15
cmpq %rdx, %r15
jb 0x5980
movq %rdx, %r15
xorl %ecx, %ecx
cmpb %dil, %sil
setne %cl
jmp 0x59a6
xorl %ecx, %ecx
addq %r15, %rcx
cmpq %rdx, %rcx
jae 0x59c5
movb (%rbp,%rcx), %sil
cmpb (%r13,%rcx), %sil
je 0x59c5
incq %rcx
cmpq %rdx, %rcx
jb 0x59ae
movq %rdx, %rcx
leaq (%r15,%rax), %rdx
cmpq %rcx, %r15
jne 0x59ea
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 0x5a3f
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 0x5a1c
movq 0x65b2(%rip), %rdi      # 0xbfc0
cmpb $0x0, (%rdi)
je 0x5a18
incl 0x8(%rax)
jmp 0x5a1c
lock
incl 0x8(%rax)
movups (%rsi), %xmm0
leaq 0x8(%rsp), %rsi
movups %xmm0, 0x10(%rsi)
movq %rbx, %rdi
callq 0x5af8
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5a3f
callq 0x4130
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2b1f(%rip), %rdi      # 0x8577
leaq 0x290e(%rip), %rsi      # 0x836d
leaq 0x2b39(%rip), %rcx      # 0x859f
movl $0x13a, %edx            # imm = 0x13A
callq 0x3160
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5a82
callq 0x4130
movq %rbx, %rdi
callq 0x3370