// File: /workspace/github_cpp_makefile_star2_O1/ivan-tkatchev[P]makerpm/makerpm.cc
// Function: create_cpio(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, rpmprops_t&)
void create_cpio(const std::string& archive_name, const std::string& prefix,
                 std::vector<std::string>& files, rpmprops_t& props) {

    // RPM wants files to be in sorted order.
    std::sort(files.begin(), files.end());


    struct archive* a;
    struct archive* adisk;
    int r;

    a = ::archive_write_new();
    if (a == NULL) {
        throw std::runtime_error("Could not allocate archive struct.");
    }
    
    adisk = ::archive_read_disk_new();
    if (adisk == NULL ) {
        throw std::runtime_error("Could not allocate archive struct.");
    }

    ::archive_read_disk_set_symlink_physical(adisk);
    ::archive_read_disk_set_standard_lookup(adisk);

    r = ::archive_write_set_format_cpio_newc(a);
    if (r != ARCHIVE_OK) {
        throw std::runtime_error("Could not set archive format: " + std::string(::archive_error_string(a)));
    }

    r = ::archive_write_open_filename(a, archive_name.c_str());
    if (r != ARCHIVE_OK) {
        throw std::runtime_error("Could not open archive for writing: " + archive_name + ::archive_error_string(a));
    }

    for (const std::string& f : files) {

        struct archive_entry* entry;

        entry = ::archive_entry_new();

        if (entry == NULL) {
            throw std::runtime_error("Could not allocate archive entry struct.");
        }

        ::archive_entry_copy_sourcepath(entry, f.c_str());

        r = ::archive_read_disk_entry_from_file(adisk, entry, -1, NULL);        

        if (r != ARCHIVE_OK) {
            throw std::runtime_error("Could not read file: " + f + ::archive_error_string(a));
        }

        std::string pathname = f;

        if (pathname == prefix) {
            pathname = "/";

        } else if (pathname.size() > prefix.size() && 
                   pathname.compare(0, prefix.size(), prefix) == 0) {

            pathname = pathname.substr(prefix.size());
        }

        if (pathname.size() == 0) {
            throw std::runtime_error("Invalid empty pathname.");
        }

        if (pathname[0] == '/') {
            pathname = "." + pathname;

        } else if (pathname.size() < 2 ||
                   pathname[0] != '.' || pathname[1] != '/') {

            pathname = "./" + pathname;
        }

        ::archive_entry_copy_pathname(entry, pathname.c_str());

        if (::archive_entry_filetype(entry) != AE_IFREG) {
            ::archive_entry_set_size(entry, 0);
        }

        r = ::archive_write_header(a, entry);

        if (r != ARCHIVE_OK) {
            throw std::runtime_error("Could not write file to archive: " + f + ::archive_error_string(a));
        }

        if (::archive_entry_size(entry) != 0) {

            mfile mf(f);

            ssize_t res = ::archive_write_data(a, mf.addr, mf.size);

            if (res != (ssize_t)mf.size) {
                throw std::runtime_error("Could not write file to archive: " + f);
            }

            add_to_rpmprops(entry, &mf, props);

        } else {

            add_to_rpmprops(entry, nullptr, props);
        }

        ::archive_entry_free(entry);
    }

    if (::archive_write_close(a)) {
        throw std::runtime_error("Could not close archive: " + std::string(::archive_error_string(a)));
    }

    if (::archive_read_free(adisk)) {
        throw std::runtime_error("Could not close archive: " + std::string(::archive_error_string(a)));
    }

    ::archive_write_free(a);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, 0x70(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r13
movq (%rdx), %rbx
movq 0x8(%rdx), %r12
cmpq %r12, %rbx
je 0x111e7
movq %r12, %rax
subq %rbx, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x14b8f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x14c73
callq 0x3390
testq %rax, %rax
je 0x11703
movq %rax, %rbx
callq 0x3330
testq %rax, %rax
je 0x11724
movq %rax, %r12
movq %rax, %rdi
callq 0x3560
movq %r12, %rdi
callq 0x3040
movq %rbx, %rdi
callq 0x3320
testl %eax, %eax
jne 0x11745
movq %r12, 0x78(%rsp)
movq (%r13), %rsi
movq %rbx, 0x48(%rsp)
movq %rbx, %rdi
callq 0x34c0
testl %eax, %eax
jne 0x117af
movq (%r14), %r13
movq 0x8(%r14), %rax
movq %rax, 0x80(%rsp)
cmpq %rax, %r13
je 0x1149f
leaq 0x28(%rsp), %rbp
callq 0x33d0
testq %rax, %rax
je 0x115aa
movq %rax, %r14
movq (%r13), %rsi
movq %rax, %rdi
callq 0x3420
movq 0x78(%rsp), %rdi
movq %r14, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
callq 0x3630
testl %eax, %eax
jne 0x114e0
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x1392a
movq 0x30(%rsp), %r12
movq 0x8(%r15), %rbx
cmpq %rbx, %r12
jne 0x112e1
testq %r12, %r12
je 0x11336
movq (%r15), %rsi
movq 0x28(%rsp), %rdi
movq %r12, %rdx
callq 0x33c0
testl %eax, %eax
je 0x11336
cmpq %rbx, %r12
jbe 0x11350
movq %rbp, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x3610
testl %eax, %eax
jne 0x11350
movq 0x8(%r15), %rdx
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq $-0x1, %rcx
callq 0x35a0
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x32e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11350
callq 0x32f0
jmp 0x11350
movl $0x1, %r8d
movq %rbp, %rdi
xorl %esi, %esi
movq %r12, %rdx
leaq 0x85b3(%rip), %rcx      # 0x198fe
callq 0x32d0
movq 0x30(%rsp), %rcx
testq %rcx, %rcx
je 0x115dc
movq 0x28(%rsp), %rax
movb (%rax), %dl
cmpb $0x2f, %dl
jne 0x11383
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x8417(%rip), %rsi      # 0x19790
movq %rbp, %rdx
callq 0x12b16
jmp 0x113b1
cmpq $0x1, %rcx
sete %cl
cmpb $0x2e, %dl
setne %dl
orb %cl, %dl
jne 0x1139a
cmpb $0x2f, 0x1(%rax)
je 0x113d0
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x8554(%rip), %rsi      # 0x198fd
movq %rbp, %rdx
callq 0x12b16
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x32e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x113d0
callq 0x32f0
movq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x3470
movq %r14, %rdi
callq 0x33f0
cmpl $0x8000, %eax           # imm = 0x8000
je 0x113f6
movq %r14, %rdi
xorl %esi, %esi
callq 0x3440
movq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x3230
testl %eax, %eax
jne 0x11545
movq %r14, %rdi
callq 0x3640
testq %rax, %rax
je 0x11462
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x12b98
movq 0x50(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x48(%rsp), %rdi
callq 0x31d0
cmpq 0x60(%rsp), %rax
jne 0x11613
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x10dbd
leaq 0x50(%rsp), %rdi
callq 0x12d74
jmp 0x11471
movq %r14, %rdi
xorl %esi, %esi
movq 0x70(%rsp), %rdx
callq 0x10dbd
movq %r14, %rdi
callq 0x3680
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1148d
callq 0x32f0
addq $0x20, %r13
cmpq 0x80(%rsp), %r13
jne 0x11264
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x30c0
testl %eax, %eax
jne 0x1180f
movq 0x78(%rsp), %rdi
callq 0x30e0
testl %eax, %eax
jne 0x11879
movq %rbx, %rdi
callq 0x35f0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x83db(%rip), %rsi      # 0x198cf
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
callq 0x12b16
movq 0x48(%rsp), %rdi
callq 0x33e0
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x3380
leaq 0x38(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x11661
movups (%rcx), %xmm0
leaq 0x38(%rsp), %rdx
movups %xmm0, (%rdx)
jmp 0x1166e
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x83a7(%rip), %rsi      # 0x19900
leaq 0x50(%rsp), %rdi
movq %r13, %rdx
callq 0x12b16
movq 0x48(%rsp), %rdi
callq 0x33e0
leaq 0x50(%rsp), %rdi
movq %rax, %rsi
callq 0x3380
leaq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x116b2
movups (%rcx), %xmm0
leaq 0x18(%rsp), %rdx
movups %xmm0, (%rdx)
jmp 0x116bf
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x82e8(%rip), %rsi      # 0x198a6
movq %rax, %rdi
callq 0x3190
movq 0xba1b(%rip), %rsi      # 0x1cfe8
movq 0xba0c(%rip), %rdx      # 0x1cfe0
movq %r14, %rdi
callq 0x3360
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x82f5(%rip), %rsi      # 0x198e5
movq %rax, %rdi
callq 0x3190
movq 0xb9e9(%rip), %rsi      # 0x1cfe8
movq 0xb9da(%rip), %rdx      # 0x1cfe0
movq %r14, %rdi
callq 0x3360
jmp 0x1192c
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x82d9(%rip), %rsi      # 0x19900
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
callq 0x12b16
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xb99b(%rip), %rsi      # 0x1cfe8
movq 0xb98c(%rip), %rdx      # 0x1cfe0
movq %r14, %rdi
callq 0x3360
jmp 0x1192c
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
movq 0x8(%rax), %rdx
leaq 0x28(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movb $0x1, %bpl
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xb94a(%rip), %rsi      # 0x1cfe8
movq 0xb93b(%rip), %rdx      # 0x1cfe0
movq %r14, %rdi
callq 0x3360
jmp 0x1192c
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
movq 0x8(%rax), %rdx
leaq 0x8(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movb $0x1, %bpl
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xb8f9(%rip), %rsi      # 0x1cfe8
movq 0xb8ea(%rip), %rdx      # 0x1cfe0
movq %r14, %rdi
callq 0x3360
jmp 0x1192c
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x8128(%rip), %rsi      # 0x1983f
movq %rax, %rdi
callq 0x3190
jmp 0x115c6
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x8107(%rip), %rsi      # 0x1983f
movq %rax, %rdi
callq 0x3190
jmp 0x115c6
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
movq %rbx, %rdi
callq 0x33e0
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %rax, %rsi
callq 0x3590
leaq 0x80ef(%rip), %rsi      # 0x19862
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x123ae
movb $0x1, %bpl
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xb84d(%rip), %rsi      # 0x1cfe8
movq 0xb83e(%rip), %rdx      # 0x1cfe0
movq %r14, %rdi
callq 0x3360
jmp 0x1192c
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x80be(%rip), %rsi      # 0x19881
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
callq 0x12b16
movq 0x48(%rsp), %rdi
callq 0x33e0
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x3380
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x118e0
movups (%rcx), %xmm0
movups %xmm0, (%r15)
jmp 0x118ed
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
movq %rbx, %rdi
callq 0x33e0
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %rax, %rsi
callq 0x3590
leaq 0x80e5(%rip), %rsi      # 0x19922
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x123ae
movb $0x1, %bpl
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xb783(%rip), %rsi      # 0x1cfe8
movq 0xb774(%rip), %rdx      # 0x1cfe0
movq %r14, %rdi
callq 0x3360
jmp 0x1192c
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
movq %rbx, %rdi
callq 0x33e0
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %rax, %rsi
callq 0x3590
leaq 0x807b(%rip), %rsi      # 0x19922
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x123ae
movb $0x1, %bpl
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xb719(%rip), %rsi      # 0x1cfe8
movq 0xb70a(%rip), %rdx      # 0x1cfe0
movq %r14, %rdi
callq 0x3360
jmp 0x1192c
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
movq 0x8(%rax), %rdx
leaq 0x28(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movb $0x1, %bpl
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xb6cb(%rip), %rsi      # 0x1cfe8
movq 0xb6bc(%rip), %rdx      # 0x1cfe0
movq %r14, %rdi
callq 0x3360
jmp 0x11943
jmp 0x1196c
jmp 0x11943
jmp 0x1196c
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
jne 0x11954
jmp 0x11972
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11972
callq 0x32f0
jmp 0x11972
jmp 0x1196c
jmp 0x11a63
jmp 0x11a63
jmp 0x11a63
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x11a32
jmp 0x11a63
jmp 0x11a63
jmp 0x11a63
jmp 0x11a63
jmp 0x11a47
jmp 0x11a47
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11a0d
callq 0x32f0
jmp 0x11a0d
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x11a28
callq 0x32f0
jmp 0x11a28
jmp 0x11a89
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119f4
callq 0x32f0
jmp 0x119f4
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x11a7d
movq %r14, %rdi
callq 0x3500
jmp 0x11a7d
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11a54
callq 0x32f0
jmp 0x11a54
movq %rax, %rbx
movb $0x1, %bpl
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11a69
callq 0x32f0
jmp 0x11a69
jmp 0x11a89
jmp 0x11a89
movq %rax, %rbx
jmp 0x11a59
movq %rax, %rbx
jmp 0x11a6e
jmp 0x11a89
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x11a8c
movq %r14, %rdi
callq 0x3500
jmp 0x11a8c
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x11aa0
movq %r14, %rdi
callq 0x3500
jmp 0x11aa0
jmp 0x11a89
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x12d74
jmp 0x11a8c
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x11aa0
callq 0x32f0
movq %rbx, %rdi
callq 0x3370