// File: /workspace/github_c_makefile_star2_O3/hfiguiere[P]exifprobe/jp2000.c
// Function: process_jp2_uuid
unsigned long
process_jp2_uuid(FILE *inptr,struct jp2box *box,struct image_summary *summary_entry,
                                                        int indent)
{
    unsigned long boxoffset,max_offset,dataoffset;
    unsigned long boxlength,dumplength;
    unsigned long ifd_offset = 0UL;
    unsigned short idbyte,byte;
    struct fileheader *header = NULL;
    int chpr = 0;
    int i;

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

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

    idbyte = byte = read_ubyte(inptr,dataoffset);
    print_tag_address(SECTION,dataoffset,indent + 4,"*");
    if((LIST_MODE))
    {
        if((PRINT_VALUE))
            chpr += printf(" # ID: ");
    }
    else
        chpr += printf("ID: ");
    if(!(LIST_MODE) || (PRINT_VALUE))
    {
        if(!feof(inptr) && !ferror(inptr))
        {
            chpr += printf("%02x",(unsigned int)byte & 0xff);
            for(i = 1; i < 16; ++i)
            {
                byte = read_ubyte(inptr,HERE);
                if(feof(inptr) || ferror(inptr))
                    break;
                chpr += printf(",%02x",(unsigned int)byte & 0xff);
            }
            chpr = newline(chpr);
        }
    }
    dataoffset += 16;

    /* No idea what the 16 "ID" bytes mean, or how to track           */
    /* registered types through the OID register. For now, a leading  */
    /* byte of 0x5 seems to signal a TIFF IFD. Dump a little bit of   */
    /* anything else. Probably need to check more of the ID...        */

    /* ...ok, now I've seen *two* ids that introduce TIFF sections... */
    if((idbyte != 5) && (idbyte != 0xb1))
    {
        if((PRINT_SECTION))
        {
            dumplength = max_offset - dataoffset;
            if(dumplength > 48)
                dumplength = 48;
            chpr = newline(chpr);
            hexdump(inptr,dataoffset,dumplength,dumplength,16,indent,SUBINDENT);
            chpr = newline(1);
        }
    }

    /* So far I've seen these with recognizable "magic"               */
    /* 96,a9,f1,f1,... MSIG - ??? what is this?                       */
    /* 2c,4c,01,00,... 8BIM Adobe PhotoShop - should handle this...   */
    /* 05,37,cd,ab,... TIFF - this we can do...                       */
    /* b1,4b,f8,bd.... also TIFF                                      */
    header = read_imageheader(inptr,dataoffset);
    if(header && (header->probe_magic == PROBE_TIFFMAGIC))
    {
        if((PRINT_SECTION))
        {
            chpr = newline(chpr);
            print_tag_address(SECTION,dataoffset,indent + 4,"@");
            print_header(header,SECTION);
            ifd_offset = read_ulong(inptr,header->file_marker,HERE); 
            chpr += printf(" ifd offset = %#lx/%lu",ifd_offset,ifd_offset);
            chpr += printf(" (+ %lu = %#lx/%lu)",dataoffset,
                                                    dataoffset + ifd_offset,
                                                    dataoffset + ifd_offset);
            chpr = newline(0);
        }
        dataoffset = process_tiff_ifd(inptr,header->file_marker,
                            8,dataoffset,max_offset,summary_entry,"JP2.uuid",
                            TIFF_IFD,0,-1,indent + 4);
    }
    dataoffset = boxoffset + boxlength;

    if((PRINT_SECTION))
    {
        chpr = newline(0);
        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 $0x28, %rsp
movl %ecx, %r14d
movq %rdx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, %r13
leaq 0x36b0b(%rip), %rax     # 0x58180
movzwl 0x2(%rax), %eax
testl $0x104, %eax            # imm = 0x104
je 0x21693
movq %r13, %rdi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x209e0
xorl %r12d, %r12d
jmp 0x216ae
leaq 0x27625(%rip), %rdx     # 0x48cbf
movq %r13, %rdi
movq %rbx, %rsi
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x20aa9
movl %eax, %r12d
movq 0x18(%rbx), %r15
movq 0x10(%rbx), %rbp
addq %r15, %rbp
addq 0x20(%rbx), %r15
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4d48
movl %eax, 0x4(%rsp)
leal 0x4(%r14), %edx
leaq 0x20282(%rip), %rcx     # 0x41959
movl $0x40000, %edi          # imm = 0x40000
movq %rbp, %rsi
movq %rdx, 0x8(%rsp)
callq 0x55eb
leaq 0x36a90(%rip), %rax     # 0x58180
movq (%rax), %rax
testl $0x1040000, %eax        # imm = 0x1040000
je 0x21703
leaq 0x2768a(%rip), %rdi     # 0x48d8b
jmp 0x2170e
testb $0x30, %al
je 0x21718
leaq 0x2767a(%rip), %rdi     # 0x48d88
xorl %eax, %eax
callq 0x3120
addl %eax, %r12d
leaq 0x36a61(%rip), %rax     # 0x58180
testl $0x1040030, (%rax)      # imm = 0x1040030
movq %rbx, 0x20(%rsp)
movq %r14, 0x10(%rsp)
je 0x217bb
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x217bb
movq %r13, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x217bb
movzbl 0x4(%rsp), %esi
leaq 0x1ffed(%rip), %rdi     # 0x41746
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %r12d, %ebx
movl $0xf, %r14d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r13, %rdi
callq 0x4d48
movl %eax, %r12d
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x217ac
movq %r13, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x217ac
movzbl %r12b, %esi
leaq 0x1ffa7(%rip), %rdi     # 0x41745
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
decl %r14d
jne 0x2176b
movl %ebx, %edi
callq 0x1707a
movl %eax, %r12d
movq 0x10(%rsp), %r14
movl 0x4(%rsp), %eax
addq $0x10, %rbp
cmpw $0x5, %ax
je 0x2182c
movzwl %ax, %eax
cmpl $0xb1, %eax
je 0x2182c
leaq 0x369a6(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x2182c
movq %r15, %rax
subq %rbp, %rax
cmpq $0x30, %rax
movl $0x30, %ebx
cmovbq %rax, %rbx
movl %r12d, %edi
callq 0x1707a
subq $0x8, %rsp
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %rbx, %rcx
movl $0x10, %r8d
movl %r14d, %r9d
pushq $0x2
callq 0x7480
addq $0x10, %rsp
movl $0x1, %edi
callq 0x1707a
movl %eax, %r12d
movq %r13, %rdi
movq %rbp, %rsi
callq 0x41ac
testq %rax, %rax
je 0x21909
movq %rax, %r14
cmpq $0x2a, 0x8(%rax)
jne 0x21909
leaq 0x3692b(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x218d2
movl %r12d, %edi
callq 0x1707a
leaq 0x1f872(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq %rbp, %rsi
movq 0x8(%rsp), %rdx
callq 0x55eb
movl $0x40000, %esi          # imm = 0x40000
movq %r14, %rdi
callq 0x5158
movzwl (%r14), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
callq 0x4707
movq %rax, %rbx
leaq 0x1f83a(%rip), %rdi     # 0x410de
movq %rax, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3120
addq %rbp, %rbx
leaq 0x23a0c(%rip), %rdi     # 0x452c7
movq %rbp, %rsi
movq %rbx, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3120
xorl %edi, %edi
callq 0x1707a
movzwl (%r14), %esi
subq $0x8, %rsp
xorl %eax, %eax
leaq 0x274ad(%rip), %r10     # 0x48d90
movl $0x8, %edx
movq %r13, %rdi
movq %rbp, %rcx
movq %r15, %r8
movq 0x20(%rsp), %r9
pushq 0x10(%rsp)
pushq $-0x1
pushq %rax
pushq %rax
pushq %r10
callq 0xcabc
addq $0x30, %rsp
leaq 0x36870(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x21953
xorl %edi, %edi
callq 0x1707a
movl %eax, %ebx
leaq -0x1(%r15), %rsi
leaq 0x1f7b2(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x10(%rsp), %rdx
callq 0x55eb
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x208ff
movl %ebx, %edi
callq 0x1707a
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq