// File: /workspace/github_c_makefile_star2_O2/KhronosGroup[P]dfdutils/createdfd.c
// Function: createDFD422
uint32_t *createDFD422(int bigEndian, int numSamples,
                       int bits[], int paddings[], int channels[],
                       int position_xs[], int position_ys[],
                       enum VkSuffix suffix) {
    assert(!bigEndian); (void) bigEndian;
    assert(suffix == s_UNORM); (void) suffix;

    int totalBits = 0;
    for (int i = 0; i < numSamples; ++i)
        totalBits += bits[i] + paddings[i];
    assert(totalBits % 8 == 0);

    uint32_t BDFDSize = sizeof(uint32_t) * (KHR_DF_WORD_SAMPLESTART + numSamples * KHR_DF_WORD_SAMPLEWORDS);
    uint32_t DFDSize = sizeof(uint32_t) + BDFDSize;
    uint32_t *DFD = (uint32_t *) malloc(DFDSize);
    memset(DFD, 0, DFDSize);
    DFD[0] = DFDSize;
    uint32_t *BDFD = DFD + 1;
    KHR_DFDSETVAL(BDFD, VENDORID, KHR_DF_VENDORID_KHRONOS);
    KHR_DFDSETVAL(BDFD, DESCRIPTORTYPE, KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT);
    KHR_DFDSETVAL(BDFD, VERSIONNUMBER, KHR_DF_VERSIONNUMBER_LATEST);
    KHR_DFDSETVAL(BDFD, DESCRIPTORBLOCKSIZE, BDFDSize);
    KHR_DFDSETVAL(BDFD, MODEL, KHR_DF_MODEL_YUVSDA);
    KHR_DFDSETVAL(BDFD, PRIMARIES, KHR_DF_PRIMARIES_UNSPECIFIED);
    KHR_DFDSETVAL(BDFD, TRANSFER, KHR_DF_TRANSFER_LINEAR);
    KHR_DFDSETVAL(BDFD, FLAGS, KHR_DF_FLAG_ALPHA_STRAIGHT);
    KHR_DFDSETVAL(BDFD, TEXELBLOCKDIMENSION0, 2 - 1); // 422 contains 2 x 1 blocks
    KHR_DFDSETVAL(BDFD, TEXELBLOCKDIMENSION1, 1 - 1);
    KHR_DFDSETVAL(BDFD, TEXELBLOCKDIMENSION2, 1 - 1);
    KHR_DFDSETVAL(BDFD, TEXELBLOCKDIMENSION3, 1 - 1);
    KHR_DFDSETVAL(BDFD, BYTESPLANE0, totalBits / 8);
    KHR_DFDSETVAL(BDFD, BYTESPLANE1, 0);
    KHR_DFDSETVAL(BDFD, BYTESPLANE2, 0);
    KHR_DFDSETVAL(BDFD, BYTESPLANE3, 0);
    KHR_DFDSETVAL(BDFD, BYTESPLANE4, 0);
    KHR_DFDSETVAL(BDFD, BYTESPLANE5, 0);
    KHR_DFDSETVAL(BDFD, BYTESPLANE6, 0);
    KHR_DFDSETVAL(BDFD, BYTESPLANE7, 0);

    int bitOffset = 0;
    for (int i = 0; i < numSamples; ++i) {
        KHR_DFDSETSVAL(BDFD, i, BITOFFSET, bitOffset);
        KHR_DFDSETSVAL(BDFD, i, BITLENGTH, bits[i] - 1);
        KHR_DFDSETSVAL(BDFD, i, CHANNELID, channels[i]);
        KHR_DFDSETSVAL(BDFD, i, QUALIFIERS, 0); // None of: FLOAT, SIGNED, EXPONENT, LINEAR
        KHR_DFDSETSVAL(BDFD, i, SAMPLEPOSITION0, position_xs[i]);
        KHR_DFDSETSVAL(BDFD, i, SAMPLEPOSITION1, position_ys[i]);
        KHR_DFDSETSVAL(BDFD, i, SAMPLEPOSITION2, 0);
        KHR_DFDSETSVAL(BDFD, i, SAMPLEPOSITION3, 0);
        KHR_DFDSETSVAL(BDFD, i, SAMPLELOWER, 0);
        KHR_DFDSETSVAL(BDFD, i, SAMPLEUPPER, (1u << bits[i]) - 1u);
        bitOffset += bits[i] + paddings[i];
    }

    return DFD;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testl %edi, %edi
jne 0x1db7
cmpl $0x0, 0x58(%rsp)
jne 0x1dd6
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
xorl %eax, %eax
testl %esi, %esi
movl $0x0, %ebp
cmovgl %esi, %ebp
xorl %r13d, %r13d
cmpq %rax, %rbp
je 0x1cc8
addl (%r12,%rax,4), %r13d
addl (%r15,%rax,4), %r13d
incq %rax
jmp 0x1cb6
testb $0x7, %r13b
jne 0x1df5
movl %esi, %eax
shll $0x4, %eax
shll $0x14, %esi
movl %esi, 0xc(%rsp)
addl $0x1c, %eax
movq %rax, 0x10(%rsp)
pushq $0x1
popq %rdi
movq %rax, %rsi
callq 0x1070
movq 0x10(%rsp), %rcx
movl %ecx, (%rax)
movl 0xc(%rsp), %ecx
addl $0x180002, %ecx         # imm = 0x180002
movl %ecx, 0x8(%rax)
movabsq $0x100010002, %rcx      # imm = 0x100010002
movq %rcx, 0xc(%rax)
shrl $0x3, %r13d
movzbl %r13b, %ecx
movl %ecx, 0x14(%rax)
shlq $0x2, %rbp
xorl %edx, %edx
movl $0xffff, %esi           # imm = 0xFFFF
movl $0xff0000, %edi         # imm = 0xFF0000
pushq $-0x1
popq %r8
xorl %r9d, %r9d
cmpq %rdx, %rbp
je 0x1da8
movl %r9d, %r10d
andl %esi, %r10d
movl (%r12,%rdx), %ecx
movl %ecx, %r11d
shll $0x10, %r11d
addl %edi, %r11d
andl %edi, %r11d
movl (%r14,%rdx), %r13d
andl $0xf, %r13d
shll $0x18, %r13d
orl %r10d, %r13d
orl %r11d, %r13d
movl %r13d, 0x1c(%rax,%rdx,4)
movzbl (%rbx,%rdx), %r10d
movq 0x50(%rsp), %r11
movl (%r11,%rdx), %r11d
shll $0x8, %r11d
andl %esi, %r11d
orl %r10d, %r11d
movl %r11d, 0x20(%rax,%rdx,4)
andl $0x0, 0x24(%rax,%rdx,4)
movl %r8d, %r10d
shll %cl, %r10d
addl %r9d, %ecx
notl %r10d
movl %r10d, 0x28(%rax,%rdx,4)
addl (%r15,%rdx), %ecx
addq $0x4, %rdx
movl %ecx, %r9d
jmp 0x1d35
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25c0(%rip), %rdi      # 0x437e
leaq 0x256c(%rip), %rsi      # 0x4331
leaq 0x25bd(%rip), %rcx      # 0x4389
movl $0x18a, %edx            # imm = 0x18A
callq 0x1060
leaq 0x25ff(%rip), %rdi      # 0x43dc
leaq 0x254d(%rip), %rsi      # 0x4331
leaq 0x259e(%rip), %rcx      # 0x4389
movl $0x18b, %edx            # imm = 0x18B
callq 0x1060
leaq 0x25f2(%rip), %rdi      # 0x43ee
leaq 0x252e(%rip), %rsi      # 0x4331
leaq 0x257f(%rip), %rcx      # 0x4389
movl $0x190, %edx            # imm = 0x190
callq 0x1060