// File: ivan-tkatchev[P]makerpm/makerpm.cc
// Function: make_index1(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, mfile&, 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>>&)
mfile make_index1(const std::string& index2, mfile& payload, const std::string& compressed_payload, std::string& header) {

    // Add signature fields.

    Store store;

    ////

    unsigned char sha1_raw[20];

    ::SHA1((const unsigned char*)index2.data(), index2.size(), sha1_raw);

    std::string sha1 = print_digest(sha1_raw, 20);

    uint64_t uncompressedsize = payload.size;

    ////

    compress_file(payload, compressed_payload);

    mfile ret(compressed_payload);

    ////

    std::vector<unsigned char> md5;
    md5.resize(16);

    MD5_CTX md5_c;

    if (!::MD5_Init(&md5_c))
        throw std::runtime_error("MD5_Init() failed");

    if (!::MD5_Update(&md5_c, (const unsigned char*)index2.data(), index2.size()))
        throw std::runtime_error("MD5_Update() failed");

    if (!::MD5_Update(&md5_c, (const unsigned char*)ret.addr, ret.size))
        throw std::runtime_error("MD5_Update() failed");

    if (!::MD5_Final(&(md5[0]), &md5_c))
        throw std::runtime_error("MD5_Final() failed");

    ////

    store.add(rpm::TAG_SHA1HEADER, sha1, false);

    uint64_t size = index2.size() + ret.size;

    if (size < 0xFFFFFFFF) {
        store.add(rpm::TAG_SIGSIZE, (uint32_t)size);
    } else {
        store.add(rpm::TAG_SIGLONGSIZE, size);
    }

    store.add(rpm::TAG_MD5, md5);

    if (uncompressedsize < 0xFFFFFFFF) {
        store.add(rpm::TAG_PAYLOADSIZE, (uint32_t)uncompressedsize);
    } else {
        store.add(rpm::TAG_PAYLOADLONGSIZE, uncompressedsize);
    }

    header = store.str(rpm::TAG_HEADERSIGNATURES);

    // Align the data to 8 bytes.

    size_t n = header.size();
    size_t q = (8 - (n % 8)) % 8;

    while (q > 0) {
        header += '\0';
        --q;
    }

    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x198(%rbp)
movq %rdi, %rax
movq %rax, -0x190(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x21c60
movq -0x10(%rbp), %rdi
callq 0x41e0
movq %rax, -0x188(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4270
movq -0x188(%rbp), %rdi
movq %rax, %rsi
leaq -0x90(%rbp), %rdx
callq 0x4170
jmp 0x1f20a
leaq -0xc0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0x14, %edx
callq 0x1f0d0
jmp 0x1f224
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1eec0
jmp 0x1f242
movq -0x198(%rbp), %rdi
movb $0x0, -0xc9(%rbp)
movq -0x20(%rbp), %rsi
callq 0x22ed0
jmp 0x1f25b
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x230d0
movq -0x1a0(%rbp), %rdi
movl $0x10, %esi
callq 0x230f0
jmp 0x1f281
leaq -0x144(%rbp), %rdi
callq 0x44f0
movl %eax, -0x1a4(%rbp)
jmp 0x1f295
movl -0x1a4(%rbp), %eax
cmpl $0x0, %eax
jne 0x1f350
movl $0x10, %edi
callq 0x42f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1b0(%rbp)
leaq 0x12254(%rip), %rsi     # 0x31516
callq 0x41f0
jmp 0x1f2c9
movq -0x1b0(%rbp), %rdi
movq 0x1ad09(%rip), %rsi     # 0x39fe0
movq 0x1acfa(%rip), %rdx     # 0x39fd8
callq 0x4430
jmp 0x1f705
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1f6f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1f6e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1f699
movq -0x1b0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
callq 0x4630
jmp 0x1f699
movq -0x10(%rbp), %rdi
callq 0x41e0
movq %rax, -0x1c0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4270
movq -0x1c0(%rbp), %rsi
movq %rax, %rdx
leaq -0x144(%rbp), %rdi
callq 0x4090
movl %eax, -0x1b4(%rbp)
jmp 0x1f387
movl -0x1b4(%rbp), %eax
cmpl $0x0, %eax
jne 0x1f3f9
movl $0x10, %edi
callq 0x42f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1c8(%rbp)
leaq 0x12178(%rip), %rsi     # 0x31528
callq 0x41f0
jmp 0x1f3b7
movq -0x1c8(%rbp), %rdi
movq 0x1ac1b(%rip), %rsi     # 0x39fe0
movq 0x1ac0c(%rip), %rdx     # 0x39fd8
callq 0x4430
jmp 0x1f705
movq -0x1c8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
callq 0x4630
jmp 0x1f699
movq -0x198(%rbp), %rax
movq (%rax), %rsi
movq 0x10(%rax), %rdx
leaq -0x144(%rbp), %rdi
callq 0x4090
movl %eax, -0x1cc(%rbp)
jmp 0x1f41b
movl -0x1cc(%rbp), %eax
cmpl $0x0, %eax
jne 0x1f48d
movl $0x10, %edi
callq 0x42f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1d8(%rbp)
leaq 0x120e4(%rip), %rsi     # 0x31528
callq 0x41f0
jmp 0x1f44b
movq -0x1d8(%rbp), %rdi
movq 0x1ab87(%rip), %rsi     # 0x39fe0
movq 0x1ab78(%rip), %rdx     # 0x39fd8
callq 0x4430
jmp 0x1f705
movq -0x1d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
callq 0x4630
jmp 0x1f699
xorl %eax, %eax
movl %eax, %esi
leaq -0xe8(%rbp), %rdi
callq 0x23180
movq %rax, %rdi
leaq -0x144(%rbp), %rsi
callq 0x4330
movl %eax, -0x1dc(%rbp)
jmp 0x1f4b4
movl -0x1dc(%rbp), %eax
cmpl $0x0, %eax
jne 0x1f526
movl $0x10, %edi
callq 0x42f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1e8(%rbp)
leaq 0x1205f(%rip), %rsi     # 0x3153c
callq 0x41f0
jmp 0x1f4e4
movq -0x1e8(%rbp), %rdi
movq 0x1aaee(%rip), %rsi     # 0x39fe0
movq 0x1aadf(%rip), %rdx     # 0x39fd8
callq 0x4430
jmp 0x1f705
movq -0x1e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
callq 0x4630
jmp 0x1f699
leaq -0x70(%rbp), %rdi
movl $0x10d, %esi            # imm = 0x10D
leaq -0xc0(%rbp), %rdx
xorl %ecx, %ecx
callq 0x21ca0
jmp 0x1f53f
movq -0x10(%rbp), %rdi
callq 0x4270
movq -0x198(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x150(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x150(%rbp)
jae 0x1f580
movl -0x150(%rbp), %edx
leaq -0x70(%rbp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x21d50
jmp 0x1f57e
jmp 0x1f599
movq -0x150(%rbp), %rdx
leaq -0x70(%rbp), %rdi
movl $0x10e, %esi            # imm = 0x10E
callq 0x228a0
jmp 0x1f597
jmp 0x1f599
leaq -0x70(%rbp), %rdi
movl $0x3ec, %esi            # imm = 0x3EC
leaq -0xe8(%rbp), %rdx
callq 0x231a0
jmp 0x1f5b0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0xc8(%rbp)
jae 0x1f5d6
movl -0xc8(%rbp), %edx
leaq -0x70(%rbp), %rdi
movl $0x3ef, %esi            # imm = 0x3EF
callq 0x21d50
jmp 0x1f5d4
jmp 0x1f5ef
movq -0xc8(%rbp), %rdx
leaq -0x70(%rbp), %rdi
movl $0x10f, %esi            # imm = 0x10F
callq 0x228a0
jmp 0x1f5ed
jmp 0x1f5ef
leaq -0x170(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x3e, %edx
callq 0x22970
jmp 0x1f606
movq -0x28(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x43a0
leaq -0x170(%rbp), %rdi
callq 0x4540
movq -0x28(%rbp), %rdi
callq 0x4270
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rcx
andq $0x7, %rcx
movl $0x8, %eax
subq %rcx, %rax
andq $0x7, %rax
movq %rax, -0x180(%rbp)
cmpq $0x0, -0x180(%rbp)
jbe 0x1f67b
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x4490
jmp 0x1f667
movq -0x180(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x180(%rbp)
jmp 0x1f650
movb $0x1, -0xc9(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x23290
testb $0x1, -0xc9(%rbp)
jne 0x1f6bf
jmp 0x1f6b3
leaq -0xe8(%rbp), %rdi
callq 0x23290
movq -0x198(%rbp), %rdi
callq 0x232f0
jmp 0x1f6e4
movq -0x198(%rbp), %rdi
callq 0x232f0
leaq -0xc0(%rbp), %rdi
callq 0x4540
leaq -0x70(%rbp), %rdi
callq 0x22d90
movq -0x190(%rbp), %rax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
leaq -0xc0(%rbp), %rdi
callq 0x4540
leaq -0x70(%rbp), %rdi
callq 0x22d90
movq -0x98(%rbp), %rdi
callq 0x4440
nopw %cs:(%rax,%rax)