// File: /workspace/github_cpp_makefile_star2_O2/qhan1028[P]JPEG-Decoder/jpeg-decoder.cpp
// Function: process_SOS(std::basic_ifstream<char, std::char_traits<char>>&, sos&)
bool process_SOS(ifstream& jpegfile, sos_t& sos) {
    unsigned int pointer = 0;
    char c, c1, c2;

    /* SOS length */
    jpegfile.read(&c1, 1); pointer++;
    jpegfile.read(&c2, 1); pointer++;
    unsigned int len = to_num(c1, c2);

    if (debug)
        cout << "[SOS] len = " << len << endl;

    while (pointer < len) {
        /* number of channels */
        jpegfile.read(&c, 1); pointer++;
        sos.ns = to_uint(c);

        sos.cda = new cda_t[sos.ns];

        /* information of color channels */
        for (unsigned int i = 0; i < sos.ns; i++) {
            jpegfile.read(&c, 1); pointer++;
            unsigned int cs = to_uint(c);

            jpegfile.read(&c, 1); pointer++;
            unsigned int tdta = to_uint(c);
            sos.cda[cs].td = tdta >> 4;
            sos.cda[cs].ta = tdta & 0x0F;
        }

        /* other information */
        jpegfile.read(&c, 1); pointer++;
        sos.ss = to_uint(c);

        jpegfile.read(&c, 1); pointer++;
        sos.se = to_uint(c);

        jpegfile.read(&c, 1); pointer++;
        unsigned int ahal = to_uint(c);
        sos.ah = ahal >> 4;
        sos.al = ahal & 0x0F;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, -0x40(%rbp)
movq %rdi, %rbx
leaq -0x2b(%rbp), %r13
pushq $0x1
popq %r12
movq %r13, %rsi
movq %r12, %rdx
callq 0x21f0
leaq -0x2a(%rbp), %r15
movq %rbx, -0x48(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x21f0
movzbl (%r13), %ecx
movzbl (%r15), %eax
shll $0x8, %ecx
orl %eax, %ecx
movl %ecx, -0x30(%rbp)
cmpb $0x1, 0x5f1d(%rip)      # 0x91da
jne 0x32e5
movq 0x5d0a(%rip), %rdi      # 0x8fd0
leaq 0x2f5e(%rip), %rsi      # 0x622b
callq 0x2190
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20e0
pushq $0x2
popq %r13
leaq -0x29(%rbp), %r14
pushq $0x1
popq %rbx
movq -0x48(%rbp), %rax
cmpl -0x30(%rbp), %r13d
jae 0x33d7
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x21f0
movzbl -0x29(%rbp), %r12d
movq -0x40(%rbp), %r15
movl %r12d, (%r15)
leal (,%r12,8), %edi
callq 0x2030
movq %rax, 0x8(%r15)
addl $0x4, %r13d
movl %r13d, -0x34(%rbp)
movq -0x48(%rbp), %r13
xorl %r15d, %r15d
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x21f0
cmpl %r12d, %r15d
jae 0x3387
movzbl -0x29(%rbp), %r12d
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x21f0
movzbl -0x29(%rbp), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movq -0x40(%rbp), %rsi
movq 0x8(%rsi), %rdx
movl %ecx, (%rdx,%r12,8)
andl $0xf, %eax
movl %eax, 0x4(%rdx,%r12,8)
incl %r15d
movl (%rsi), %r12d
addl $0x2, -0x34(%rbp)
jmp 0x3338
movzbl -0x29(%rbp), %eax
movq -0x40(%rbp), %r15
movl %eax, 0x10(%r15)
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x21f0
movzbl -0x29(%rbp), %eax
movl %eax, 0x14(%r15)
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x21f0
movzbl -0x29(%rbp), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl %ecx, 0x18(%r15)
andl $0xf, %eax
movl %eax, 0x1c(%r15)
movq %r13, %rax
movl -0x34(%rbp), %r13d
jmp 0x32f4
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq