// File: /workspace/github_c_makefile_star2_O1/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 0x370d0(%rip), %rax     # 0x58180
movzwl 0x2(%rax), %eax
testl $0x104, %eax            # imm = 0x104
je 0x210ce
movq %r13, %rdi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x2041a
xorl %r12d, %r12d
jmp 0x210e9
leaq 0x27baa(%rip), %rdx     # 0x48c7f
movq %r13, %rdi
movq %rbx, %rsi
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x204e6
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 0x4d44
movl %eax, 0x4(%rsp)
leal 0x4(%r14), %edx
leaq 0x20847(%rip), %rcx     # 0x41959
movl $0x40000, %edi          # imm = 0x40000
movq %rbp, %rsi
movq %rdx, 0x8(%rsp)
callq 0x5605
leaq 0x37055(%rip), %rax     # 0x58180
movq (%rax), %rax
testl $0x1040000, %eax        # imm = 0x1040000
je 0x2113e
leaq 0x27c0f(%rip), %rdi     # 0x48d4b
jmp 0x21149
testb $0x30, %al
je 0x21153
leaq 0x27bff(%rip), %rdi     # 0x48d48
xorl %eax, %eax
callq 0x3120
addl %eax, %r12d
leaq 0x37026(%rip), %rax     # 0x58180
testl $0x1040030, (%rax)      # imm = 0x1040030
movq %rbx, 0x20(%rsp)
movq %r14, 0x10(%rsp)
je 0x211f6
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x211f6
movq %r13, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x211f6
movzbl 0x4(%rsp), %esi
leaq 0x205b2(%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 0x4d44
movl %eax, %r12d
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x211e7
movq %r13, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x211e7
movzbl %r12b, %esi
leaq 0x2056c(%rip), %rdi     # 0x41745
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
decl %r14d
jne 0x211a6
movl %ebx, %edi
callq 0x16b56
movl %eax, %r12d
movq 0x10(%rsp), %r14
movl 0x4(%rsp), %eax
addq $0x10, %rbp
cmpw $0x5, %ax
je 0x21267
movzwl %ax, %eax
cmpl $0xb1, %eax
je 0x21267
leaq 0x36f6b(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x21267
movq %r15, %rax
subq %rbp, %rax
cmpq $0x30, %rax
movl $0x30, %ebx
cmovbq %rax, %rbx
movl %r12d, %edi
callq 0x16b56
subq $0x8, %rsp
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %rbx, %rcx
movl $0x10, %r8d
movl %r14d, %r9d
pushq $0x2
callq 0x7446
addq $0x10, %rsp
movl $0x1, %edi
callq 0x16b56
movl %eax, %r12d
movq %r13, %rdi
movq %rbp, %rsi
callq 0x418c
testq %rax, %rax
je 0x21344
movq %rax, %r14
cmpq $0x2a, 0x8(%rax)
jne 0x21344
leaq 0x36ef0(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x2130d
movl %r12d, %edi
callq 0x16b56
leaq 0x1fe37(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq %rbp, %rsi
movq 0x8(%rsp), %rdx
callq 0x5605
movl $0x40000, %esi          # imm = 0x40000
movq %r14, %rdi
callq 0x5198
movzwl (%r14), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
callq 0x46cc
movq %rax, %rbx
leaq 0x1fdff(%rip), %rdi     # 0x410de
movq %rax, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3120
addq %rbp, %rbx
leaq 0x23f8d(%rip), %rdi     # 0x45283
movq %rbp, %rsi
movq %rbx, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3120
xorl %edi, %edi
callq 0x16b56
movzwl (%r14), %esi
subq $0x8, %rsp
xorl %eax, %eax
leaq 0x27a32(%rip), %r10     # 0x48d50
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 0xc93c
addq $0x30, %rsp
leaq 0x36e35(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x2138e
xorl %edi, %edi
callq 0x16b56
movl %eax, %ebx
leaq -0x1(%r15), %rsi
leaq 0x1fd77(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x10(%rsp), %rdx
callq 0x5605
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x2033b
movl %ebx, %edi
callq 0x16b56
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq