// File: ivan-tkatchev[P]makerpm/makerpm.cc
// Function: add_to_rpmprops(archive_entry*, mfile*, rpmprops_t&)
void add_to_rpmprops(struct archive_entry* entry, mfile* data, rpmprops_t& props) {

    props.files.push_back(rpmprops_t::file_t());

    rpmprops_t::file_t& f = props.files.back();

    uint64_t size = ::archive_entry_size(entry);

    if (size < 0xFFFFFFFF) {
        f.size = size;
    } else {
        f.longsize = size;
    }

    f.mode = ::archive_entry_mode(entry);
    f.rdev = ::archive_entry_rdev(entry);
    f.mtime = ::archive_entry_mtime(entry);

    const char* linkto = ::archive_entry_symlink(entry);
    if (linkto != NULL) {
        f.linkto = linkto;
    }

    f.device = ::archive_entry_dev(entry);
    f.inode = ::archive_entry_ino(entry);

    if (props.forceusername.size() > 0) {
        f.username = props.forceusername;

    } else {

        const char* uname = ::archive_entry_uname(entry);

        if (uname == NULL) {
            f.username = uid_to_uname(::archive_entry_uid(entry));
        } else {
            f.username = uname;
        }
    }

    if (props.forcegroupname.size() > 0) {
        f.groupname = props.forcegroupname;

    } else {

        const char* gname = ::archive_entry_gname(entry);

        if (gname == NULL) {
            f.groupname = gid_to_gname(::archive_entry_gid(entry));
        } else {
            f.groupname = gname;
        }
    }

    f.fname = ::archive_entry_pathname(entry);

    if (f.fname.size() < 2 ||
        f.fname[0] != '.' ||
        f.fname[1] != '/') {

        throw std::runtime_error("RPM requires a CPIO archive with relative paths that start with \"./\"!\n"
                                 "Malformed pathname in archive: " + f.fname);
    }

    unsigned char digest[16];
    if (data != nullptr) {
        ::MD5((const unsigned char*)data->addr, data->size, digest);
    } else {
        ::MD5((const unsigned char*)"", 0, digest);
    }
    f.digest = print_digest(digest, 16);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x408, %rax            # imm = 0x408
movq %rax, -0x1d0(%rbp)
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x234c0
movq -0x1d0(%rbp), %rdi
movq -0x1c8(%rbp), %rsi
callq 0x23490
jmp 0x1fc50
leaq -0xe8(%rbp), %rdi
callq 0x235b0
movq -0x18(%rbp), %rdi
addq $0x408, %rdi            # imm = 0x408
callq 0x23610
movq %rax, -0x100(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4790
movq %rax, -0x108(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x108(%rbp)
jae 0x1fcc8
movq -0x108(%rbp), %rax
movl %eax, %ecx
movq -0x100(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1fcda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x235b0
jmp 0x20086
movq -0x108(%rbp), %rcx
movq -0x100(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
callq 0x4180
movw %ax, %cx
movq -0x100(%rbp), %rax
movw %cx, 0x10(%rax)
movq -0x8(%rbp), %rdi
callq 0x46a0
movw %ax, %cx
movq -0x100(%rbp), %rax
movw %cx, 0x12(%rax)
movq -0x8(%rbp), %rdi
callq 0x4220
movl %eax, %ecx
movq -0x100(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rdi
callq 0x4380
movq %rax, -0x110(%rbp)
cmpq $0x0, -0x110(%rbp)
je 0x1fd4e
movq -0x110(%rbp), %rsi
movq -0x100(%rbp), %rdi
addq $0x38, %rdi
callq 0x4310
movq -0x8(%rbp), %rdi
callq 0x42b0
movl %eax, %ecx
movq -0x100(%rbp), %rax
movl %ecx, 0xa4(%rax)
movq -0x8(%rbp), %rdi
callq 0x4210
movl %eax, %ecx
movq -0x100(%rbp), %rax
movl %ecx, 0xa8(%rax)
movq -0x18(%rbp), %rdi
addq $0x268, %rdi            # imm = 0x268
callq 0x4270
cmpq $0x0, %rax
jbe 0x1fdb1
movq -0x18(%rbp), %rsi
addq $0x268, %rsi            # imm = 0x268
movq -0x100(%rbp), %rdi
addq $0x60, %rdi
callq 0x47d0
jmp 0x1fe20
movq -0x8(%rbp), %rdi
callq 0x41d0
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0x1fe07
movq -0x8(%rbp), %rdi
callq 0x4130
movl %eax, %esi
leaq -0x138(%rbp), %rdi
callq 0x1f940
movq -0x100(%rbp), %rdi
addq $0x60, %rdi
leaq -0x138(%rbp), %rsi
callq 0x43a0
leaq -0x138(%rbp), %rdi
callq 0x4540
jmp 0x1fe1e
movq -0x118(%rbp), %rsi
movq -0x100(%rbp), %rdi
addq $0x60, %rdi
callq 0x4310
jmp 0x1fe20
movq -0x18(%rbp), %rdi
addq $0x288, %rdi            # imm = 0x288
callq 0x4270
cmpq $0x0, %rax
jbe 0x1fe56
movq -0x18(%rbp), %rsi
addq $0x288, %rsi            # imm = 0x288
movq -0x100(%rbp), %rdi
addq $0x80, %rdi
callq 0x47d0
jmp 0x1fecb
movq -0x8(%rbp), %rdi
callq 0x4480
movq %rax, -0x140(%rbp)
cmpq $0x0, -0x140(%rbp)
jne 0x1feaf
movq -0x8(%rbp), %rdi
callq 0x4260
movl %eax, %esi
leaq -0x160(%rbp), %rdi
callq 0x1fac0
movq -0x100(%rbp), %rdi
addq $0x80, %rdi
leaq -0x160(%rbp), %rsi
callq 0x43a0
leaq -0x160(%rbp), %rdi
callq 0x4540
jmp 0x1fec9
movq -0x140(%rbp), %rsi
movq -0x100(%rbp), %rdi
addq $0x80, %rdi
callq 0x4310
jmp 0x1fecb
movq -0x8(%rbp), %rdi
callq 0x4760
movq %rax, %rsi
movq -0x100(%rbp), %rdi
addq $0xb0, %rdi
callq 0x4310
movq -0x100(%rbp), %rdi
addq $0xb0, %rdi
callq 0x4270
cmpq $0x2, %rax
jb 0x1ff46
movq -0x100(%rbp), %rdi
addq $0xb0, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x47b0
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x1ff46
movq -0x100(%rbp), %rdi
addq $0xb0, %rdi
movl $0x1, %esi
callq 0x47b0
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x20007
movb $0x1, -0x181(%rbp)
movl $0x10, %edi
callq 0x42f0
movq %rax, -0x1d8(%rbp)
movq -0x100(%rbp), %rdx
addq $0xb0, %rdx
leaq 0x115ea(%rip), %rsi     # 0x3155d
leaq -0x180(%rbp), %rdi
callq 0x22dc0
jmp 0x1ff81
movq -0x1d8(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x4230
jmp 0x1ff96
movq -0x1d8(%rbp), %rdi
movb $0x0, -0x181(%rbp)
movq 0x1a035(%rip), %rsi     # 0x39fe0
movq 0x1a026(%rip), %rdx     # 0x39fd8
callq 0x4430
jmp 0x20092
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
jmp 0x1ffee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x4540
testb $0x1, -0x181(%rbp)
jne 0x1fff9
jmp 0x20005
movq -0x1d8(%rbp), %rdi
callq 0x4630
jmp 0x20086
cmpq $0x0, -0x10(%rbp)
je 0x2002b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x1a0(%rbp), %rdx
callq 0x45a0
jmp 0x20042
leaq -0x1a0(%rbp), %rdx
leaq 0x1175d(%rip), %rdi     # 0x31796
xorl %eax, %eax
movl %eax, %esi
callq 0x45a0
leaq -0x1a0(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
movl $0x10, %edx
callq 0x1f0d0
movq -0x100(%rbp), %rdi
addq $0x18, %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x43a0
leaq -0x1c0(%rbp), %rdi
callq 0x4540
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
movq -0xf0(%rbp), %rdi
callq 0x4440
nopw %cs:(%rax,%rax)