// File: /workspace/github_c_makefile_star2_O0/albinoloverats[P]hide/src/jpeg-load.c
// Function: ParseSOS
static int ParseSOS(stJpegData *jdata, const uint8_t *stream)
{
	/*
	 * SOS          16              0xffd8                  Start Of Scan
	 * Ls           16              2Ns + 6                 Scan header length
	 * Ns           8               1-4                     Number of image components
	 * Csj          8               0-255                   Scan Component Selector
	 * Tdj          4               0-1                     DC Coding Table Selector
	 * Taj          4               0-1                     AC Coding Table Selector
	 * Ss           8               0                       Start of spectral selection
	 * Se           8               63                      End of spectral selection
	 * Ah           4               0                       Successive Approximation Bit High
	 * Ai           4               0                       Successive Approximation Bit Low
	 */

	uint32_t nr_components = stream[2];

	if (nr_components != 3)
	{
		fprintf(stderr, "Fail @ %s:%d\n", __FILE__, __LINE__);
		exit(-1);
	}

	stream += 3;
	for (uint32_t i = 0; i < nr_components; i++)
	{
		uint32_t cid = *stream++;
		uint32_t table = *stream++;

		if ((table & 0xf) >= 4)
		{
			fprintf(stderr, "Fail @ %s:%d\n", __FILE__, __LINE__);
			exit(-1);
		}
		if ((table >> 4) >= 4)
		{
			fprintf(stderr, "Fail @ %s:%d\n", __FILE__, __LINE__);
			exit(-1);
		}

		jdata->m_component_info[cid].m_acTable = &jdata->m_HTAC[table & 0xf];
		jdata->m_component_info[cid].m_dcTable = &jdata->m_HTDC[table >> 4];
	}
	jdata->m_stream = stream + 3;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, -0x14(%rbp)
cmpl $0x3, -0x14(%rbp)
je 0x239f
movq 0x6c80(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4d6e(%rip), %rsi      # 0x70f0
leaq 0x4d75(%rip), %rdx      # 0x70fe
movl $0x18e, %ecx            # imm = 0x18E
movb $0x0, %al
callq 0x10e0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1150
movq -0x10(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x24d4
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
andl $0xf, %eax
cmpl $0x4, %eax
jb 0x2421
movq 0x6bfe(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4cec(%rip), %rsi      # 0x70f0
leaq 0x4cf3(%rip), %rdx      # 0x70fe
movl $0x19a, %ecx            # imm = 0x19A
movb $0x0, %al
callq 0x10e0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1150
movl -0x20(%rbp), %eax
shrl $0x4, %eax
cmpl $0x4, %eax
jb 0x245a
movq 0x6bc5(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4cb3(%rip), %rsi      # 0x70f0
leaq 0x4cba(%rip), %rdx      # 0x70fe
movl $0x19f, %ecx            # imm = 0x19F
movb $0x0, %al
callq 0x10e0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1150
movq -0x8(%rbp), %rcx
addq $0xcf20, %rcx           # imm = 0xCF20
movl -0x20(%rbp), %eax
andl $0xf, %eax
movl %eax, %eax
imulq $0x3118, %rax, %rax     # imm = 0x3118
addq %rax, %rcx
movq -0x8(%rbp), %rax
addq $0x20, %rax
movl -0x1c(%rbp), %edx
imulq $0xa8, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rcx
addq $0xac0, %rcx            # imm = 0xAC0
movl -0x20(%rbp), %eax
shrl $0x4, %eax
movl %eax, %eax
imulq $0x3118, %rax, %rax     # imm = 0x3118
addq %rax, %rcx
movq -0x8(%rbp), %rax
addq $0x20, %rax
movl -0x1c(%rbp), %edx
imulq $0xa8, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x23b2
movq -0x10(%rbp), %rcx
addq $0x3, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)