// File: /workspace/github_c_makefile_star2_O2/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 0x36e50(%rip), %rax     # 0x57180
movzwl 0x2(%rax), %eax
testw $0x104, %ax             # imm = 0x104
je 0x2034d
movq %r13, %rdi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x1f71d
xorl %r12d, %r12d
jmp 0x20368
leaq 0x2691b(%rip), %rdx     # 0x46c6f
movq %r13, %rdi
movq %rbx, %rsi
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x1f7e6
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 0x48de
movl %eax, 0x4(%rsp)
leal 0x4(%r14), %edx
leaq 0x1f5c8(%rip), %rcx     # 0x3f959
movl $0x40000, %edi          # imm = 0x40000
movq %rbp, %rsi
movq %rdx, 0x8(%rsp)
callq 0x5100
leaq 0x36dd6(%rip), %rax     # 0x57180
movq (%rax), %rax
testl $0x1040000, %eax        # imm = 0x1040000
je 0x203bd
leaq 0x26980(%rip), %rdi     # 0x46d3b
jmp 0x203c8
testb $0x30, %al
je 0x203d2
leaq 0x26970(%rip), %rdi     # 0x46d38
xorl %eax, %eax
callq 0x3120
addl %eax, %r12d
leaq 0x36da7(%rip), %rax     # 0x57180
testl $0x1040030, (%rax)      # imm = 0x1040030
movq %rbx, 0x20(%rsp)
movq %r14, 0x10(%rsp)
je 0x20476
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x20476
movq %r13, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x20476
movzbl 0x4(%rsp), %esi
leaq 0x1f333(%rip), %rdi     # 0x3f746
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %r12d, %ebx
pushq $0xf
popq %r14
subl $0x1, %r14d
jb 0x20467
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r13, %rdi
callq 0x48de
movl %eax, %r12d
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x20467
movq %r13, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x20467
movzbl %r12b, %esi
leaq 0x1f2e9(%rip), %rdi     # 0x3f745
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
jmp 0x20423
movl %ebx, %edi
callq 0x160f7
movl %eax, %r12d
movq 0x10(%rsp), %r14
movl 0x4(%rsp), %eax
addq $0x10, %rbp
cmpw $0x5, %ax
je 0x204df
movzwl %ax, %eax
cmpl $0xb1, %eax
je 0x204df
leaq 0x36ceb(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x204df
movq %r15, %rax
subq %rbp, %rax
cmpq $0x30, %rax
pushq $0x30
popq %rbx
cmovbq %rax, %rbx
movl %r12d, %edi
callq 0x160f7
subq $0x8, %rsp
pushq $0x10
popq %r8
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %rbx, %rcx
movl %r14d, %r9d
pushq $0x2
callq 0x6e93
popq %rax
popq %rcx
pushq $0x1
popq %rdi
callq 0x160f7
movl %eax, %r12d
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3d98
testq %rax, %rax
je 0x205b9
movq %rax, %r14
cmpq $0x2a, 0x8(%rax)
jne 0x205b9
leaq 0x36c78(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x20585
movl %r12d, %edi
callq 0x160f7
leaq 0x1ebbf(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq %rbp, %rsi
movq 0x8(%rsp), %rdx
callq 0x5100
movl $0x40000, %esi          # imm = 0x40000
movq %r14, %rdi
callq 0x4cd0
movzwl (%r14), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
callq 0x42ba
movq %rax, %rbx
leaq 0x1eb87(%rip), %rdi     # 0x3f0de
movq %rax, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3120
addq %rbp, %rbx
leaq 0x22d15(%rip), %rdi     # 0x43283
movq %rbp, %rsi
movq %rbx, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3120
xorl %edi, %edi
callq 0x160f7
movzwl (%r14), %esi
subq $0x8, %rsp
leaq 0x267ac(%rip), %rax     # 0x46d40
pushq $0x8
popq %rdx
movq %r13, %rdi
movq %rbp, %rcx
movq %r15, %r8
movq 0x20(%rsp), %r9
pushq 0x10(%rsp)
pushq $-0x1
pushq $0x0
pushq $0x0
pushq %rax
callq 0xc004
addq $0x30, %rsp
leaq 0x36bc0(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x20601
xorl %edi, %edi
callq 0x160f7
movl %eax, %ebx
leaq -0x1(%r15), %rsi
leaq 0x1eb02(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x10(%rsp), %rdx
callq 0x5100
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x1f649
movl %ebx, %edi
callq 0x160f7
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq