// File: /workspace/github_c_makefile_star2_O3/tvlabs[P]edge264/edge264_headers.c
// Function: parse_scaling_lists
static void parse_scaling_lists(Edge264Decoder *dec, i8x16 *w4x4, i8x16 *w8x8, int transform_8x8_mode_flag, int chroma_format_idc)
{
	i8x16 fb4x4 = *w4x4; // fall-back
	i8x16 d4x4 = Default_4x4_Intra; // for useDefaultScalingMatrixFlag
	for (int i = 0; i < 6; i++, w4x4++) {
		log_dec(dec, "    - [");
		if (i == 3) {
			fb4x4 = *w4x4;
			d4x4 = Default_4x4_Inter;
		}
		if (!get_u1(&dec->_gb)) { // scaling_list_present_flag
			*w4x4 = fb4x4;
		} else {
			unsigned nextScale = (8 + get_se16(&dec->_gb, -128, 127)) & 255;
			log_dec(dec, "%u", nextScale);
			if (nextScale == 0) {
				*w4x4 = fb4x4 = d4x4;
			} else {
				for (unsigned j = 0, lastScale;;) {
					((uint8_t *)w4x4)[((int8_t *)scan_4x4)[j]] = nextScale ?: lastScale;
					if (++j >= 16)
						break;
					if (nextScale != 0) {
						lastScale = nextScale;
						nextScale = (nextScale + get_se16(&dec->_gb, -128, 127)) & 255;
						log_dec(dec, ",%u", nextScale);
					}
				}
				fb4x4 = *w4x4;
			}
		}
		log_dec(dec, "]\n");
	}
	
	// For 8x8 scaling lists, we really have no better choice than pointers.
	if (!transform_8x8_mode_flag)
		return;
	for (int i = 0; i < (chroma_format_idc == 3 ? 6 : 2); i++, w8x8 += 4) {
		log_dec(dec, "    - [");
		if (!get_u1(&dec->_gb)) {
			if (i >= 2) {
				w8x8[0] = w8x8[-8];
				w8x8[1] = w8x8[-7];
				w8x8[2] = w8x8[-6];
				w8x8[3] = w8x8[-5];
			}
		} else {
			unsigned nextScale = (8 + get_se16(&dec->_gb, -128, 127)) & 255;
			log_dec(dec, "%u", nextScale);
			if (nextScale == 0) {
				const i8x16 *d8x8 = (i % 2 == 0) ? Default_8x8_Intra : Default_8x8_Inter;
				w8x8[0] = d8x8[0];
				w8x8[1] = d8x8[1];
				w8x8[2] = d8x8[2];
				w8x8[3] = d8x8[3];
			} else {
				for (unsigned j = 0, lastScale = 0;;) {
					((uint8_t *)w8x8)[((int8_t *)scan_8x8_cabac)[j]] = nextScale ?: lastScale;
					if (++j >= 64)
						break;
					if (nextScale != 0) {
						lastScale = nextScale;
						nextScale = (nextScale + get_se16(&dec->_gb, -128, 127)) & 255;
						log_dec(dec, ",%u", nextScale);
					}
				}
			}
		}
		log_dec(dec, "]\n");
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, 0x14(%rsp)
movl %ecx, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, %r14
vmovaps (%rsi), %xmm0
vmovaps %xmm0, 0x20(%rsp)
leaq 0x7cb2(%rdi), %rax
movq %rax, (%rsp)
movzwl 0x7cb0(%rdi), %eax
vmovaps 0xcccf(%rip), %xmm0     # 0x335a0
vmovaps %xmm0, 0x30(%rsp)
xorl %r15d, %r15d
movzwl %ax, %eax
cmpl $0x2541, %eax           # imm = 0x2541
ja 0x2690b
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movzwl %cx, %esi
leaq 0x1436b(%rip), %rdx     # 0x3ac67
xorl %eax, %eax
callq 0x1070
addw %ax, 0x7cb0(%r14)
cmpl $0x3, %r15d
jne 0x2692b
vmovaps (%r12), %xmm0
vmovaps %xmm0, 0x20(%rsp)
vmovaps 0xcc8b(%rip), %xmm0     # 0x335b0
vmovaps %xmm0, 0x30(%rsp)
movq %r14, %rdi
callq 0x25dac
testl %eax, %eax
je 0x26a47
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0x25dec
movl %eax, %r13d
addl $0x8, %r13d
movzbl %r13b, %ebp
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x26991
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movzwl %cx, %esi
leaq 0x1327f(%rip), %rdx     # 0x39bff
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1070
addw %ax, 0x7cb0(%r14)
testl %ebp, %ebp
je 0x26a55
movl %r15d, 0x1c(%rsp)
movb %r13b, (%r12)
movl $0x1, %r15d
xorl %eax, %eax
movl $0x0, %r13d
testb $0x1, %al
jne 0x26a08
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0x25dec
addl %ebp, %eax
movzbl %al, %r13d
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x26a06
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movzwl %cx, %esi
leaq 0x1427b(%rip), %rdx     # 0x3ac6f
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1070
addw %ax, 0x7cb0(%r14)
movl %ebp, %ebx
testl %r13d, %r13d
sete %al
movl %r13d, %ecx
cmovel %ebx, %ecx
leaq 0xc845(%rip), %rdx      # 0x33260
movsbq (%r15,%rdx), %rdx
movb %cl, (%r12,%rdx)
incq %r15
movl %r13d, %ebp
cmpq $0x10, %r15
jne 0x269aa
vmovaps (%r12), %xmm0
vmovaps %xmm0, 0x20(%rsp)
movl 0x1c(%rsp), %r15d
jmp 0x26a67
vmovaps 0x20(%rsp), %xmm0
vmovaps %xmm0, (%r12)
jmp 0x26a67
vmovaps 0x30(%rsp), %xmm0
vmovaps %xmm0, (%r12)
vmovaps %xmm0, 0x20(%rsp)
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x26aa5
movq (%rsp), %rcx
leaq (%rcx,%rax), %rdi
movl $0x2542, %esi           # imm = 0x2542
subq %rax, %rsi
leaq 0x13f42(%rip), %rdx     # 0x3a9d0
xorl %eax, %eax
callq 0x1070
addw 0x7cb0(%r14), %ax
movw %ax, 0x7cb0(%r14)
incl %r15d
addq $0x10, %r12
cmpl $0x6, %r15d
jne 0x268da
cmpl $0x0, 0x18(%rsp)
je 0x26d09
xorl %ecx, %ecx
cmpl $0x3, 0x14(%rsp)
sete %cl
leal 0x2(,%rcx,4), %ecx
movl %ecx, 0x20(%rsp)
leaq 0x11d83(%rip), %r12     # 0x38860
xorl %ebp, %ebp
movzwl %ax, %eax
cmpl $0x2541, %eax           # imm = 0x2541
ja 0x26b13
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movzwl %cx, %esi
leaq 0x14166(%rip), %rdx     # 0x3ac67
xorl %eax, %eax
vzeroupper
callq 0x1070
addw %ax, 0x7cb0(%r14)
movq %r14, %rdi
vzeroupper
callq 0x25dac
testl %eax, %eax
je 0x26c26
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0x25dec
movl %eax, %r13d
addl $0x8, %r13d
movzbl %r13b, %r15d
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x26b7d
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movzwl %cx, %esi
leaq 0x13094(%rip), %rdx     # 0x39bff
movl %r15d, %ecx
xorl %eax, %eax
callq 0x1070
addw %ax, 0x7cb0(%r14)
testl %r15d, %r15d
je 0x26c4a
movq 0x8(%rsp), %rdi
movb %r13b, (%rdi)
xorl %ecx, %ecx
movl $0x1, %ebx
xorl %eax, %eax
movl $0x0, %r13d
testb $0x1, %cl
jne 0x26bfd
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0x25dec
addl %r15d, %eax
movzbl %al, %r13d
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x26bf5
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movzwl %cx, %esi
leaq 0x1408c(%rip), %rdx     # 0x3ac6f
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1070
addw %ax, 0x7cb0(%r14)
movl %r15d, %eax
movq 0x8(%rsp), %rdi
testl %r13d, %r13d
sete %cl
movl %r13d, %edx
cmovel %eax, %edx
movsbq (%rbx,%r12), %rsi
movb %dl, (%rdi,%rsi)
incq %rbx
movl %r13d, %r15d
cmpq $0x40, %rbx
jne 0x26b97
jmp 0x26cae
cmpl $0x2, %ebp
movq 0x8(%rsp), %rdi
jb 0x26cae
vmovaps -0x80(%rdi), %xmm0
vmovaps %xmm0, (%rdi)
vmovups -0x70(%rdi), %ymm0
vmovups %ymm0, 0x10(%rdi)
vmovaps -0x50(%rdi), %xmm0
jmp 0x26ca9
vmovaps 0xc96e(%rip), %xmm0     # 0x335c0
testb $0x1, %bpl
movq 0x8(%rsp), %rdi
je 0x26c65
vmovaps 0xc96b(%rip), %xmm0     # 0x335d0
vmovaps %xmm0, (%rdi)
vmovaps 0xc96f(%rip), %xmm0     # 0x335e0
je 0x26c7b
vmovaps 0xc975(%rip), %xmm0     # 0x335f0
vmovaps %xmm0, 0x10(%rdi)
vmovaps 0xc978(%rip), %xmm0     # 0x33600
je 0x26c92
vmovaps 0xc97e(%rip), %xmm0     # 0x33610
vmovaps %xmm0, 0x20(%rdi)
vmovaps 0xc981(%rip), %xmm0     # 0x33620
je 0x26ca9
vmovaps 0xc987(%rip), %xmm0     # 0x33630
vmovaps %xmm0, 0x30(%rdi)
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x26cf4
movq (%rsp), %rcx
leaq (%rcx,%rax), %rdi
movl $0x2542, %esi           # imm = 0x2542
subq %rax, %rsi
leaq 0x13cfb(%rip), %rdx     # 0x3a9d0
xorl %eax, %eax
vzeroupper
callq 0x1070
movq 0x8(%rsp), %rdi
addw 0x7cb0(%r14), %ax
movw %ax, 0x7cb0(%r14)
incl %ebp
addq $0x40, %rdi
movq %rdi, 0x8(%rsp)
cmpl 0x20(%rsp), %ebp
jne 0x26adf
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq