// File: /workspace/github_c_makefile_star2_O3/hfiguiere[P]exifprobe/jp2000.c
// Function: process_jpc_qcd
unsigned long
process_jpc_qcd(FILE *inptr,unsigned long marker_offset,unsigned short tag,
                                    struct image_summary *summary_entry,
                                    int indent)
{
    unsigned long max_offset;
    unsigned short seg_length;
    unsigned short qstyle;
    unsigned short guardbits;
    unsigned short stepsize,rawstepsize;
    char *name;
    int chpr = 0;
    int i;

    name = jp2000tagname(tag);
    seg_length = read_ushort(inptr,TIFF_MOTOROLA,marker_offset +2 );
    print_tag_address(SECTION|ENTRY,marker_offset,indent,"@");

    if((LIST_MODE))
    {
        if((PRINT_TAGINFO))
        {
            if((PRINT_LONGNAMES))
                chpr += printf("JP2.jp2c.");
            chpr += printf("%s",name);
        }
        if((PRINT_VALUE))
            chpr += printf(" = @%lu:%u",marker_offset,seg_length + 2);
    }
    else
        chpr += printf("<%#x=%s> length %u",tag,name,seg_length);
    max_offset = marker_offset + seg_length + 2;
    marker_offset += 4;

    qstyle = read_ubyte(inptr,marker_offset);
    ++marker_offset;
    chpr = newline(chpr);
    print_tag_address(ENTRY,marker_offset,indent + 8,"=");
    if((PRINT_TAGINFO))
    {
        if((PRINT_LONGNAMES))
            chpr += printf("JP2.jp2c.qcd.");
        chpr += printf("QuantizationStyle");
    }
    if((PRINT_VALUE))
    {
        chpr += printf(" = %#x",qstyle & 0xff);
        chpr += printf(" = ");
        if((qstyle & 0x1f) == 0)
            chpr += printf("no quantization");
        else if((qstyle & 0x1f) == 1)
            chpr += printf("implicit quantization");
        else if((qstyle & 0x1f) == 2)
            chpr += printf("explicit quantization");
        guardbits = (qstyle >> 5) & 0x7;

        chpr += printf(", %u guard bit%s",guardbits,guardbits > 1 ? "s" : "");
    }
    /* Record quantization in the second byte of the summary      */
    /* compression                                                */
    if(summary_entry)
        summary_entry->compression |= (((qstyle & 3) << 8) & 0xff00);
    for(i = 0;marker_offset < (max_offset - 1); ++i)
    {
        chpr = newline(chpr);
        print_tag_address(ENTRY,marker_offset,indent + 8,"=");
        if((qstyle & 0x1f) == 0)
        {
            rawstepsize = read_ubyte(inptr,marker_offset);
            stepsize = rawstepsize >> 3;
            if(stepsize & ~0x1f)
            {
                PUSHCOLOR(RED);
                print_tag_address(ENTRY,marker_offset,indent + SUBINDENT,"@");
                chpr += printf("# WARNING: stepsize exponent %d out of range (%#x => %#x)",
                                                                    i,rawstepsize,stepsize);
                POPCOLOR();
                marker_offset++;
                continue;
                break;
            }
            stepsize <<= 11;
            if((PRINT_TAGINFO))
            {
                if((PRINT_LONGNAMES))
                    chpr += printf("JP2.jp2c.");
                chpr += printf("qcd.Stepsize[%d]",i);
            }
            if((PRINT_VALUE))
                chpr += printf(" = %#x -> %u",rawstepsize,stepsize);
            marker_offset++;
        }
        else
        {
            stepsize = read_ushort(inptr,TIFF_MOTOROLA,marker_offset);
            marker_offset += 2;
            if((PRINT_TAGINFO))
            {
                if((PRINT_LONGNAMES))
                    chpr += printf("JP2.jp2c.qcd.");
                chpr += printf("Stepsize[%d]",i);
            }
            if((PRINT_VALUE))
                chpr += printf(" = %u",stepsize);
        }
    }
    if(!(LIST_MODE))
    {
        chpr = newline(chpr);
        print_tag_address(SECTION|ENTRY,marker_offset - 1,indent,"@");
        chpr += printf("</%#x=%s> ",tag,name);
    }
    if(marker_offset > max_offset)
        printred(" READ PAST END OF BOX");
    chpr = newline(chpr);

    return(max_offset);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, %r15d
movq %rcx, 0x18(%rsp)
movl %edx, %ebx
movq %rsi, %r12
movq %rdi, %r13
movl %edx, %edi
callq 0xc94f
movq %rax, %r14
leaq 0x2(%r12), %rdx
movq %r13, 0x10(%rsp)
movq %r13, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x45af
movl %eax, %ebp
leaq 0x1bd9a(%rip), %rcx     # 0x410dc
movl $0x4043333, %edi        # imm = 0x4043333
movq %r12, %rsi
movl %r15d, %edx
callq 0x55eb
leaq 0x32e27(%rip), %rax     # 0x58180
movq (%rax), %rax
movzwl %bp, %r13d
movzwl %bx, %esi
testl $0x1040000, %eax        # imm = 0x1040000
movq %r14, 0x40(%rsp)
movl %esi, 0x20(%rsp)
movq %r13, 0x30(%rsp)
je 0x25391
leaq 0x23bfb(%rip), %rdi     # 0x48f7a
movq %r14, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
jmp 0x253f0
testl $0x3003, %eax           # imm = 0x3003
je 0x253d1
xorl %ebx, %ebx
testb $0x40, %al
je 0x253ae
leaq 0x23ba3(%rip), %rdi     # 0x48f48
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
leaq 0x1bce2(%rip), %rdi     # 0x41097
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl %ebx, %r14d
leaq 0x32db4(%rip), %rax     # 0x58180
movq (%rax), %rax
jmp 0x253d4
xorl %r14d, %r14d
testb $0x30, %al
je 0x253f0
leal 0x2(%r13), %edx
leaq 0x23b8c(%rip), %rdi     # 0x48f6f
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
leaq 0x4(%r12), %rsi
movq 0x10(%rsp), %rdi
callq 0x4d48
movl %eax, 0xc(%rsp)
movq %r12, 0x38(%rsp)
leaq 0x5(%r12), %rbp
movl %r14d, %edi
callq 0x1707a
movl %eax, %r13d
leal 0x8(%r15), %edx
leaq 0x1f5a2(%rip), %rcx     # 0x449c5
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl %edx, 0x24(%rsp)
callq 0x55eb
leaq 0x32d45(%rip), %rax     # 0x58180
movq (%rax), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x25475
testb $0x40, %al
je 0x2545a
leaq 0x23e83(%rip), %rdi     # 0x492d3
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
leaq 0x23e80(%rip), %rdi     # 0x492e1
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
leaq 0x32d0e(%rip), %rax     # 0x58180
movq (%rax), %rax
movq 0x10(%rsp), %r12
testb $0x30, %al
movq %r15, 0x28(%rsp)
je 0x25512
movzwl 0xc(%rsp), %ebx
movzbl %bl, %esi
leaq 0x23c6e(%rip), %rdi     # 0x49104
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl %r13d, %r15d
leaq 0x250fe(%rip), %rdi     # 0x4a5a8
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl %r15d, %r14d
andl $0x1f, %ebx
cmpl $0x2, %ebx
ja 0x254d9
movl %ebx, %eax
leaq 0x23e94(%rip), %rcx     # 0x4935c
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
movl 0xc(%rsp), %esi
shrl $0x5, %esi
andl $0x7, %esi
cmpw $0x2, %si
leaq 0x1bbaa(%rip), %rax     # 0x41098
leaq 0x227e1(%rip), %rdx     # 0x47cd6
cmovaeq %rax, %rdx
leaq 0x23df3(%rip), %rdi     # 0x492f3
xorl %eax, %eax
callq 0x3120
movl %eax, %r13d
addl %r14d, %r13d
movq 0x28(%rsp), %r15
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax), %rbx
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
je 0x2553a
movl 0xc(%rsp), %eax
andl $0x3, %eax
shll $0x8, %eax
orl %eax, 0xc8(%rcx)
incq %rbx
cmpq %rbx, %rbp
jae 0x256ce
leal 0x2(%r15), %eax
movl %eax, 0x18(%rsp)
xorl %r15d, %r15d
movl %r13d, %edi
callq 0x1707a
movl %eax, %r13d
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl 0x24(%rsp), %edx
leaq 0x1f456(%rip), %rcx     # 0x449c5
callq 0x55eb
testb $0x1f, 0xc(%rsp)
je 0x255f8
movq %r12, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %rbp, %rdx
callq 0x45af
movl %eax, %r14d
leaq 0x32beb(%rip), %rax     # 0x58180
movq (%rax), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x255d2
testb $0x40, %al
je 0x255b4
leaq 0x23d29(%rip), %rdi     # 0x492d3
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
leaq 0x23d87(%rip), %rdi     # 0x49342
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
leaq 0x32bb1(%rip), %rax     # 0x58180
movq (%rax), %rax
addq $0x2, %rbp
testb $0x30, %al
je 0x256c2
movzwl %r14w, %esi
leaq 0x1f9b5(%rip), %rdi     # 0x44f9e
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
jmp 0x256c2
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4d48
movzwl %ax, %r12d
movl %r12d, %eax
shrl $0x3, %eax
movzwl %ax, %r14d
cmpl $0x100, %r12d           # imm = 0x100
jae 0x25688
leaq 0x32b5f(%rip), %rax     # 0x58180
movq (%rax), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x2565e
testb $0x40, %al
je 0x25640
leaq 0x23912(%rip), %rdi     # 0x48f48
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
leaq 0x23cf7(%rip), %rdi     # 0x4933e
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
leaq 0x32b25(%rip), %rax     # 0x58180
movq (%rax), %rax
testb $0x30, %al
je 0x2567e
shll $0xb, %r14d
movzwl %r14w, %edx
leaq 0x23cde(%rip), %rdi     # 0x4934f
movl %r12d, %esi
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
movq 0x10(%rsp), %r12
incq %rbp
jmp 0x256c2
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl 0x18(%rsp), %edx
leaq 0x1ba41(%rip), %rcx     # 0x410dc
callq 0x55eb
leaq 0x23c5d(%rip), %rdi     # 0x49304
movl %r15d, %esi
movl %r12d, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
incq %rbp
movq 0x10(%rsp), %r12
incl %r15d
cmpq %rbx, %rbp
jb 0x25551
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax), %rbx
addq $0x2, %rbx
leaq 0x32a99(%rip), %rax     # 0x58180
movzwl 0x2(%rax), %eax
testl $0x104, %eax            # imm = 0x104
je 0x25734
movl %r13d, %edi
callq 0x1707a
movl %eax, %r14d
leaq -0x1(%rbp), %rsi
leaq 0x1b9d4(%rip), %rcx     # 0x410dc
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x28(%rsp), %rdx
callq 0x55eb
leaq 0x239ab(%rip), %rdi     # 0x490c9
movl 0x20(%rsp), %esi
movq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %r13d
addl %r14d, %r13d
cmpq %rbx, %rbp
jbe 0x25745
leaq 0x23994(%rip), %rdi     # 0x490d4
callq 0x5c26
movl %r13d, %edi
callq 0x1707a
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop