// File: /workspace/github_c_makefile_star2_O2/hfiguiere[P]exifprobe/jp2000.c
// Function: process_jp2_ihdr
unsigned long
process_jp2_ihdr(FILE *inptr,struct jp2box *box,struct image_summary *summary_entry,
                                                        int indent)
{
    unsigned long boxoffset,max_offset,dataoffset;
    unsigned long boxlength;
    unsigned long imgheight = 0UL;
    unsigned long imgwidth = 0UL;
    unsigned short nc = 0;
    unsigned short bpc = 0;
    unsigned short comp = 0;
    unsigned short hasUNK = 0;
    unsigned short hasIPR = 0;
    int chpr = 0;

    if((LIST_MODE))
        chpr = list_jp2box(inptr,box,"JP2.jp2h.",indent,1);
    else
        print_jp2box(inptr,box,indent);
    boxoffset = box->boxoffset;
    boxlength = box->boxlength;

    dataoffset = boxoffset + box->dataoffset;
    max_offset = boxoffset + boxlength;

    imgheight = read_ulong(inptr,TIFF_MOTOROLA,dataoffset);
    print_tag_address(ENTRY,dataoffset,indent + 8,"=");
    if((PRINT_TAGINFO))
    {
        if((PRINT_LONGNAMES))
            chpr += printf("JP2.jp2h.ihdr.");
        chpr += printf("ImageHeight");
    }
    if((PRINT_VALUE))
        chpr += printf(" = %lu",imgheight);
    chpr = newline(chpr);
    dataoffset += 4;

    imgwidth = read_ulong(inptr,TIFF_MOTOROLA,dataoffset);
    print_tag_address(ENTRY,dataoffset,indent + 8,"=");
    if((PRINT_TAGINFO))
    {
        if((PRINT_LONGNAMES))
            chpr += printf("JP2.jp2h.ihdr.");
        chpr += printf("ImageWidth");
    }
    if((PRINT_VALUE))
        chpr += printf(" = %lu",imgwidth);
    chpr = newline(chpr);
    dataoffset += 4;
    if(summary_entry && (imgheight > 0) &&
                            (summary_entry->pixel_height < imgheight))
    {
        summary_entry->pixel_height = imgheight;
    }
    if(summary_entry && (imgwidth > 0) &&
                            (summary_entry->pixel_width < imgwidth))
    {
        summary_entry->pixel_width = imgwidth;
    }

    nc = read_ushort(inptr,TIFF_MOTOROLA,dataoffset);
    print_tag_address(ENTRY,dataoffset,indent + 8,"=");
    if((PRINT_TAGINFO))
    {
        if((PRINT_LONGNAMES))
            chpr += printf("JP2.jp2h.ihdr.");
        chpr += printf("NumberOfComponents");
    }
    if((PRINT_VALUE))
        chpr += printf(" = %u",nc);
    chpr = newline(chpr);
    dataoffset += 2;

    bpc = read_ubyte(inptr,dataoffset);
    print_tag_address(ENTRY,dataoffset,indent + 8,"=");
    if((PRINT_TAGINFO))
    {
        if((PRINT_LONGNAMES))
            chpr += printf("JP2.jp2h.ihdr.");
        chpr += printf("BitsPerComponent");
    }
    if((PRINT_VALUE))
        chpr += printf(" = %u",bpc);
    chpr = newline(chpr);
    dataoffset++;

    comp = read_ubyte(inptr,dataoffset);
    print_tag_address(ENTRY,dataoffset,indent + 8,"=");
    if((PRINT_TAGINFO))
    {
        if((PRINT_LONGNAMES))
            chpr += printf("JP2.jp2h.ihdr.");
        chpr += printf("Compression");
    }
    if((PRINT_VALUE))
        chpr += printf(" = %u",comp);
    chpr = newline(chpr);
    /* This is always 7 according to spec, and tells us nothing;  */
    /* it will be over-written with the transform type from a COD */
    /* segement, if one is found. I imagine that "extensions" to  */
    /* the spec will quickly overwhelm this.                      */
    if((summary_entry) && (summary_entry->compression <= 0))
        summary_entry->compression = comp;
    dataoffset++;

    hasUNK = read_ubyte(inptr,dataoffset);
    print_tag_address(ENTRY,dataoffset,indent + 8,"=");
    if((PRINT_TAGINFO))
    {
        if((PRINT_LONGNAMES))
            chpr += printf("JP2.jp2h.ihdr.");
        chpr += printf("Colorspace");
    }
    if((PRINT_VALUE))
            chpr += printf(" = %#x = %sknown",hasUNK,hasUNK ? "un" : "");
    chpr = newline(chpr);
    dataoffset++;

    hasIPR = read_ubyte(inptr,dataoffset);
    print_tag_address(ENTRY,dataoffset,indent + 8,"=");
    if((PRINT_TAGINFO))
    {
        if((PRINT_LONGNAMES))
            chpr += printf("JP2.jp2h.ihdr.");
        chpr += printf("IPRbox");
    }
        if((PRINT_VALUE))
            chpr += printf(" = %#x = %s",hasIPR,hasIPR ? "yes" : "no");
    chpr = newline(chpr);
    dataoffset++;

    if((PRINT_SECTION))
    {
        print_tag_address(SECTION,dataoffset - 1,indent,"@");
        print_jp2type(box->tbox,1);
        chpr = newline(chpr);
    }
    return(max_offset);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %ebp
movq %rdx, 0x18(%rsp)
movq %rsi, %r14
movq %rdi, %r15
leaq 0x3692e(%rip), %r13     # 0x57180
movzwl 0x2(%r13), %eax
testw $0x104, %ax             # imm = 0x104
je 0x2086e
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x1f71d
xorl %ebx, %ebx
jmp 0x20888
leaq 0x26450(%rip), %rdx     # 0x46cc5
pushq $0x1
popq %r8
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %ecx
callq 0x1f7e6
movl %eax, %ebx
movq 0x18(%r14), %rax
movq 0x20(%r14), %rcx
movq %rcx, 0x28(%rsp)
movq %r14, 0x20(%rsp)
movq 0x10(%r14), %r12
movq %rax, 0x30(%rsp)
addq %rax, %r12
movq %r15, 0x10(%rsp)
movq %r15, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r12, %rdx
callq 0x42ba
movq %rax, %r15
leal 0x8(%rbp), %edx
leaq 0x220b9(%rip), %rcx     # 0x42981
movl $0x4003333, %edi        # imm = 0x4003333
movq %r12, %rsi
movl %edx, 0xc(%rsp)
callq 0x5100
movq (%r13), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x2090b
testb $0x40, %al
je 0x208f7
leaq 0x263e1(%rip), %rdi     # 0x46ccf
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x2b5a6(%rip), %rdi     # 0x4bea4
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq (%r13), %rax
movq %rbp, %r13
testb $0x30, %al
je 0x20925
leaq 0x1e7b2(%rip), %rdi     # 0x3f0cb
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
leaq 0x4(%r12), %rbp
movq 0x10(%rsp), %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %rbp, %rdx
callq 0x42ba
movq %rax, %r14
leaq 0x22032(%rip), %rcx     # 0x42981
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl 0xc(%rsp), %edx
callq 0x5100
leaq 0x36819(%rip), %rax     # 0x57180
movq (%rax), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x2099e
testb $0x40, %al
je 0x20984
leaq 0x26354(%rip), %rdi     # 0x46ccf
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x2b507(%rip), %rdi     # 0x4be92
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x367e5(%rip), %rax     # 0x57180
movq (%rax), %rax
movq %r13, %rbp
testb $0x30, %al
je 0x209b8
leaq 0x1e71f(%rip), %rdi     # 0x3f0cb
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x367c1(%rip), %r13     # 0x57180
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
movq 0x18(%rsp), %rdx
testq %rdx, %rdx
setne %al
testq %r15, %r15
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x209ea
cmpq %r15, 0x78(%rdx)
jae 0x209ea
movq %r15, 0x78(%rdx)
leaq 0x8(%r12), %r15
testq %rdx, %rdx
je 0x20a03
testq %r14, %r14
je 0x20a03
cmpq %r14, 0x70(%rdx)
jae 0x20a03
movq %r14, 0x70(%rdx)
movq 0x10(%rsp), %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r15, %rdx
callq 0x416a
movl %eax, %r14d
leaq 0x21f62(%rip), %rcx     # 0x42981
movl $0x4003333, %edi        # imm = 0x4003333
movq %r15, %rsi
movl 0xc(%rsp), %edx
callq 0x5100
movq (%r13), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x20a62
testb $0x40, %al
je 0x20a4e
leaq 0x2628a(%rip), %rdi     # 0x46ccf
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x26289(%rip), %rdi     # 0x46cde
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq (%r13), %rax
testb $0x30, %al
je 0x20a7a
movzwl %r14w, %esi
leaq 0x224e9(%rip), %rdi     # 0x42f5a
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
leaq 0xa(%r12), %r15
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x48de
movl %eax, %r14d
leaq 0x21ee2(%rip), %rcx     # 0x42981
movl $0x4003333, %edi        # imm = 0x4003333
movq %r15, %rsi
movl 0xc(%rsp), %edx
callq 0x5100
movq (%r13), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x20ae2
testb $0x40, %al
je 0x20ace
leaq 0x2620a(%rip), %rdi     # 0x46ccf
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x2621c(%rip), %rdi     # 0x46cf1
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq (%r13), %rax
testb $0x30, %al
je 0x20afa
movzwl %r14w, %esi
leaq 0x22469(%rip), %rdi     # 0x42f5a
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
leaq 0xb(%r12), %r15
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x48de
movl %eax, %r14d
leaq 0x21e62(%rip), %rcx     # 0x42981
movl $0x4003333, %edi        # imm = 0x4003333
movq %r15, %rsi
movl 0xc(%rsp), %edx
callq 0x5100
movq (%r13), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x20b62
testb $0x40, %al
je 0x20b4e
leaq 0x2618a(%rip), %rdi     # 0x46ccf
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x1fcdc(%rip), %rdi     # 0x40831
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq (%r13), %rax
movzwl %r14w, %r14d
testb $0x30, %al
je 0x20b7d
leaq 0x223e9(%rip), %rdi     # 0x42f5a
movl %r14d, %esi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x20ba0
cmpl $0x0, 0xc8(%rax)
jg 0x20ba0
movl %r14d, 0xc8(%rax)
leaq 0xc(%r12), %r15
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x48de
movl %eax, %r14d
leaq 0x21dc5(%rip), %rcx     # 0x42981
movl $0x4003333, %edi        # imm = 0x4003333
movq %r15, %rsi
movl 0xc(%rsp), %edx
callq 0x5100
movq (%r13), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x20bff
testb $0x40, %al
je 0x20beb
leaq 0x260ed(%rip), %rdi     # 0x46ccf
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x26110(%rip), %rdi     # 0x46d02
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq (%r13), %rax
movq 0x10(%rsp), %r15
testb $0x30, %al
je 0x20c31
movzwl %r14w, %esi
testw %si, %si
leaq 0x25070(%rip), %rax     # 0x45c86
leaq 0x26101(%rip), %rdx     # 0x46d1e
cmoveq %rax, %rdx
leaq 0x260e5(%rip), %rdi     # 0x46d0d
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
addq $0xd, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x48de
movl %eax, %r14d
leaq 0x21d2e(%rip), %rcx     # 0x42981
movl $0x4003333, %edi        # imm = 0x4003333
movq %r12, %rsi
movl 0xc(%rsp), %edx
callq 0x5100
movq (%r13), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x20c96
testb $0x40, %al
je 0x20c82
leaq 0x26056(%rip), %rdi     # 0x46ccf
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x26098(%rip), %rdi     # 0x46d21
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq (%r13), %rax
testb $0x30, %al
je 0x20cc3
movzwl %r14w, %esi
testw %si, %si
leaq 0x2aeb9(%rip), %rax     # 0x4bb61
leaq 0x26085(%rip), %rdx     # 0x46d34
cmoveq %rax, %rdx
leaq 0x2606e(%rip), %rdi     # 0x46d28
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x160f7
testb $0x4, 0x2(%r13)
je 0x20d01
movl %eax, %ebx
leaq 0x1e402(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq %r12, %rsi
movl %ebp, %edx
callq 0x5100
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x1f649
movl %ebx, %edi
callq 0x160f7
movq 0x28(%rsp), %rax
addq 0x30(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq