// File: /workspace/github_c_makefile_star2_O2/hfiguiere[P]exifprobe/process.c
// Function: process_app3
unsigned long
process_app3(FILE *inptr,unsigned long app3_offset,unsigned short tag,
                struct image_summary *summary_entry,char *parent_name,
                int indent)
{
    unsigned long max_offset = 0UL;
    unsigned long ifd_offset,fileoffset_base;
    unsigned long dumplength = 0UL;
    unsigned short app_length = 0;
    int chpr = 0;
    struct fileheader *header;
    char *app_string,*name;
    char *fulldirname = CNULL;

    if(inptr)
    {
        if(summary_entry)
        {
            summary_entry->filesubformat |= FILESUBFMT_APPN;
            summary_entry->filesubformatAPPN[3] = 1;
        }
        /* display the APP3 header                                    */
        name = tagname(tag);    /* never null                         */
        if(PRINT_SECTION)
        {
            print_tag_address(SECTION,app3_offset,indent,"@");
            chpr += printf("<%s> %#x ",name,tag);
        }

        app_length = read_ushort(inptr,TIFF_MOTOROLA,HERE);
        if(ferror(inptr) || feof(inptr))
        {
            clearerr(inptr);
            goto appdump;
        }
        if(PRINT_SECTION)
            chpr += printf("length %u, ",app_length);
        else if((PRINT_ENTRY))
        {
            /* ###%%% pseudo-tags fpr LIST Mode here */
            print_tag_address(ENTRY,HERE,indent,"*");
            if((PRINT_TAGINFO))
            {
                if((PRINT_LONGNAMES))
                    chpr += printf("%s.",parent_name);
                chpr += printf("%-14.14s","APP3");
            }
            if((PRINT_VALUE))
                chpr += printf(" = @%lu:%-9u",app3_offset,app_length);
            chpr = newline(chpr);
        }

        app_string = read_appstring(inptr,JPEG_APP3,HERE);
        if(ferror(inptr) || feof(inptr))
        {
            clearerr(inptr);
            goto appdump;
        }

        if(app_string)
        {
            if(PRINT_SECTION)
                chpr += printf("\'%s\'",app_string);

            /* The next thing we see should be a TIFF header tag      */
            /* indicating byte order used in the IFD, followed by the */
            /* offset from the start of the header to the start of    */
            /* the IFD (number of entries).                           */

            fileoffset_base = ftell(inptr);
            /* If this is a valid Meta segment, skip the pad byte.    */
            if(strncmp(app_string,"Meta",4) == 0)
            {
                fulldirname = splice(parent_name,".","APP3");
                ++fileoffset_base;
                if(PRINT_SECTION)
                {
                    chpr = newline(chpr);
                    print_tag_address(SECTION,fileoffset_base,indent + SMALLINDENT,"@");
                }
                header = read_imageheader(inptr,fileoffset_base);
                if(header && (print_header(header,SECTION) == 0) &&
                    (header->probe_magic == TIFF_MAGIC))
                {
                    ifd_offset = read_ulong(inptr,header->file_marker,HERE);
                    if(PRINT_SECTION)
                    {
                        chpr += printf(" ifd offset = %lu (+ %lu = %#lx/%lu)",ifd_offset,
                                    fileoffset_base,fileoffset_base + ifd_offset,
                                    fileoffset_base + ifd_offset);
                        chpr = newline(chpr);
                    }
                    max_offset = process_tiff_ifd(inptr,header->file_marker,ifd_offset,
                                            fileoffset_base,0L,summary_entry,fulldirname,
                                            TIFF_IFD,0,-1,indent + SMALLINDENT);

                    if(max_offset < app3_offset + app_length + 2)
                        max_offset = app3_offset + app_length +2;
                }
                else
                {
                    max_offset = app3_offset + app_length + 2;
                    if(PRINT_SECTION)
                    {
                        extraindent(indent + ADDRWIDTH);
                        if(header)
                        {
                            chpr += printf(" INVALID MAGIC %lu (%s) where TIFF header should be",
                                           header->probe_magic,tagname(header->probe_magic));
                        }
                        else
                        {
                            chpr += printf(" INVALID HEADER for TIFF");
                        }
#define PRINT_A_BIT 48
                        if(app_length > PRINT_A_BIT)
                            dumplength = PRINT_A_BIT;
                        else
                            dumplength = app_length;
                        goto appdump;
                    }
                }
                if(fulldirname)
                    free(fulldirname);
            }
            else
            {
                max_offset = app3_offset + app_length + 2;
                if(PRINT_SECTION)
                {
                    chpr += printf(" - unknown format");
                    goto appdump;
                }
            }
        }
        else if(PRINT_SECTION)
        {
            chpr += printf("  No APP3 header name string found");
            chpr = newline(chpr);
        }
        /* offset of last byte of segment                             */
        if(PRINT_SECTION)
        {
            print_tag_address(SECTION,max_offset - 1,indent,"-");
            chpr += printf("</%s>",name);
            chpr = newline(chpr);
        }
    }
    return(max_offset);

appdump:
    if(app_length > 0L)
    {
        if((PRINT_APPNDUMP) || (dumplength > 0))
        {
            if((Max_appdump == DUMPALL) || (Max_appdump > (app_length + 2)))
                dumplength = app_length + 2;
            else if(Max_appdump > 0L)
                dumplength = Max_appdump;
            else if(dumplength == 0)
                dumplength = Max_undefined;
            if(dumplength)
            {
                chpr = newline(1);
                hexdump(inptr,app3_offset,app_length + 2,dumplength,16,
                            indent + SMALLINDENT,SMALLINDENT);
                chpr = newline(1);
            }
        }
        else
        {
            if(PRINT_SEGMENT)
            {
                chpr += printf(" - (not dumped: use -A)");
                chpr = newline(chpr);
            }
        }
        max_offset = app3_offset + app_length + 2;
        /* close off the segment; a start "tag" was printed           */
        print_tag_address(SECTION,app3_offset + app_length + 1,indent,"-");
        if(PRINT_SECTION)
        {
            chpr += printf("</%s>",name);
            chpr = newline(chpr);
        }
    }
    setcharsprinted(chpr);
    return(max_offset);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x28(%rsp)
testq %rdi, %rdi
je 0x1485e
movq %r8, %r13
movq %rcx, %r14
movq %rsi, %r15
movq %rdi, %r12
testq %rcx, %rcx
je 0x1472b
orb $-0x80, 0x19(%r14)
movl $0x1, 0x28(%r14)
movzwl %dx, %ebx
movl %ebx, %edi
callq 0xa1c8
movq %rax, 0x48(%rsp)
leaq 0x42a3f(%rip), %rax     # 0x57180
xorl %ebp, %ebp
testb $0x4, 0x2(%rax)
je 0x14779
leaq 0x2a98c(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq %r15, %rsi
movq 0x28(%rsp), %rdx
callq 0x5100
leaq 0x2eaff(%rip), %rdi     # 0x43268
movq 0x48(%rsp), %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x416a
movl %eax, %ebx
movq %r12, %rdi
callq 0x30b0
movzwl %bx, %ecx
movq %rcx, 0x30(%rsp)
testl %eax, %eax
jne 0x148ae
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x148ae
leaq 0x429c4(%rip), %rax     # 0x57180
movq (%rax), %rax
btl $0x12, %eax
jb 0x14866
testl $0x4003333, %eax        # imm = 0x4003333
je 0x1487b
leaq 0x2b17e(%rip), %rcx     # 0x3f959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq 0x28(%rsp), %rdx
callq 0x5100
leaq 0x4298a(%rip), %rax     # 0x57180
movq (%rax), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x14837
testb $0x40, %al
je 0x14816
leaq 0x2ec9d(%rip), %rdi     # 0x434a7
movq %r13, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq 0x2e884(%rip), %rdi     # 0x430a1
leaq 0x2d282(%rip), %rsi     # 0x41aa6
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq 0x4294c(%rip), %rax     # 0x57180
movq (%rax), %rax
testb $0x30, %al
je 0x14853
leaq 0x2e868(%rip), %rdi     # 0x430aa
movq %r15, %rsi
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
jmp 0x1487b
xorl %r14d, %r14d
jmp 0x149d7
leaq 0x2e828(%rip), %rdi     # 0x43095
movq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %rdi
movl $0xffe3, %esi           # imm = 0xFFE3
callq 0x4c1f
movq %rax, 0x38(%rsp)
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x148ae
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
je 0x149e9
movq %r12, %rdi
callq 0x31b0
xorl %r13d, %r13d
xorl %r14d, %r14d
testw %bx, %bx
je 0x149d0
leaq 0x428b4(%rip), %rax     # 0x57180
movq (%rax), %rax
movl %eax, %ecx
andl $0x400000, %ecx         # imm = 0x400000
orq %r13, %rcx
je 0x14959
leaq 0x43b35(%rip), %rax     # 0x58418
movq (%rax), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
sete %cl
movq 0x30(%rsp), %rdx
leaq 0x2(%rdx), %rbx
cmpq %rbx, %rax
seta %dl
orb %cl, %dl
movq %rbx, %r14
jne 0x14926
movq %rax, %r14
testq %rax, %rax
jne 0x14926
testq %r13, %r13
jne 0x1491e
leaq 0x43aed(%rip), %rax     # 0x58408
movq (%rax), %r13
movq %r13, %r14
testq %r13, %r13
je 0x1497d
pushq $0x1
popq %r13
movl %r13d, %edi
callq 0x160f7
movq 0x28(%rsp), %rax
leal 0x2(%rax), %r9d
movl $0x2, (%rsp)
pushq $0x10
popq %r8
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x6e93
jmp 0x14973
btl $0x13, %eax
jae 0x1497d
leaq 0x2e8ea(%rip), %rdi     # 0x43250
xorl %eax, %eax
callq 0x3120
movl %eax, %r13d
addl %ebp, %r13d
movl %r13d, %edi
callq 0x160f7
movl %eax, %ebp
movq 0x30(%rsp), %rax
leaq (%rax,%r15), %r14
addq $0x2, %r14
leaq 0x1(%rax,%r15), %rsi
leaq 0x2a763(%rip), %rcx     # 0x3f0f9
movl $0x40000, %edi          # imm = 0x40000
movq 0x28(%rsp), %rdx
callq 0x5100
leaq 0x427d4(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x149d0
leaq 0x2b176(%rip), %rdi     # 0x3fb2f
movq 0x48(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
movl %ebp, %edi
callq 0x16a4f
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x42790(%rip), %rax     # 0x57180
movq (%rax), %rax
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
je 0x14a71
btl $0x12, %eax
jae 0x14a16
leaq 0x30b7e(%rip), %rdi     # 0x45588
movq %rcx, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movq %r12, %rdi
callq 0x3190
movq %rax, 0x40(%rsp)
leaq 0x2e8ef(%rip), %rsi     # 0x43319
pushq $0x4
popq %rdx
movq 0x38(%rsp), %rdi
callq 0x3090
testl %eax, %eax
je 0x14a83
movq 0x30(%rsp), %rax
leaq (%r15,%rax), %r14
addq $0x2, %r14
leaq 0x42731(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x14c65
leaq 0x2e884(%rip), %rdi     # 0x432e4
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
jmp 0x148bc
btl $0x12, %eax
jb 0x14b5f
xorl %r14d, %r14d
jmp 0x14c65
leaq 0x2af0d(%rip), %rsi     # 0x3f997
leaq 0x2d015(%rip), %rdx     # 0x41aa6
movq %r13, %rdi
callq 0x16f1d
movq %rax, %rcx
movq 0x40(%rsp), %r13
incq %r13
leaq 0x426d5(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
movq %rcx, 0x38(%rsp)
je 0x14adb
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
movq 0x28(%rsp), %rax
leal 0x2(%rax), %edx
leaq 0x2a60e(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq %r13, %rsi
callq 0x5100
movq %r12, %rdi
movq %r13, 0x40(%rsp)
movq %r13, %rsi
callq 0x3d98
movq %rax, %r13
testq %rax, %rax
je 0x14b3b
movl $0x40000, %esi          # imm = 0x40000
movq %r13, %rdi
callq 0x4cd0
testl %eax, %eax
jne 0x14b3b
cmpq $0x2a, 0x8(%r13)
jne 0x14b3b
movzwl (%r13), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %rdi
callq 0x42ba
movq %rax, %rdx
leaq 0x42659(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
jne 0x14bd8
movq 0x40(%rsp), %rbx
jmp 0x14c0f
movq 0x30(%rsp), %rax
leaq (%r15,%rax), %r14
addq $0x2, %r14
leaq 0x42631(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
jne 0x14b80
movq 0x38(%rsp), %r13
jmp 0x14c5d
leaq 0x2e7b8(%rip), %rdi     # 0x4331e
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
jmp 0x14c65
movq 0x28(%rsp), %rax
leal 0x8(%rax), %edi
callq 0x8f6f
testq %r13, %r13
je 0x14bb5
movq 0x8(%r13), %r13
movzwl %r13w, %edi
callq 0xa1c8
leaq 0x2e6f1(%rip), %rdi     # 0x43297
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3120
jmp 0x14bc3
leaq 0x2e70f(%rip), %rdi     # 0x432cb
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
cmpw $0x30, %bx
pushq $0x30
popq %rax
cmovbl %ebx, %eax
movzwl %ax, %r13d
jmp 0x148bc
movq %rdx, %rcx
movq 0x40(%rsp), %rbx
addq %rbx, %rcx
leaq 0x2e688(%rip), %rdi     # 0x43272
movq %rdx, %rsi
movq %rdx, 0x50(%rsp)
movq %rbx, %rdx
movq %rcx, %r8
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movq 0x50(%rsp), %rdx
movl %eax, %ebp
movzwl (%r13), %esi
movq 0x28(%rsp), %rax
addl $0x2, %eax
orl $-0x1, 0x18(%rsp)
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
movl %eax, 0x20(%rsp)
movq 0x38(%rsp), %r13
movq %r13, (%rsp)
movq %r12, %rdi
movq %rbx, %rcx
xorl %r8d, %r8d
movq %r14, %r9
callq 0xc004
movq 0x30(%rsp), %rcx
leaq (%r15,%rcx), %r14
addq $0x2, %r14
cmpq %r14, %rax
cmovaq %rax, %r14
movq %r13, %rdi
callq 0x3050
leaq 0x42514(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x149d7
leaq -0x1(%r14), %rsi
leaq 0x2a478(%rip), %rcx     # 0x3f0f9
movl $0x40000, %edi          # imm = 0x40000
movq 0x28(%rsp), %rdx
callq 0x5100
leaq 0x2ae98(%rip), %rdi     # 0x3fb2f
movq 0x48(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
jmp 0x149d7