// File: lukasz-wiecaszek[P]h264iframedecoder/h264_decoder.cpp
// Function: ymn::h264_decoder::init_chroma_qp_tables()
void h264_decoder::init_chroma_qp_tables()
{
    const int depth = m_active_sps->bit_depth_luma_minus8;
    const int max_qp = 51 + 6 * depth;
    int offset;

#define QP(qp, depth) ((qp) + 6 * (depth))
#define CHROMA_QP_TABLE_END(d)                                        \
    QP(0,  d), QP(1,  d), QP(2,  d), QP(3,  d), QP(4,  d), QP(5,  d), \
    QP(6,  d), QP(7,  d), QP(8,  d), QP(9,  d), QP(10, d), QP(11, d), \
    QP(12, d), QP(13, d), QP(14, d), QP(15, d), QP(16, d), QP(17, d), \
    QP(18, d), QP(19, d), QP(20, d), QP(21, d), QP(22, d), QP(23, d), \
    QP(24, d), QP(25, d), QP(26, d), QP(27, d), QP(28, d), QP(29, d), \
    QP(29, d), QP(30, d), QP(31, d), QP(32, d), QP(32, d), QP(33, d), \
    QP(34, d), QP(34, d), QP(35, d), QP(35, d), QP(36, d), QP(36, d), \
    QP(37, d), QP(37, d), QP(37, d), QP(38, d), QP(38, d), QP(38, d), \
    QP(39, d), QP(39, d), QP(39, d), QP(39, d)

    /* One chroma qp table for each supported bit depth (8, 9, 10). */
    static const uint8_t chroma_qp[3][H264_QP_MAX + 1] =
    {
        {CHROMA_QP_TABLE_END(0)},
        {0, 1, 2, 3, 4, 5, CHROMA_QP_TABLE_END(1)},
        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, CHROMA_QP_TABLE_END(2)}
    };

    offset = m_active_pps->chroma_qp_index_offset;
    for (int q = 0; q < max_qp + 1; ++q)
        m_chroma_qp_table[0][q] = chroma_qp[depth][std::clamp(q + offset, 0, max_qp)];

    offset = m_active_pps->second_chroma_qp_index_offset;
    for (int q = 0; q < max_qp + 1; ++q)
        m_chroma_qp_table[1][q] = chroma_qp[depth][std::clamp(q + offset, 0, max_qp)];

#undef CHROMA_QP_TABLE_END
#undef QP
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x88358(%rax), %rcx
movl 0x18(%rcx), %ecx
movl %ecx, 0x3c(%rsp)
imull $0x6, 0x3c(%rsp), %ecx
addl $0x33, %ecx
movl %ecx, 0x38(%rsp)
movq 0x88360(%rax), %rax
movl 0x440(%rax), %eax
movl %eax, 0x34(%rsp)
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
movl 0x38(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1a591
movslq 0x3c(%rsp), %rcx
leaq 0xdadf(%rip), %rax      # 0x28010
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movl 0x30(%rsp), %eax
addl 0x34(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
leaq 0x2c(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0x19190
movq 0x8(%rsp), %rcx
movq %rax, %rdx
movq 0x10(%rsp), %rax
movslq (%rdx), %rdx
movb (%rcx,%rdx), %dl
movslq 0x30(%rsp), %rcx
movb %dl, 0xa63d0(%rax,%rcx)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x1a516
movq 0x10(%rsp), %rax
movq 0x88360(%rax), %rax
movl 0x708(%rax), %eax
movl %eax, 0x34(%rsp)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movl 0x38(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1a628
movslq 0x3c(%rsp), %rcx
leaq 0xda46(%rip), %rax      # 0x28010
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, (%rsp)
movl 0x24(%rsp), %eax
addl 0x34(%rsp), %eax
movl %eax, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0x19190
movq (%rsp), %rcx
movq %rax, %rdx
movq 0x10(%rsp), %rax
movslq (%rdx), %rdx
movb (%rcx,%rdx), %dl
movslq 0x24(%rsp), %rcx
movb %dl, 0xa6410(%rax,%rcx)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1a5af
addq $0x48, %rsp
retq
nopl (%rax)