// File: /workspace/github_c_makefile_star2_O3/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 0x1ee9
cmpl $0x0, 0x58(%rsp)
jne 0x1f08
movq %rcx, %r15
movq %rdx, %r12
movl %esi, %ebp
testl %esi, %esi
movq %r9, 0x10(%rsp)
movq %r8, 0x8(%rsp)
jle 0x1df2
xorl %eax, %eax
xorl %ebx, %ebx
addl (%r12,%rax,4), %ebx
addl (%r15,%rax,4), %ebx
incq %rax
cmpq %rax, %rbp
jne 0x1dbe
testb $0x7, %bl
je 0x1df4
leaq 0x2624(%rip), %rdi      # 0x43fe
leaq 0x2560(%rip), %rsi      # 0x4341
leaq 0x25b1(%rip), %rcx      # 0x4399
movl $0x190, %edx            # imm = 0x190
callq 0x1060
xorl %ebx, %ebx
movl %esi, %r13d
shll $0x4, %r13d
movl %esi, %r14d
shll $0x14, %r14d
addl $0x1c, %r13d
movl $0x1, %edi
movl %esi, 0x4(%rsp)
movq %r13, %rsi
callq 0x1070
addl $0x180002, %r14d        # imm = 0x180002
shrl $0x3, %ebx
movl %r13d, (%rax)
movl %r14d, 0x8(%rax)
movabsq $0x100010002, %rcx      # imm = 0x100010002
movq %rcx, 0xc(%rax)
movzbl %bl, %ecx
movl %ecx, 0x14(%rax)
cmpl $0x0, 0x4(%rsp)
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r13
jle 0x1eda
movq 0x50(%rsp), %rsi
shlq $0x2, %rbp
xorl %edi, %edi
movl $0xffff, %r8d           # imm = 0xFFFF
movl $0xff0000, %r9d         # imm = 0xFF0000
xorl %r10d, %r10d
movl (%r12,%rdi), %edx
movl %edx, %r11d
movl %edx, %ecx
addl %r10d, %edx
andl %r8d, %r10d
shll $0x10, %r11d
addl %r9d, %r11d
andl %r9d, %r11d
movl (%r13,%rdi), %ebx
andl $0xf, %ebx
shll $0x18, %ebx
orl %r10d, %ebx
orl %r11d, %ebx
movl %ebx, 0x1c(%rax,%rdi,4)
movzbl (%r14,%rdi), %r10d
movl (%rsi,%rdi), %r11d
shll $0x8, %r11d
andl %r8d, %r11d
orl %r10d, %r11d
movl %r11d, 0x20(%rax,%rdi,4)
movl $0x0, 0x24(%rax,%rdi,4)
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
shll %cl, %r10d
notl %r10d
movl %r10d, 0x28(%rax,%rdi,4)
addl (%r15,%rdi), %edx
addq $0x4, %rdi
movl %edx, %r10d
cmpq %rdi, %rbp
jne 0x1e6b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x249e(%rip), %rdi      # 0x438e
leaq 0x244a(%rip), %rsi      # 0x4341
leaq 0x249b(%rip), %rcx      # 0x4399
movl $0x18a, %edx            # imm = 0x18A
callq 0x1060
leaq 0x24dd(%rip), %rdi      # 0x43ec
leaq 0x242b(%rip), %rsi      # 0x4341
leaq 0x247c(%rip), %rcx      # 0x4399
movl $0x18b, %edx            # imm = 0x18B
callq 0x1060