// File: /workspace/github_cpp_makefile_star2_O3/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 0x12c82
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 0x1661f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x166f3
callq 0x3390
testq %rax, %rax
je 0x1319e
movq %rax, %rbx
callq 0x3330
testq %rax, %rax
je 0x131bf
movq %rax, %r12
movq %rax, %rdi
callq 0x3550
movq %r12, %rdi
callq 0x3040
movq %rbx, %rdi
callq 0x3320
testl %eax, %eax
jne 0x131e0
movq %r12, 0x78(%rsp)
movq (%r13), %rsi
movq %rbx, 0x48(%rsp)
movq %rbx, %rdi
callq 0x34c0
testl %eax, %eax
jne 0x1324a
movq (%r14), %r13
movq 0x8(%r14), %rax
movq %rax, 0x80(%rsp)
cmpq %rax, %r13
je 0x12f3a
leaq 0x28(%rsp), %rbp
callq 0x33d0
testq %rax, %rax
je 0x13045
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 0x3620
testl %eax, %eax
jne 0x12f7b
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x153fa
movq 0x30(%rsp), %r12
movq 0x8(%r15), %rbx
cmpq %rbx, %r12
jne 0x12d7c
testq %r12, %r12
je 0x12dd1
movq (%r15), %rsi
movq 0x28(%rsp), %rdi
movq %r12, %rdx
callq 0x33c0
testl %eax, %eax
je 0x12dd1
cmpq %rbx, %r12
jbe 0x12deb
movq %rbp, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x3600
testl %eax, %eax
jne 0x12deb
movq 0x8(%r15), %rdx
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq $-0x1, %rcx
callq 0x3590
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x32e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x12deb
callq 0x32f0
jmp 0x12deb
movl $0x1, %r8d
movq %rbp, %rdi
xorl %esi, %esi
movq %r12, %rdx
leaq 0x8294(%rip), %rcx      # 0x1b07a
callq 0x32d0
movq 0x30(%rsp), %rcx
testq %rcx, %rcx
je 0x13077
movq 0x28(%rsp), %rax
movb (%rax), %dl
cmpb $0x2f, %dl
jne 0x12e1e
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x80f8(%rip), %rsi      # 0x1af0c
movq %rbp, %rdx
callq 0x145e8
jmp 0x12e4c
cmpq $0x1, %rcx
sete %cl
cmpb $0x2e, %dl
setne %dl
orb %cl, %dl
jne 0x12e35
cmpb $0x2f, 0x1(%rax)
je 0x12e6b
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x8235(%rip), %rsi      # 0x1b079
movq %rbp, %rdx
callq 0x145e8
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x32e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x12e6b
callq 0x32f0
movq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x3470
movq %r14, %rdi
callq 0x33f0
cmpl $0x8000, %eax           # imm = 0x8000
je 0x12e91
movq %r14, %rdi
xorl %esi, %esi
callq 0x3440
movq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x3230
testl %eax, %eax
jne 0x12fe0
movq %r14, %rdi
callq 0x3630
testq %rax, %rax
je 0x12efd
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x1466a
movq 0x50(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x48(%rsp), %rdi
callq 0x31d0
cmpq 0x60(%rsp), %rax
jne 0x130ae
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x1285b
leaq 0x50(%rsp), %rdi
callq 0x14844
jmp 0x12f0c
movq %r14, %rdi
xorl %esi, %esi
movq 0x70(%rsp), %rdx
callq 0x1285b
movq %r14, %rdi
callq 0x3670
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x12f28
callq 0x32f0
addq $0x20, %r13
cmpq 0x80(%rsp), %r13
jne 0x12cff
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x30c0
testl %eax, %eax
jne 0x132aa
movq 0x78(%rsp), %rdi
callq 0x30e0
testl %eax, %eax
jne 0x13314
movq %rbx, %rdi
callq 0x35e0
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 0x80bc(%rip), %rsi      # 0x1b04b
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
callq 0x145e8
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 0x130fc
movups (%rcx), %xmm0
leaq 0x38(%rsp), %rdx
movups %xmm0, (%rdx)
jmp 0x13109
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x8088(%rip), %rsi      # 0x1b07c
leaq 0x50(%rsp), %rdi
movq %r13, %rdx
callq 0x145e8
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 0x1314d
movups (%rcx), %xmm0
leaq 0x18(%rsp), %rdx
movups %xmm0, (%rdx)
jmp 0x1315a
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x7fc9(%rip), %rsi      # 0x1b022
movq %rax, %rdi
callq 0x3190
movq 0xbf80(%rip), %rsi      # 0x1efe8
movq 0xbf71(%rip), %rdx      # 0x1efe0
movq %r14, %rdi
callq 0x3360
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x7fd6(%rip), %rsi      # 0x1b061
movq %rax, %rdi
callq 0x3190
movq 0xbf4e(%rip), %rsi      # 0x1efe8
movq 0xbf3f(%rip), %rdx      # 0x1efe0
movq %r14, %rdi
callq 0x3360
jmp 0x133c7
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x7fba(%rip), %rsi      # 0x1b07c
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
callq 0x145e8
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xbf00(%rip), %rsi      # 0x1efe8
movq 0xbef1(%rip), %rdx      # 0x1efe0
movq %r14, %rdi
callq 0x3360
jmp 0x133c7
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 0xbeaf(%rip), %rsi      # 0x1efe8
movq 0xbea0(%rip), %rdx      # 0x1efe0
movq %r14, %rdi
callq 0x3360
jmp 0x133c7
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 0xbe5e(%rip), %rsi      # 0x1efe8
movq 0xbe4f(%rip), %rdx      # 0x1efe0
movq %r14, %rdi
callq 0x3360
jmp 0x133c7
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x7e09(%rip), %rsi      # 0x1afbb
movq %rax, %rdi
callq 0x3190
jmp 0x13061
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x7de8(%rip), %rsi      # 0x1afbb
movq %rax, %rdi
callq 0x3190
jmp 0x13061
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 0x3580
leaq 0x7dd0(%rip), %rsi      # 0x1afde
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x13e64
movb $0x1, %bpl
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xbdb2(%rip), %rsi      # 0x1efe8
movq 0xbda3(%rip), %rdx      # 0x1efe0
movq %r14, %rdi
callq 0x3360
jmp 0x133c7
movl $0x10, %edi
callq 0x3240
movq %rax, %r14
leaq 0x7d9f(%rip), %rsi      # 0x1affd
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
callq 0x145e8
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 0x1337b
movups (%rcx), %xmm0
movups %xmm0, (%r15)
jmp 0x13388
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 0x3580
leaq 0x7dc6(%rip), %rsi      # 0x1b09e
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x13e64
movb $0x1, %bpl
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xbce8(%rip), %rsi      # 0x1efe8
movq 0xbcd9(%rip), %rdx      # 0x1efe0
movq %r14, %rdi
callq 0x3360
jmp 0x133c7
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 0x3580
leaq 0x7d5c(%rip), %rsi      # 0x1b09e
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x13e64
movb $0x1, %bpl
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x31c0
xorl %ebp, %ebp
movq 0xbc7e(%rip), %rsi      # 0x1efe8
movq 0xbc6f(%rip), %rdx      # 0x1efe0
movq %r14, %rdi
callq 0x3360
jmp 0x133c7
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 0xbc30(%rip), %rsi      # 0x1efe8
movq 0xbc21(%rip), %rdx      # 0x1efe0
movq %r14, %rdi
callq 0x3360
jmp 0x133de
jmp 0x13413
jmp 0x133de
jmp 0x13413
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
jne 0x133ef
jmp 0x133f4
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x133f4
callq 0x32f0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x1349b
jmp 0x13413
jmp 0x1352b
jmp 0x1352b
jmp 0x1352b
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x13508
jmp 0x1352b
jmp 0x1352b
jmp 0x1352b
jmp 0x1352b
jmp 0x1352b
jmp 0x1352b
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x13459
callq 0x32f0
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1346c
callq 0x32f0
testb %bpl, %bpl
jne 0x13521
jmp 0x1354c
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x13491
callq 0x32f0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x134a5
callq 0x32f0
testb %bpl, %bpl
jne 0x1352e
jmp 0x13560
jmp 0x13549
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x134cf
callq 0x32f0
testb %bpl, %bpl
jne 0x134d9
jmp 0x1353d
movq %rax, %rbx
movq %r14, %rdi
callq 0x34f0
jmp 0x1353d
movq %rax, %rbx
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13521
callq 0x32f0
jmp 0x13521
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1352e
callq 0x32f0
jmp 0x1352e
jmp 0x13549
jmp 0x13549
jmp 0x1351e
jmp 0x1352b
jmp 0x13549
movq %rax, %rbx
movq %r14, %rdi
callq 0x34f0
jmp 0x1354c
movq %rax, %rbx
movq %r14, %rdi
callq 0x34f0
jmp 0x13560
jmp 0x13549
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x14844
jmp 0x1354c
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x13560
callq 0x32f0
movq %rbx, %rdi
callq 0x3370