// File: /workspace/github_cpp_makefile_star2_O1/jansucan[P]diff-dd/src/create.cpp
// Function: create(Options::Create const&)
void
create(const Options::Create &opts)
{
    std::ifstream in_istream{opts.getInFilePath(),
                             std::ifstream::in | std::ifstream::binary};
    if (!in_istream) {
        throw BufferedStream::Error("cannot open input file");
    }

    std::ifstream base_istream{opts.getBaseFilePath(),
                               std::ifstream::in | std::ifstream::binary};
    if (!base_istream) {
        throw BufferedStream::Error("cannot open base file");
    }

    // When backing up, the output file is truncated to hold the new data
    std::ofstream out_ostream{opts.getOutFilePath(), std::ofstream::out |
                                                         std::ofstream::trunc |
                                                         std::ofstream::binary};
    if (!out_ostream) {
        throw BufferedStream::Error("cannot open output file");
    }

    DiffFinder diff_finder(base_istream, in_istream, opts.getBufferSize(),
                           FormatV2::RecordHeaderSize);
    FormatV2::Writer diff_writer(out_ostream, opts.getBufferSize());

    for (;;) {
        const Diff diff{diff_finder.findNextDiff()};
        if (diff.isEmpty()) {
            break;
        }

        diff_writer.writeDiffRecord(diff.getStart(), diff.getSize(),
                                    diff.getData());

        // Here, the diff is destructed and page data reference counters
        // decremented
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x818, %rsp            # imm = 0x818
movq %rdi, %rbx
leaq 0x408(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x61dc
movq (%r14), %rsi
leaq 0x610(%rsp), %rdi
movl $0xc, %edx
callq 0x3390
leaq 0x408(%rsp), %rdi
callq 0x4bb2
movq 0x610(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x630(%rsp,%rax)
jne 0x488d
leaq 0x208(%rsp), %rdi
movq %rbx, %rsi
callq 0x61ee
movq 0x208(%rsp), %rsi
leaq 0x408(%rsp), %rdi
movl $0xc, %edx
callq 0x3390
leaq 0x208(%rsp), %rdi
callq 0x4bb2
movq 0x408(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x428(%rsp,%rax)
jne 0x48fb
leaq 0x98(%rsp), %rdi
movq %rbx, %rsi
callq 0x6200
movq 0x98(%rsp), %rsi
leaq 0x208(%rsp), %rdi
movl $0x34, %edx
callq 0x3260
leaq 0x98(%rsp), %rdi
callq 0x4bb2
movq 0x208(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x228(%rsp,%rax)
jne 0x4966
movq %rbx, %rdi
callq 0x61d8
leaq 0x98(%rsp), %rdi
leaq 0x408(%rsp), %rsi
leaq 0x610(%rsp), %rdx
movl $0xc, %r8d
movl %eax, %ecx
callq 0x4bea
movq %rbx, %rdi
callq 0x61d8
movl %eax, %edx
leaq 0x8(%rsp), %rdi
leaq 0x208(%rsp), %rsi
callq 0x4c8e
leaq 0x48(%rsp), %rbx
leaq 0x98(%rsp), %r14
leaq 0x30(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4cbe
movq 0x88(%rsp), %r13
movq 0x90(%rsp), %r12
movq %r12, %rbp
subq %r13, %rbp
je 0x4788
movq %r15, %rdi
movq %rbx, %rsi
callq 0x53ee
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x532e
movq %r15, %rdi
callq 0x5726
movl $0x28, %ebp
movq 0x48(%rsp,%rbp), %rdi
testq %rdi, %rdi
je 0x479c
callq 0x413a
addq $-0x20, %rbp
cmpq $-0x18, %rbp
jne 0x478d
cmpq %r13, %r12
jne 0x473f
leaq 0x8(%rsp), %rdi
callq 0x3e62
movl $0x140, %ebx            # imm = 0x140
movq 0x98(%rsp,%rbx), %rdi
testq %rdi, %rdi
je 0x47cc
callq 0x413a
addq $-0x20, %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0x47ba
movq 0x190(%rsp), %rdi
testq %rdi, %rdi
je 0x47eb
callq 0x413a
movq 0x170(%rsp), %rdi
testq %rdi, %rdi
je 0x47fd
callq 0x413a
leaq 0x72fc(%rip), %r14      # 0xbb00
leaq 0x120(%rsp), %rbx
movq %r14, -0x20(%rbx)
movq %rbx, %rdi
callq 0x40b8
movq %r14, -0x80(%rbx)
leaq 0xc0(%rsp), %rdi
callq 0x40b8
movq 0x7778(%rip), %rax      # 0xbfa8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x210(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x208(%rsp,%rcx)
callq 0x31d0
leaq 0x300(%rsp), %rdi
callq 0x30d0
leaq 0x408(%rsp), %rdi
callq 0x3080
leaq 0x610(%rsp), %rdi
callq 0x3080
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x3130
movq %rax, %r14
leaq 0x418(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3bb3(%rip), %rsi      # 0x8460
leaq 0x3bc2(%rip), %rdx      # 0x8476
leaq 0x408(%rsp), %rdi
callq 0x41c2
movb $0x1, %bpl
leaq 0x408(%rsp), %rsi
movq %r14, %rdi
callq 0x32d0
leaq 0x72b5(%rip), %rax      # 0xbb90
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x7241(%rip), %rsi      # 0xbb28
movq 0x76c2(%rip), %rdx      # 0xbfb0
movq %r14, %rdi
callq 0x3360
jmp 0x49cf
movl $0x10, %edi
callq 0x3130
movq %rax, %r14
leaq 0x218(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3b5c(%rip), %rsi      # 0x8477
leaq 0x3b6a(%rip), %rdx      # 0x848c
leaq 0x208(%rsp), %rdi
callq 0x41c2
movb $0x1, %bpl
leaq 0x208(%rsp), %rsi
movq %r14, %rdi
callq 0x32d0
leaq 0x7247(%rip), %rax      # 0xbb90
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x71d3(%rip), %rsi      # 0xbb28
movq 0x7654(%rip), %rdx      # 0xbfb0
movq %r14, %rdi
callq 0x3360
jmp 0x49cf
movl $0x10, %edi
callq 0x3130
movq %rax, %r14
leaq 0xa8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3b07(%rip), %rsi      # 0x848d
leaq 0x3b17(%rip), %rdx      # 0x84a4
leaq 0x98(%rsp), %rdi
callq 0x41c2
movb $0x1, %bpl
leaq 0x98(%rsp), %rsi
movq %r14, %rdi
callq 0x32d0
leaq 0x71dc(%rip), %rax      # 0xbb90
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x7168(%rip), %rsi      # 0xbb28
movq 0x75e9(%rip), %rdx      # 0xbfb0
movq %r14, %rdi
callq 0x3360
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0x49f7
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3240
jmp 0x49f7
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x4b2c
movq %r14, %rdi
callq 0x3190
jmp 0x4b2c
movq %rax, %rbx
movq 0x208(%rsp), %rdi
cmpq %r15, %rdi
je 0x4a35
movq 0x218(%rsp), %rsi
incq %rsi
callq 0x3240
jmp 0x4a35
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x4b39
movq %r14, %rdi
callq 0x3190
jmp 0x4b39
movq %rax, %rbx
movq 0x408(%rsp), %rdi
cmpq %r15, %rdi
je 0x4a73
movq 0x418(%rsp), %rsi
incq %rsi
callq 0x3240
jmp 0x4a73
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x4b46
movq %r14, %rdi
callq 0x3190
jmp 0x4b46
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x4bb2
jmp 0x4b39
movq %rax, %rbx
jmp 0x4b39
movq %rax, %rbx
leaq 0x208(%rsp), %rdi
callq 0x4bb2
jmp 0x4b46
movq %rax, %rbx
jmp 0x4b46
movq %rax, %rbx
leaq 0x408(%rsp), %rdi
callq 0x4bb2
jmp 0x4b53
movq %rax, %rbx
jmp 0x4b1f
movq %rax, %rbx
jmp 0x4b2c
movq %rax, %rbx
jmp 0x4af1
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5726
movl $0x28, %r14d
movq 0x48(%rsp,%r14), %rdi
testq %rdi, %rdi
je 0x4b06
callq 0x413a
addq $-0x20, %r14
cmpq $-0x18, %r14
jne 0x4af7
jmp 0x4b15
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3e62
leaq 0x98(%rsp), %rdi
callq 0x576e
leaq 0x208(%rsp), %rdi
callq 0x3330
leaq 0x408(%rsp), %rdi
callq 0x3080
leaq 0x610(%rsp), %rdi
callq 0x3080
movq %rbx, %rdi
callq 0x3370
nop