// File: /workspace/github_c_makefile_star2_O3/hfiguiere[P]exifprobe/process.c
// Function: process_app1
unsigned long
process_app1(FILE *inptr,unsigned long app1_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[1] = 1;
        }
        /* display the APP1 header                                    */
        name = tagname(tag);    /* never null                         */
        if(PRINT_SECTION)
        {
            print_tag_address(SECTION,app1_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","APP1");
            }
            if((PRINT_VALUE))
                chpr += printf(" = @%lu:%-9u",app1_offset,app_length);
            chpr = newline(chpr);
        }

        app_string = read_appstring(inptr,JPEG_APP1,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 Exif segment, skip the pad byte.    */
            if(strncmp(app_string,"Exif",4) == 0)
            {
                fulldirname = splice(parent_name,".","APP1");
                ++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);
                    }
                    /* ###%%% maybe should unlock the summary entry,  */
                    /* so that the tiff processor will use it? not    */
                    /* sure if that's appropriate for APP1 found in   */
                    /* jpeg sub-images.                               */
                    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 < app1_offset + app_length + 2)
                        max_offset = app1_offset + app_length +2;
                }
                else
                {
                    max_offset = app1_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 = app1_offset + app_length + 2;
                if(PRINT_SECTION)
                {
                    chpr += printf(" - unknown format");
                    goto appdump;
                }
            }
        }
        else if(PRINT_SECTION)
        {
            chpr += printf("  No APP1 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,app1_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 = app1_offset + app_length + 2;
        /* close off the segment; a start "tag" was printed           */
        print_tag_address(SECTION,app1_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 $0x38, %rsp
movq %rsi, 0x10(%rsp)
testq %rdi, %rdi
je 0x15060
movl %r9d, %r15d
movq %r8, %r12
movq %rcx, %r14
movq %rdi, %r13
testq %rcx, %rcx
je 0x14f19
orb $-0x80, 0x19(%r14)
movl $0x1, 0x20(%r14)
movzwl %dx, %ebx
movl %ebx, %edi
callq 0xaad8
movq %rax, %rbp
leaq 0x43253(%rip), %rax     # 0x58180
movl $0x0, 0x4(%rsp)
testb $0x4, 0x2(%rax)
je 0x14f6b
leaq 0x2c19a(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x10(%rsp), %rsi
movl %r15d, %edx
callq 0x55eb
leaq 0x30351(%rip), %rdi     # 0x452ac
movq %rbp, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x3120
movl %eax, 0x4(%rsp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x45af
movl %eax, %ebx
movq %r13, %rdi
callq 0x30b0
movzwl %bx, %ecx
movq %rcx, 0x8(%rsp)
testl %eax, %eax
jne 0x14fa3
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
je 0x15104
movq %r13, %rdi
callq 0x31b0
xorl %r12d, %r12d
xorl %r14d, %r14d
testw %bx, %bx
je 0x150c7
movq %rbp, 0x18(%rsp)
leaq 0x431ba(%rip), %rax     # 0x58180
movq (%rax), %rax
movl %eax, %ecx
andl $0x400000, %ecx         # imm = 0x400000
movq %r15, %rbp
orq %r12, %rcx
je 0x15068
leaq 0x44434(%rip), %rax     # 0x59418
movq (%rax), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
sete %cl
movq 0x8(%rsp), %rdx
leaq 0x2(%rdx), %rbx
cmpq %rbx, %rax
seta %dl
orb %cl, %dl
movq %rbx, %r15
jne 0x15027
movq %rax, %r15
testq %rax, %rax
jne 0x15027
testq %r12, %r12
jne 0x1501f
leaq 0x443ec(%rip), %rax     # 0x59408
movq (%rax), %r12
movq %r12, %r15
testq %r12, %r12
je 0x15090
movl $0x1, %r14d
movl $0x1, %edi
callq 0x1707a
leal 0x2(%rbp), %r9d
subq $0x8, %rsp
movq %r13, %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
movq %r15, %rcx
movl $0x10, %r8d
pushq $0x2
callq 0x7480
addq $0x10, %rsp
jmp 0x15084
xorl %r14d, %r14d
jmp 0x150f2
btl $0x13, %eax
jae 0x15090
leaq 0x3021f(%rip), %rdi     # 0x45294
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl 0x4(%rsp), %r14d
movl %r14d, %edi
callq 0x1707a
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %r14
addq $0x2, %r14
leaq 0x1(%rcx,%rax), %rsi
leaq 0x2c04b(%rip), %rcx     # 0x410f9
movl $0x40000, %edi          # imm = 0x40000
movl %ebp, %edx
callq 0x55eb
leaq 0x430bf(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
jne 0x150cd
movl 0x4(%rsp), %edi
jmp 0x150ed
leaq 0x2ca5b(%rip), %rdi     # 0x41b2f
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
callq 0x1707a
movl %eax, %edi
callq 0x17a82
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x43075(%rip), %rax     # 0x58180
movq (%rax), %rax
btl $0x12, %eax
movq %rbp, 0x18(%rsp)
jb 0x151b2
testl $0x4003333, %eax        # imm = 0x4003333
je 0x151d8
leaq 0x2c82a(%rip), %rcx     # 0x41959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %r15d, %edx
callq 0x55eb
leaq 0x43038(%rip), %rax     # 0x58180
movq (%rax), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x1518e
testb $0x40, %al
je 0x1516b
leaq 0x3038e(%rip), %rdi     # 0x454eb
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, 0x4(%rsp)
leaq 0x2ff73(%rip), %rdi     # 0x450e5
leaq 0x2e919(%rip), %rsi     # 0x43a92
xorl %eax, %eax
callq 0x3120
addl %eax, 0x4(%rsp)
leaq 0x42ff5(%rip), %rax     # 0x58180
movq (%rax), %rax
testb $0x30, %al
je 0x151cb
leaq 0x2ff55(%rip), %rdi     # 0x450ee
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
jmp 0x151cf
leaq 0x2ff20(%rip), %rdi     # 0x450d9
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, 0x4(%rsp)
jmp 0x151d8
movl 0x4(%rsp), %edi
callq 0x1707a
movl %eax, 0x4(%rsp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
movl $0xffe1, %esi           # imm = 0xFFE1
callq 0x50a4
movq %rax, %rbp
movq %r13, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x15205
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
je 0x1521d
movq %r13, %rdi
callq 0x31b0
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x18(%rsp), %rbp
jmp 0x14fb1
leaq 0x42f5c(%rip), %rax     # 0x58180
movq (%rax), %rax
testq %rbp, %rbp
je 0x152aa
btl $0x12, %eax
jae 0x15247
leaq 0x3239f(%rip), %rdi     # 0x475d8
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, 0x4(%rsp)
movq %r13, %rdi
callq 0x3190
movq %rax, 0x20(%rsp)
leaq 0x2f100(%rip), %rsi     # 0x4435b
movl $0x4, %edx
movq %rbp, %rdi
callq 0x3090
testl %eax, %eax
movq 0x18(%rsp), %rbp
je 0x152c5
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rax,%rcx), %r14
addq $0x2, %r14
leaq 0x42ef6(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x152bc
leaq 0x30091(%rip), %rdi     # 0x45328
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x3120
addl %eax, 0x4(%rsp)
jmp 0x14fb1
btl $0x12, %eax
movq 0x18(%rsp), %rbp
jb 0x153a7
xorl %r14d, %r14d
movl 0x4(%rsp), %ebx
jmp 0x154bb
leaq 0x2c6cb(%rip), %rsi     # 0x41997
leaq 0x2e7bf(%rip), %rdx     # 0x43a92
movq %r12, %rdi
callq 0x17f99
movq %rax, %rcx
movq 0x20(%rsp), %r12
incq %r12
leaq 0x42e93(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
movq %rcx, 0x28(%rsp)
je 0x1531d
movl 0x4(%rsp), %edi
callq 0x1707a
movl %eax, 0x4(%rsp)
leal 0x2(%r15), %edx
leaq 0x2bdcc(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq %r12, %rsi
callq 0x55eb
movq %r13, %rdi
movq %r12, 0x20(%rsp)
movq %r12, %rsi
callq 0x41ac
movq %rax, %r12
testq %rax, %rax
je 0x1537e
movl $0x40000, %esi          # imm = 0x40000
movq %r12, %rdi
callq 0x5158
testl %eax, %eax
jne 0x1537e
cmpq $0x2a, 0x8(%r12)
jne 0x1537e
movzwl (%r12), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
callq 0x4707
movq %rax, %rdx
leaq 0x42e16(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
jne 0x15423
movq 0x20(%rsp), %rbx
jmp 0x1545e
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rax,%rcx), %r14
addq $0x2, %r14
leaq 0x42de9(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
jne 0x153ca
movq 0x28(%rsp), %r12
jmp 0x154aa
leaq 0x2ff8c(%rip), %rdi     # 0x4533a
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
callq 0x1707a
movl %eax, %ebx
jmp 0x154bb
leal 0x8(%r15), %edi
callq 0x96eb
testq %r12, %r12
je 0x153fc
movq 0x8(%r12), %r12
movzwl %r12w, %edi
callq 0xaad8
leaq 0x2feee(%rip), %rdi     # 0x452db
movq %r12, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3120
jmp 0x1540a
leaq 0x2ff0c(%rip), %rdi     # 0x4530f
xorl %eax, %eax
callq 0x3120
addl %eax, 0x4(%rsp)
cmpw $0x30, %bx
movl $0x30, %eax
cmovbl %ebx, %eax
movzwl %ax, %r12d
jmp 0x14fb1
movq %rdx, %rcx
movq 0x20(%rsp), %rbx
addq %rbx, %rcx
leaq 0x2fe81(%rip), %rdi     # 0x452b6
movq %rdx, %rsi
movq %rdx, 0x30(%rsp)
movq %rbx, %rdx
movq %rcx, %r8
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
callq 0x1707a
movq 0x30(%rsp), %rdx
movl %eax, 0x4(%rsp)
movzwl (%r12), %esi
leal 0x2(%r15), %eax
subq $0x8, %rsp
xorl %r10d, %r10d
movq %r13, %rdi
movq %rbx, %rcx
xorl %r8d, %r8d
movq %r14, %r9
pushq %rax
pushq $-0x1
pushq %r10
pushq %r10
movq 0x50(%rsp), %r12
pushq %r12
callq 0xcabc
addq $0x30, %rsp
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdx
leaq (%rcx,%rdx), %r14
addq $0x2, %r14
cmpq %r14, %rax
cmovaq %rax, %r14
testq %r12, %r12
movl 0x4(%rsp), %ebx
je 0x154bb
movq %r12, %rdi
callq 0x3050
leaq 0x42cbe(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x150f2
leaq -0x1(%r14), %rsi
leaq 0x2bc22(%rip), %rcx     # 0x410f9
movl $0x40000, %edi          # imm = 0x40000
movl %r15d, %edx
callq 0x55eb
leaq 0x2c644(%rip), %rdi     # 0x41b2f
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x1707a
jmp 0x150f2