// File: /workspace/github_c_makefile_star2_O3/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
cmpl $0x6, %esi
jne 0x1a2e
movl $0x7c, %edi
callq 0x1080
movq %rax, %r15
movaps 0x28e2(%rip), %xmm0     # 0x42b0
movups %xmm0, (%rax)
movaps 0x28e8(%rip), %xmm0     # 0x42c0
movups %xmm0, 0x10(%rax)
movaps 0x28ed(%rip), %xmm0     # 0x42d0
movups %xmm0, 0x20(%rax)
movaps 0x28f2(%rip), %xmm0     # 0x42e0
movups %xmm0, 0x30(%rax)
movaps 0x28f7(%rip), %xmm0     # 0x42f0
movups %xmm0, 0x40(%rax)
movaps 0x28fc(%rip), %xmm0     # 0x4300
movups %xmm0, 0x50(%rax)
movaps 0x2901(%rip), %xmm0     # 0x4310
movups %xmm0, 0x60(%rax)
movabsq $0xf00000000, %rax      # imm = 0xF00000000
movq %rax, 0x70(%r15)
movl $0x1f, 0x78(%r15)
jmp 0x1d25
movq %rcx, %r13
movq %rdx, %r12
movl %esi, %ebp
testl %edi, %edi
movq %r9, 0x8(%rsp)
movq %r8, 0x20(%rsp)
je 0x1ad4
xorl %r14d, %r14d
testl %ebp, %ebp
movq %r12, 0x18(%rsp)
jle 0x1bb7
movl %ebp, %eax
xorl %ecx, %ecx
xorl %r15d, %r15d
movl %r15d, 0x30(%rsp,%rcx,4)
addl (%r12,%rcx,4), %r15d
addl (%r13,%rcx,4), %r15d
incq %rcx
cmpq %rcx, %rax
jne 0x1a5f
leal -0x1(%r15), %r9d
andl $0x18, %r9d
testl %ebp, %ebp
movl %r9d, 0x14(%rsp)
jle 0x1bc2
xorl %ecx, %ecx
xorl %edx, %edx
movl %edx, %esi
xorl %r9d, %esi
movslq %esi, %rsi
movl %ecx, 0x40(%rsp,%rsi,4)
movl (%r12,%rcx,4), %esi
leal (%rdx,%rsi), %edi
decl %edi
andl $-0x8, %edi
movl %edx, %r8d
andl $-0x8, %r8d
cmpl %r8d, %edi
je 0x1abe
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 0x1a8e
jmp 0x1bc2
xorl %r14d, %r14d
movl $0x0, %r15d
testl %ebp, %ebp
jle 0x1afd
movl %ebp, %eax
xorl %ecx, %ecx
xorl %r15d, %r15d
addl (%r12,%rcx,4), %r15d
addl (%r13,%rcx,4), %r15d
incq %rcx
cmpq %rcx, %rax
jne 0x1ae8
sarl $0x3, %r15d
leal (,%rbp,4), %eax
cltq
leaq 0x1c(,%rax,4), %rbx
movq %rbx, %rdi
callq 0x1080
movl %ebp, %edx
shll $0x14, %edx
addl $0x180002, %edx         # imm = 0x180002
xorl %ecx, %ecx
movq 0x8(%rsp), %r10
cmpl $0x8, %r10d
sete %cl
shll $0x10, %ecx
addl $0x10101, %ecx          # imm = 0x10101
movl %ebx, (%rax)
movl %r14d, 0x4(%rax)
movl %edx, 0x8(%rax)
movl %ecx, 0xc(%rax)
movl %r14d, 0x10(%rax)
movl %r15d, 0x14(%rax)
movq %rax, %r15
movl %r14d, 0x18(%rax)
testl %ebp, %ebp
jle 0x1d25
movl %ebp, %eax
movq %rax, (%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r12, 0x18(%rsp)
movq 0x20(%rsp), %r12
movl (%r12,%r14,4), %edx
movq 0x18(%rsp), %rax
movl (%rax,%r14,4), %ebp
movq %r15, %rdi
movl %r14d, %esi
movl %ebp, %ecx
movl %ebx, %r8d
movl $0x1, %r9d
pushq %r10
pushq $0x1
callq 0x18b3
movq 0x18(%rsp), %r10
addq $0x10, %rsp
addl %ebx, %ebp
addl (%r13,%r14,4), %ebp
incq %r14
movl %ebp, %ebx
cmpq %r14, (%rsp)
jne 0x1b70
jmp 0x1d25
movl $0x18, 0x14(%rsp)
xorl %r15d, %r15d
movl %r15d, %r12d
sarl $0x3, %r12d
leal (,%rbp,4), %eax
cltq
leaq 0x1c(,%rax,4), %rbx
movq %rbx, %rdi
callq 0x1080
movl %ebx, (%rax)
movl %r14d, 0x4(%rax)
shll $0x14, %ebp
addl $0x180002, %ebp         # imm = 0x180002
movl %ebp, 0x8(%rax)
xorl %edx, %edx
movq 0x8(%rsp), %rcx
cmpl $0x8, %ecx
sete %dl
shll $0x10, %edx
addl $0x10101, %edx          # imm = 0x10101
movl %edx, 0xc(%rax)
movl %r14d, 0x10(%rax)
movl %r12d, 0x14(%rax)
movq %rax, (%rsp)
movl %r14d, 0x18(%rax)
testl %r15d, %r15d
jle 0x1d21
movq %rcx, %r13
xorl %r12d, %r12d
xorl %ebp, %ebp
movslq %ebp, %rax
movslq 0x40(%rsp,%rax,4), %rax
cmpq $-0x1, %rax
je 0x1c88
movl 0x30(%rsp,%rax,4), %edx
movl %edx, %ebx
xorl 0x14(%rsp), %ebx
cmpl %ebp, %ebx
jne 0x1c93
leal 0x1(%r12), %ebx
movq 0x20(%rsp), %rcx
movl (%rcx,%rax,4), %edx
movq 0x18(%rsp), %rcx
movl (%rcx,%rax,4), %r14d
movq (%rsp), %rdi
movl %r12d, %esi
movl %r14d, %ecx
movl %ebp, %r8d
movl $0x1, %r9d
pushq %r13
pushq $0x1
callq 0x18b3
addq $0x10, %rsp
movl %ebx, %r12d
jmp 0x1d15
andl $-0x8, %ebp
addl $0x8, %ebp
jmp 0x1d18
andl $0x7, %edx
movl $0x8, %ecx
subl %edx, %ecx
movq 0x18(%rsp), %rdx
movl (%rdx,%rax,4), %r14d
subl %ecx, %r14d
leal 0x1(%r12), %edx
movl %edx, 0x2c(%rsp)
movq 0x20(%rsp), %rdx
movl (%rdx,%rax,4), %edx
movl %edx, 0x28(%rsp)
movq (%rsp), %r13
movq %r13, %rdi
movl %r12d, %esi
movl %ebx, %r8d
xorl %r9d, %r9d
pushq 0x8(%rsp)
pushq $0x1
callq 0x18b3
addq $0x10, %rsp
movslq %ebx, %rax
movl $0xffffffff, 0x40(%rsp,%rax,4) # imm = 0xFFFFFFFF
addl $0x2, %r12d
movq %r13, %rdi
movl 0x2c(%rsp), %esi
movl 0x28(%rsp), %edx
movq 0x8(%rsp), %r13
movl %r14d, %ecx
movl %ebp, %r8d
movl $0x1, %r9d
pushq %r13
pushq $0x0
callq 0x18b3
addq $0x10, %rsp
addl %r14d, %ebp
cmpl %r15d, %ebp
jl 0x1c2e
movq (%rsp), %r15
movq %r15, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq