// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
movq %r8, 0x18(%rsp)
cmpl $0x6, %esi
jne 0x1a04
pushq $0x6
popq %rdi
pushq $0x4
popq %rsi
pushq $0x7
popq %rdx
xorl %ecx, %ecx
callq 0x1833
movaps 0x28ec(%rip), %xmm0     # 0x42b0
movups %xmm0, 0x1c(%rax)
movaps 0x28f1(%rip), %xmm0     # 0x42c0
movups %xmm0, 0x2c(%rax)
movaps 0x28f6(%rip), %xmm0     # 0x42d0
movups %xmm0, 0x3c(%rax)
movaps 0x28fb(%rip), %xmm0     # 0x42e0
movups %xmm0, 0x4c(%rax)
movaps 0x2900(%rip), %xmm0     # 0x42f0
movups %xmm0, 0x5c(%rax)
movaps 0x2905(%rip), %xmm0     # 0x4300
movups %xmm0, 0x6c(%rax)
jmp 0x1c22
movq %rcx, %r13
movq %rdx, %r15
xorl %ecx, %ecx
testl %edi, %edi
je 0x1ba1
testl %esi, %esi
movl $0x0, %eax
cmovgl %esi, %eax
xorl %ebx, %ebx
cmpq %rcx, %rax
je 0x1a37
movl %ebx, 0x30(%rsp,%rcx,4)
addl (%r15,%rcx,4), %ebx
addl (%r13,%rcx,4), %ebx
incq %rcx
jmp 0x1a20
leal -0x1(%rbx), %r14d
andl $0x18, %r14d
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rcx, %rax
je 0x1a8a
movl %edx, %edi
xorl %r14d, %edi
movslq %edi, %rdi
movl %ecx, 0x40(%rsp,%rdi,4)
movl (%r15,%rcx,4), %edi
leal (%rdx,%rdi), %r8d
decl %r8d
andl $-0x8, %r8d
movl %edx, %r9d
andl $-0x8, %r9d
cmpl %r9d, %r8d
je 0x1a7c
xorl %r14d, %r8d
movslq %r8d, %r8
movl %ecx, 0x40(%rsp,%r8,4)
incl %esi
addl %edx, %edi
addl (%r13,%rcx,4), %edi
incq %rcx
movl %edi, %edx
jmp 0x1a43
movl %ebx, %eax
sarl $0x3, %eax
xorl %ebp, %ebp
movl %esi, %edi
movl %eax, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x1833
xorl %esi, %esi
cmpl %ebx, %ebp
jge 0x1c22
movslq %ebp, %rcx
movslq 0x40(%rsp,%rcx,4), %rdi
cmpq $-0x1, %rdi
jne 0x1ac1
andl $-0x8, %ebp
addl $0x8, %ebp
jmp 0x1aa3
movl 0x30(%rsp,%rdi,4), %edx
movl %edx, %r13d
xorl %r14d, %r13d
cmpl %ebp, %r13d
jne 0x1b0d
leal 0x1(%rsi), %ecx
movl %ecx, 0x8(%rsp)
movq 0x18(%rsp), %rcx
movl (%rcx,%rdi,4), %edx
movl (%r15,%rdi,4), %r12d
movq %rax, %r13
movq %rax, %rdi
movl %r12d, %ecx
movl %ebp, %r8d
pushq $0x1
popq %r9
pushq 0x10(%rsp)
pushq $0x1
callq 0x18aa
addq $0x10, %rsp
movl 0x8(%rsp), %eax
movl %eax, %esi
jmp 0x1b96
andl $0x7, %edx
pushq $0x8
popq %rcx
subl %edx, %ecx
movl (%r15,%rdi,4), %edx
subl %ecx, %edx
movl %edx, 0x2c(%rsp)
leal 0x1(%rsi), %edx
movl %edx, 0x28(%rsp)
movq 0x18(%rsp), %rdx
movl (%rdx,%rdi,4), %edx
movl %edx, 0x24(%rsp)
movq %rax, %r12
movq %rax, %rdi
movq %rsi, 0x8(%rsp)
movl %r13d, %r8d
xorl %r9d, %r9d
pushq 0x10(%rsp)
pushq $0x1
callq 0x18aa
popq %rax
popq %rcx
movslq %r13d, %rax
orl $-0x1, 0x40(%rsp,%rax,4)
movq 0x8(%rsp), %rax
addl $0x2, %eax
movq %rax, 0x8(%rsp)
movq %r12, %r13
movq %r12, %rdi
movl 0x2c(%rsp), %r12d
movl 0x28(%rsp), %esi
movl 0x24(%rsp), %edx
movl %r12d, %ecx
movl %ebp, %r8d
pushq $0x1
popq %r9
pushq 0x10(%rsp)
pushq $0x0
callq 0x18aa
movq 0x18(%rsp), %rsi
addq $0x10, %rsp
addl %r12d, %ebp
movq %r13, %rax
jmp 0x1aa3
testl %esi, %esi
movl $0x0, %r12d
cmovgl %esi, %r12d
xorl %eax, %eax
cmpq %rcx, %r12
je 0x1bc2
addl (%r15,%rcx,4), %eax
addl (%r13,%rcx,4), %eax
incq %rcx
jmp 0x1baf
sarl $0x3, %eax
xorl %ebp, %ebp
movl %esi, %edi
movl %eax, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x1833
movq %rax, 0x8(%rsp)
xorl %r14d, %r14d
cmpq %rbp, %r12
je 0x1c1d
movq 0x18(%rsp), %rax
movl (%rax,%rbp,4), %edx
movl (%r15,%rbp,4), %ebx
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %ecx
movl %r14d, %r8d
pushq $0x1
popq %r9
pushq 0x10(%rsp)
pushq $0x1
callq 0x18aa
popq %rax
popq %rcx
addl %r14d, %ebx
addl (%r13,%rbp,4), %ebx
incq %rbp
movl %ebx, %r14d
jmp 0x1bdf
movq 0x8(%rsp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq