// File: /workspace/github_c_makefile_star2_O1/KhronosGroup[P]dfdutils/createdfd.c
// Function: createDFDPackedPadded
uint32_t *createDFDPackedPadded(int bigEndian, int numChannels,
                                int bits[], int paddings[], int channels[],
                                enum VkSuffix suffix)
{
    uint32_t *DFD = 0;
    if (numChannels == 6) {
        /* Special case E5B9G9R9 */
        DFD = writeHeader(numChannels, 4, s_UFLOAT, i_COLOR);
        writeSample(DFD, 0, 0,
                    9, 0,
                    1, 1, s_UNORM);
        KHR_DFDSETSVAL((DFD+1), 0, SAMPLEUPPER, 8448);
        writeSample(DFD, 1, 0 | KHR_DF_SAMPLE_DATATYPE_EXPONENT,
                    5, 27,
                    1, 1, s_UNORM);
        KHR_DFDSETSVAL((DFD+1), 1, SAMPLELOWER, 15);
        KHR_DFDSETSVAL((DFD+1), 1, SAMPLEUPPER, 31);
        writeSample(DFD, 2, 1,
                    9, 9,
                    1, 1, s_UNORM);
        KHR_DFDSETSVAL((DFD+1), 2, SAMPLEUPPER, 8448);
        writeSample(DFD, 3, 1 | KHR_DF_SAMPLE_DATATYPE_EXPONENT,
                    5, 27,
                    1, 1, s_UNORM);
        KHR_DFDSETSVAL((DFD+1), 3, SAMPLELOWER, 15);
        KHR_DFDSETSVAL((DFD+1), 3, SAMPLEUPPER, 31);
        writeSample(DFD, 4, 2,
                    9, 18,
                    1, 1, s_UNORM);
        KHR_DFDSETSVAL((DFD+1), 4, SAMPLEUPPER, 8448);
        writeSample(DFD, 5, 2 | KHR_DF_SAMPLE_DATATYPE_EXPONENT,
                    5, 27,
                    1, 1, s_UNORM);
        KHR_DFDSETSVAL((DFD+1), 5, SAMPLELOWER, 15);
        KHR_DFDSETSVAL((DFD+1), 5, SAMPLEUPPER, 31);
    } else if (bigEndian) {
        /* No packed format is larger than 32 bits. */
        /* No packed channel crosses more than two bytes. */
        int totalBits = 0;
        int bitChannel[32];
        int beChannelStart[4];
        int channelCounter;
        int bitOffset = 0;
        int BEMask;
        int numSamples = numChannels;
        int sampleCounter;
        for (channelCounter = 0; channelCounter < numChannels; ++channelCounter) {
            beChannelStart[channelCounter] = totalBits;
            totalBits += bits[channelCounter] + paddings[channelCounter];
        }
        BEMask = (totalBits - 1) & 0x18;
        for (channelCounter = 0; channelCounter < numChannels; ++channelCounter) {
            bitChannel[bitOffset ^ BEMask] = channelCounter;
            if (((bitOffset + bits[channelCounter] - 1) & ~7) != (bitOffset & ~7)) {
                /* Continuation sample */
                bitChannel[((bitOffset + bits[channelCounter] - 1) & ~7) ^ BEMask] = channelCounter;
                numSamples++;
            }
            bitOffset += bits[channelCounter] + paddings[channelCounter];
        }
        DFD = writeHeader(numSamples, totalBits >> 3, suffix, i_COLOR);

        sampleCounter = 0;
        for (bitOffset = 0; bitOffset < totalBits;) {
            if (bitChannel[bitOffset] == -1) {
                /* Done this bit, so this is the lower half of something. */
                /* We must therefore jump to the end of the byte and continue. */
                bitOffset = (bitOffset + 8) & ~7;
            } else {
                /* Start of a channel? */
                int thisChannel = bitChannel[bitOffset];
                if ((beChannelStart[thisChannel] ^ BEMask) == bitOffset) {
                    /* Must be just one sample if we hit it first. */
                    writeSample(DFD, sampleCounter++, channels[thisChannel],
                                    bits[thisChannel], bitOffset,
                                    1, 1, suffix);
                    bitOffset += bits[thisChannel];
                } else {
                    /* Two samples. Move to the end of the first one we hit when we're done. */
                    int firstSampleBits = 8 - (beChannelStart[thisChannel] & 0x7); /* Rest of the byte */
                    int secondSampleBits = bits[thisChannel] - firstSampleBits; /* Rest of the bits */
                    writeSample(DFD, sampleCounter++, channels[thisChannel],
                                firstSampleBits, beChannelStart[thisChannel] ^ BEMask,
                                0, 1, suffix);
                    /* Mark that we've already handled this sample */
                    bitChannel[beChannelStart[thisChannel] ^ BEMask] = -1;
                    writeSample(DFD, sampleCounter++, channels[thisChannel],
                                secondSampleBits, bitOffset,
                                1, 0, suffix);
                    bitOffset += secondSampleBits;
                }
            }
        }

    } else { /* Little-endian */

        int sampleCounter;
        int totalBits = 0;
        int bitOffset = 0;
        for (sampleCounter = 0; sampleCounter < numChannels; ++sampleCounter) {
            totalBits += bits[sampleCounter] + paddings[sampleCounter];
        }

        /* One sample per channel */
        DFD = writeHeader(numChannels, totalBits >> 3, suffix, i_COLOR);
        for (sampleCounter = 0; sampleCounter < numChannels; ++sampleCounter) {
            writeSample(DFD, sampleCounter, channels[sampleCounter],
                        bits[sampleCounter], bitOffset,
                        1, 1, suffix);
            bitOffset += bits[sampleCounter] + paddings[sampleCounter];
        }
    }
    return DFD;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
cmpl $0x6, %esi
jne 0x1bde
movl $0x7c, %edi
callq 0x1080
movq %rax, %r12
movaps 0x3748(%rip), %xmm0     # 0x52b0
movups %xmm0, (%rax)
movaps 0x374e(%rip), %xmm0     # 0x52c0
movups %xmm0, 0x10(%rax)
movaps 0x3753(%rip), %xmm0     # 0x52d0
movups %xmm0, 0x20(%rax)
xorl %eax, %eax
movl %eax, 0x30(%r12)
movabsq $0x1f0000000f, %rcx     # imm = 0x1F0000000F
movq %rcx, 0x34(%r12)
movaps 0x3742(%rip), %xmm0     # 0x52e0
movups %xmm0, 0x3c(%r12)
movq $0x2104001b, 0x4c(%r12) # imm = 0x2104001B
movq %rcx, 0x54(%r12)
movsd 0x3736(%rip), %xmm0     # 0x52f0
movups %xmm0, 0x58(%r12)
movabsq $0x2204001b00002100, %rdx # imm = 0x2204001B00002100
movq %rdx, 0x68(%r12)
movl %eax, 0x70(%r12)
movq %rcx, 0x74(%r12)
jmp 0x1ea6
movq %rcx, %r13
movl %esi, %ebp
movq %r8, 0x20(%rsp)
testl %edi, %edi
je 0x1c1b
movl %ebp, %eax
testl %ebp, %ebp
jle 0x1cf8
xorl %ecx, %ecx
xorl %r15d, %r15d
movq 0x10(%rsp), %rdx
movl %r15d, 0x30(%rsp,%rcx,4)
addl (%rdx,%rcx,4), %r15d
addl (%r13,%rcx,4), %r15d
incq %rcx
cmpq %rcx, %rax
jne 0x1c00
jmp 0x1cfb
xorl %r14d, %r14d
movl $0x0, %r15d
testl %ebp, %ebp
jle 0x1c49
movl %ebp, %eax
xorl %ecx, %ecx
xorl %r15d, %r15d
movq 0x10(%rsp), %rdx
addl (%rdx,%rcx,4), %r15d
addl (%r13,%rcx,4), %r15d
incq %rcx
cmpq %rcx, %rax
jne 0x1c34
sarl $0x3, %r15d
leal (,%rbp,4), %eax
cltq
leaq 0x1c(,%rax,4), %rbx
movq %rbx, %rdi
callq 0x1080
movl %ebx, (%rax)
movl %r14d, 0x4(%rax)
movl %ebp, %ecx
shll $0x14, %ecx
addl $0x180002, %ecx         # imm = 0x180002
movl %ecx, 0x8(%rax)
xorl %ecx, %ecx
cmpl $0x8, 0x8(%rsp)
sete %cl
shll $0x10, %ecx
addl $0x10101, %ecx          # imm = 0x10101
movl %ecx, 0xc(%rax)
movl %r14d, 0x10(%rax)
movl %r15d, 0x14(%rax)
movq %rax, %r15
movl %r14d, 0x18(%rax)
testl %ebp, %ebp
jle 0x1cf0
movl %ebp, %eax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0x20(%rsp), %r12
movl (%r12,%r14,4), %edx
movq 0x10(%rsp), %rax
movl (%rax,%r14,4), %ebp
movq %r15, %rdi
movl %r14d, %esi
movl %ebp, %ecx
movl %ebx, %r8d
movl $0x1, %r9d
pushq 0x8(%rsp)
pushq $0x1
callq 0x1a3f
addq $0x10, %rsp
addl %ebx, %ebp
addl (%r13,%r14,4), %ebp
incq %r14
movl %ebp, %ebx
cmpq %r14, 0x18(%rsp)
jne 0x1cb0
movq %r15, %r12
jmp 0x1ea6
xorl %r15d, %r15d
leal -0x1(%r15), %r9d
andl $0x18, %r9d
testl %ebp, %ebp
jle 0x1d50
xorl %ecx, %ecx
xorl %edx, %edx
movl %edx, %esi
xorl %r9d, %esi
movslq %esi, %rsi
movl %ecx, 0x40(%rsp,%rsi,4)
movq 0x10(%rsp), %rsi
movl (%rsi,%rcx,4), %esi
leal (%rdx,%rsi), %edi
decl %edi
andl $-0x8, %edi
movl %edx, %r8d
andl $-0x8, %r8d
cmpl %r8d, %edi
je 0x1d3f
xorl %r9d, %edi
movslq %edi, %rdi
movl %ecx, 0x40(%rsp,%rdi,4)
incl %ebp
addl %edx, %esi
addl (%r13,%rcx,4), %esi
incq %rcx
movl %esi, %edx
cmpq %rcx, %rax
jne 0x1d0b
movl %r9d, 0x18(%rsp)
movl %r15d, %r14d
sarl $0x3, %r14d
leal (,%rbp,4), %eax
cltq
leaq 0x1c(,%rax,4), %rbx
movq %rbx, %rdi
callq 0x1080
movq %rax, %r12
movl %ebx, (%rax)
xorl %r13d, %r13d
movl %r13d, 0x4(%rax)
shll $0x14, %ebp
addl $0x180002, %ebp         # imm = 0x180002
movl %ebp, 0x8(%rax)
xorl %eax, %eax
cmpl $0x8, 0x8(%rsp)
sete %al
shll $0x10, %eax
addl $0x10101, %eax          # imm = 0x10101
movl %eax, 0xc(%r12)
movl %r13d, 0x10(%r12)
movl %r14d, 0x14(%r12)
movl %r13d, 0x18(%r12)
testl %r15d, %r15d
jle 0x1ea6
xorl %ebp, %ebp
movslq %ebp, %rax
movslq 0x40(%rsp,%rax,4), %rax
cmpq $-0x1, %rax
je 0x1e18
movl 0x30(%rsp,%rax,4), %edx
movl %edx, %ebx
xorl 0x18(%rsp), %ebx
cmpl %ebp, %ebx
jne 0x1e20
leal 0x1(%r13), %ebx
movq 0x20(%rsp), %rcx
movl (%rcx,%rax,4), %edx
movq 0x10(%rsp), %rcx
movl (%rcx,%rax,4), %r14d
movq %r12, %rdi
movl %r13d, %esi
movl %r14d, %ecx
movl %ebp, %r8d
movl $0x1, %r9d
pushq 0x8(%rsp)
pushq $0x1
callq 0x1a3f
addq $0x10, %rsp
movl %ebx, %r13d
jmp 0x1e9a
andl $-0x8, %ebp
addl $0x8, %ebp
jmp 0x1e9d
andl $0x7, %edx
movl $0x8, %ecx
subl %edx, %ecx
movq 0x10(%rsp), %rdx
movl (%rdx,%rax,4), %r14d
subl %ecx, %r14d
leal 0x1(%r13), %edx
movl %edx, 0x2c(%rsp)
movq 0x20(%rsp), %rdx
movl (%rdx,%rax,4), %edx
movl %edx, 0x28(%rsp)
movq %r12, %rdi
movl %r13d, %esi
movl %ebx, %r8d
xorl %r9d, %r9d
pushq 0x8(%rsp)
pushq $0x1
callq 0x1a3f
addq $0x10, %rsp
movslq %ebx, %rax
movl $0xffffffff, 0x40(%rsp,%rax,4) # imm = 0xFFFFFFFF
addl $0x2, %r13d
movq %r12, %rdi
movl 0x2c(%rsp), %esi
movl 0x28(%rsp), %edx
movl %r14d, %ecx
movl %ebp, %r8d
movl $0x1, %r9d
pushq 0x8(%rsp)
pushq $0x0
callq 0x1a3f
addq $0x10, %rsp
addl %r14d, %ebp
cmpl %r15d, %ebp
jl 0x1dbe
movq %r12, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq