// File: /workspace/github_c_makefile_star2_O1/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
movq %rsi, %r15
vmovaps (%rsi), %xmm0
vmovaps %xmm0, 0x20(%rsp)
movl %r8d, 0x14(%rsp)
movl %ecx, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
movq %rdi, %r14
leaq 0x7cb2(%rdi), %rax
movq %rax, (%rsp)
vmovaps 0xd46e(%rip), %xmm0     # 0x33490
vmovaps %xmm0, 0x30(%rsp)
xorl %r12d, %r12d
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x26063
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movswq %cx, %rsi
leaq 0x14a93(%rip), %rdx     # 0x3aae7
xorl %eax, %eax
callq 0x1070
addw %ax, 0x7cb0(%r14)
cmpl $0x3, %r12d
jne 0x26082
vmovaps (%r15), %xmm0
vmovaps %xmm0, 0x20(%rsp)
vmovaps 0xd424(%rip), %xmm0     # 0x334a0
vmovaps %xmm0, 0x30(%rsp)
movq %r14, %rdi
callq 0x2551d
testl %eax, %eax
je 0x2619e
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0x2555d
movl %eax, %r13d
addl $0x8, %r13d
movzbl %r13b, %ebp
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x260e9
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movswq %cx, %rsi
leaq 0x139a7(%rip), %rdx     # 0x39a7f
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1070
addw %ax, 0x7cb0(%r14)
testl %ebp, %ebp
je 0x261ab
movl %r12d, 0x1c(%rsp)
movb %r13b, (%r15)
movl $0x1, %r12d
xorl %eax, %eax
movl $0x0, %r13d
testb $0x1, %al
jne 0x26160
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0x2555d
addl %ebp, %eax
movzbl %al, %r13d
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x2615e
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movswq %cx, %rsi
leaq 0x149a3(%rip), %rdx     # 0x3aaef
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 0xcfed(%rip), %rdx      # 0x33160
movsbq (%r12,%rdx), %rdx
movb %cl, (%r15,%rdx)
incq %r12
movl %r13d, %ebp
cmpq $0x10, %r12
jne 0x26101
vmovaps (%r15), %xmm0
vmovaps %xmm0, 0x20(%rsp)
movl 0x1c(%rsp), %r12d
jmp 0x261bc
vmovaps 0x20(%rsp), %xmm0
vmovaps %xmm0, (%r15)
jmp 0x261bc
vmovaps 0x30(%rsp), %xmm0
vmovaps %xmm0, (%r15)
vmovaps %xmm0, 0x20(%rsp)
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x261f4
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movswq %cx, %rsi
leaq 0x1466b(%rip), %rdx     # 0x3a850
xorl %eax, %eax
callq 0x1070
addw %ax, 0x7cb0(%r14)
incl %r12d
addq $0x10, %r15
cmpl $0x6, %r12d
jne 0x2602b
cmpl $0x0, 0x18(%rsp)
je 0x2645f
xorl %eax, %eax
cmpl $0x3, 0x14(%rsp)
sete %al
leal 0x2(,%rax,4), %eax
movl %eax, 0x20(%rsp)
leaq 0x124c4(%rip), %rbp     # 0x386f0
xorl %r12d, %r12d
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x2626a
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movswq %cx, %rsi
leaq 0x1488f(%rip), %rdx     # 0x3aae7
xorl %eax, %eax
vzeroupper
callq 0x1070
addw %ax, 0x7cb0(%r14)
movq %r14, %rdi
vzeroupper
callq 0x2551d
testl %eax, %eax
je 0x2637f
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0x2555d
movl %eax, %r13d
addl $0x8, %r13d
movzbl %r13b, %r15d
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x262d5
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movswq %cx, %rsi
leaq 0x137bc(%rip), %rdx     # 0x39a7f
movl %r15d, %ecx
xorl %eax, %eax
callq 0x1070
addw %ax, 0x7cb0(%r14)
testl %r15d, %r15d
je 0x263a4
movq 0x8(%rsp), %rdi
movb %r13b, (%rdi)
xorl %ecx, %ecx
movl $0x1, %ebx
xorl %eax, %eax
movl $0x0, %r13d
testb $0x1, %cl
jne 0x26356
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0x2555d
addl %r15d, %eax
movzbl %al, %r13d
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x2634e
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movswq %cx, %rsi
leaq 0x147b3(%rip), %rdx     # 0x3aaef
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,%rbp), %rsi
movb %dl, (%rdi,%rsi)
incq %rbx
movl %r13d, %r15d
cmpq $0x40, %rbx
jne 0x262ef
jmp 0x26408
cmpl $0x2, %r12d
movq 0x8(%rsp), %rdi
jb 0x26408
vmovaps -0x80(%rdi), %xmm0
vmovaps %xmm0, (%rdi)
vmovups -0x70(%rdi), %ymm0
vmovups %ymm0, 0x10(%rdi)
vmovaps -0x50(%rdi), %xmm0
jmp 0x26403
vmovaps 0xd104(%rip), %xmm0     # 0x334b0
testb $0x1, %r12b
movq 0x8(%rsp), %rdi
je 0x263bf
vmovaps 0xd101(%rip), %xmm0     # 0x334c0
vmovaps %xmm0, (%rdi)
vmovaps 0xd105(%rip), %xmm0     # 0x334d0
je 0x263d5
vmovaps 0xd10b(%rip), %xmm0     # 0x334e0
vmovaps %xmm0, 0x10(%rdi)
vmovaps 0xd10e(%rip), %xmm0     # 0x334f0
je 0x263ec
vmovaps 0xd114(%rip), %xmm0     # 0x33500
vmovaps %xmm0, 0x20(%rdi)
vmovaps 0xd117(%rip), %xmm0     # 0x33510
je 0x26403
vmovaps 0xd11d(%rip), %xmm0     # 0x33520
vmovaps %xmm0, 0x30(%rdi)
movzwl 0x7cb0(%r14), %eax
cmpq $0x2541, %rax           # imm = 0x2541
ja 0x26448
movq %rax, %rdi
addq (%rsp), %rdi
movl $0x2542, %ecx           # imm = 0x2542
subl %eax, %ecx
movswq %cx, %rsi
leaq 0x1441f(%rip), %rdx     # 0x3a850
xorl %eax, %eax
vzeroupper
callq 0x1070
movq 0x8(%rsp), %rdi
addw %ax, 0x7cb0(%r14)
incl %r12d
addq $0x40, %rdi
movq %rdi, 0x8(%rsp)
cmpl 0x20(%rsp), %r12d
jne 0x2622f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq