// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq -0x2b(%rbp), %r15
movl $0x1, %edx
movq %r15, %rsi
callq 0x2220
leaq -0x2a(%rbp), %r12
movl $0x1, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2220
movzbl (%r15), %r13d
movzbl (%r12), %eax
shll $0x8, %r13d
orl %eax, %r13d
cmpb $0x1, 0x5a2d(%rip)      # 0x91fa
jne 0x381f
movq 0x57fa(%rip), %r15      # 0x8fd0
leaq 0x2a4e(%rip), %rsi      # 0x622b
movl $0xc, %edx
movq %r15, %rdi
callq 0x2210
movl %r13d, %esi
movq %r15, %rdi
callq 0x2110
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
cmpl $0x3, %r13d
jb 0x392b
movl $0x2, %r12d
leaq -0x29(%rbp), %r15
movl %r13d, -0x30(%rbp)
movq %rbx, -0x38(%rbp)
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
movzbl -0x29(%rbp), %r13d
movl %r13d, (%rbx)
leal (,%r13,8), %edi
callq 0x2030
movq %rax, 0x8(%rbx)
testl %r13d, %r13d
je 0x38c6
xorl %r13d, %r13d
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
addl $0x2, %r12d
movq %r14, %rbx
movq %r15, %r14
movzbl -0x29(%rbp), %r15d
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2220
movzbl -0x29(%rbp), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movq -0x38(%rbp), %rsi
movq 0x8(%rsi), %rdx
movl %ecx, (%rdx,%r15,8)
andl $0xf, %eax
movl %eax, 0x4(%rdx,%r15,8)
movq %r14, %r15
movq %rbx, %r14
incl %r13d
cmpl (%rsi), %r13d
jb 0x386c
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
movzbl -0x29(%rbp), %eax
movq -0x38(%rbp), %rbx
movl %eax, 0x10(%rbx)
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
movzbl -0x29(%rbp), %eax
movl %eax, 0x14(%rbx)
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
addl $0x4, %r12d
movzbl -0x29(%rbp), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl %ecx, 0x18(%rbx)
andl $0xf, %eax
movl %eax, 0x1c(%rbx)
movl -0x30(%rbp), %r13d
cmpl %r13d, %r12d
jb 0x383b
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq