// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movl %r8d, %r12d
movq %rcx, 0x20(%rsp)
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r13
movl %edx, %edi
callq 0xbe97
movq %rax, %r15
leaq 0x2(%r14), %rdx
movq %r13, 0x8(%rsp)
movq %r13, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x416a
movl %eax, %ebp
leaq 0x1b1ca(%rip), %rcx     # 0x3f0dc
movl $0x4043333, %edi        # imm = 0x4043333
movq %r14, %rsi
movq %r12, 0x18(%rsp)
movl %r12d, %edx
callq 0x5100
leaq 0x33252(%rip), %rax     # 0x57180
movq (%rax), %rax
movzwl %bp, %ebp
movzwl %bx, %esi
testl $0x1040000, %eax        # imm = 0x1040000
movq %r15, 0x30(%rsp)
movl %esi, 0x28(%rsp)
je 0x23f5e
leaq 0x22fdc(%rip), %rdi     # 0x46f2a
movq %r15, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
jmp 0x23fbd
testw $0x3003, %ax            # imm = 0x3003
je 0x23fa1
movq %rbp, %r12
xorl %ebp, %ebp
testb $0x40, %al
je 0x23f7d
leaq 0x22f84(%rip), %rdi     # 0x46ef8
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
leaq 0x1b113(%rip), %rdi     # 0x3f097
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
leaq 0x331e7(%rip), %rax     # 0x57180
movq (%rax), %rax
movq %r12, %rbp
jmp 0x23fa3
xorl %ebx, %ebx
testb $0x30, %al
je 0x23fbd
leal 0x2(%rbp), %edx
leaq 0x22f6e(%rip), %rdi     # 0x46f1f
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x4(%r14), %rsi
movq 0x8(%rsp), %rdi
callq 0x48de
movl %eax, 0x4(%rsp)
leaq 0x5(%r14), %r12
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
movq 0x18(%rsp), %rax
leal 0x8(%rax), %edx
leaq 0x1e996(%rip), %rcx     # 0x42981
movl $0x4003333, %edi        # imm = 0x4003333
movq %r12, %rsi
movl %edx, 0x2c(%rsp)
callq 0x5100
leaq 0x3317d(%rip), %rax     # 0x57180
movq (%rax), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x2403a
testb $0x40, %al
je 0x24020
leaq 0x2326c(%rip), %rdi     # 0x47283
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x2326a(%rip), %rdi     # 0x47291
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x33149(%rip), %rax     # 0x57180
movq (%rax), %rax
testb $0x30, %al
je 0x240d3
movq %rbp, 0x10(%rsp)
movzwl 0x4(%rsp), %r13d
movzbl %r13b, %esi
leaq 0x2305c(%rip), %rdi     # 0x470b4
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl %ebx, %r15d
leaq 0x244ec(%rip), %rdi     # 0x48558
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
addl %r15d, %ebp
andl $0x1f, %r13d
cmpl $0x2, %r13d
ja 0x2409c
movl %r13d, %eax
leaq 0x23280(%rip), %rcx     # 0x4730c
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl 0x4(%rsp), %esi
shrl $0x5, %esi
andl $0x7, %esi
cmpw $0x2, %si
leaq 0x1afe7(%rip), %rax     # 0x3f098
leaq 0x21bce(%rip), %rdx     # 0x45c86
cmovaeq %rax, %rdx
leaq 0x231e0(%rip), %rdi     # 0x472a3
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
movq 0x10(%rsp), %rbp
leaq (%r14,%rbp), %r13
movq 0x20(%rsp), %rcx
testq %rcx, %rcx
je 0x240f1
movl 0x4(%rsp), %eax
andl $0x3, %eax
shll $0x8, %eax
orl %eax, 0xc8(%rcx)
leaq (%r14,%rbp), %rax
addq $0x2, %rax
movq %rax, 0x10(%rsp)
incq %r13
movq 0x18(%rsp), %rax
addl $0x2, %eax
movl %eax, 0x20(%rsp)
xorl %r15d, %r15d
movq 0x8(%rsp), %r14
cmpq %r13, %r12
jae 0x24285
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
movl $0x4003333, %edi        # imm = 0x4003333
movq %r12, %rsi
movl 0x2c(%rsp), %edx
leaq 0x1e847(%rip), %rcx     # 0x42981
callq 0x5100
testb $0x1f, 0x4(%rsp)
je 0x241bd
movq %r14, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r12, %rdx
callq 0x416a
movl %eax, %ebp
leaq 0x33021(%rip), %rax     # 0x57180
movq (%rax), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x24199
testb $0x40, %al
je 0x2417c
leaq 0x23110(%rip), %rdi     # 0x47283
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x2316f(%rip), %rdi     # 0x472f2
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x32fea(%rip), %rax     # 0x57180
movq (%rax), %rax
addq $0x2, %r12
testb $0x30, %al
je 0x2427d
movzwl %bp, %esi
leaq 0x1edab(%rip), %rdi     # 0x42f5a
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
jmp 0x2427d
movq %r14, %rdi
movq %r12, %rsi
callq 0x48de
movzwl %ax, %r14d
movl %r14d, %eax
shrl $0x3, %eax
movzwl %ax, %ebp
cmpw $0x100, %r14w           # imm = 0x100
jae 0x24245
leaq 0x32f9c(%rip), %rax     # 0x57180
movq (%rax), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x2421e
testb $0x40, %al
je 0x24201
leaq 0x22d00(%rip), %rdi     # 0x46ef8
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x230e6(%rip), %rdi     # 0x472ee
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x32f65(%rip), %rax     # 0x57180
movq (%rax), %rax
testb $0x30, %al
je 0x2423b
shll $0xb, %ebp
movzwl %bp, %edx
leaq 0x230d0(%rip), %rdi     # 0x472ff
movl %r14d, %esi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq 0x8(%rsp), %r14
incq %r12
jmp 0x2427d
movl $0x4003333, %edi        # imm = 0x4003333
movq %r12, %rsi
movl 0x20(%rsp), %edx
leaq 0x1ae84(%rip), %rcx     # 0x3f0dc
callq 0x5100
leaq 0x23050(%rip), %rdi     # 0x472b4
movl %r15d, %esi
movl %r14d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
incq %r12
movq 0x8(%rsp), %r14
incl %r15d
jmp 0x24115
leaq 0x32ef4(%rip), %rax     # 0x57180
movzwl 0x2(%rax), %eax
testw $0x104, %ax             # imm = 0x104
je 0x242d5
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebp
leaq -0x1(%r12), %rsi
leaq 0x1ae31(%rip), %rcx     # 0x3f0dc
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x18(%rsp), %rdx
callq 0x5100
leaq 0x22db8(%rip), %rdi     # 0x47079
movl 0x28(%rsp), %esi
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
movq 0x10(%rsp), %r14
cmpq %r14, %r12
jbe 0x242eb
leaq 0x22d9e(%rip), %rdi     # 0x47084
callq 0x56e2
movl %ebx, %edi
callq 0x160f7
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq