// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movw $0x0, -0x5a(%rbp)
movl $0x0, -0x60(%rbp)
movq $0x0, -0x80(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x1c65d
cmpq $0x0, -0x28(%rbp)
je 0x1c0f8
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rax
movl $0x1, 0x20(%rax)
movzwl -0x1a(%rbp), %edi
callq 0xd580
movq %rax, -0x78(%rbp)
leaq 0x5b074(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c14f
movq -0x18(%rbp), %rsi
movl -0x34(%rbp), %edx
movl $0x40000, %edi          # imm = 0x40000
leaq 0x47fae(%rip), %rcx     # 0x640dc
callq 0x5ed0
movq -0x78(%rbp), %rsi
movzwl -0x1a(%rbp), %edx
leaq 0x4b7f8(%rip), %rdi     # 0x6793a
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4480
movw %ax, -0x5a(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30a0
cmpl $0x0, %eax
jne 0x1c182
movq -0x10(%rbp), %rdi
callq 0x3190
cmpl $0x0, %eax
je 0x1c190
movq -0x10(%rbp), %rdi
callq 0x31a0
jmp 0x1c66a
leaq 0x5afe9(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c1c3
movzwl -0x5a(%rbp), %esi
leaq 0x4b5b6(%rip), %rdi     # 0x67767
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x1c290
leaq 0x5afb6(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x4003333, %rax        # imm = 0x4003333
cmpq $0x0, %rax
je 0x1c28e
movl -0x34(%rbp), %edx
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x48733(%rip), %rcx     # 0x64924
callq 0x5ed0
leaq 0x5af83(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x3003, %rax           # imm = 0x3003
cmpq $0x0, %rax
je 0x1c253
leaq 0x5af6d(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40, %rax
cmpq $0x0, %rax
je 0x1c238
movq -0x30(%rbp), %rsi
leaq 0x4b94e(%rip), %rdi     # 0x67b79
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq 0x4b534(%rip), %rdi     # 0x67773
leaq 0x4a054(%rip), %rsi     # 0x6629a
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq 0x5af26(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x30, %rax
cmpq $0x0, %rax
je 0x1c283
movq -0x18(%rbp), %rsi
movzwl -0x5a(%rbp), %edx
leaq 0x4b506(%rip), %rdi     # 0x6777c
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %edi
callq 0x1ef50
movl %eax, -0x60(%rbp)
jmp 0x1c290
movq -0x10(%rbp), %rdi
movl $0xffe1, %esi           # imm = 0xFFE1
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5450
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30a0
cmpl $0x0, %eax
jne 0x1c2c3
movq -0x10(%rbp), %rdi
callq 0x3190
cmpl $0x0, %eax
je 0x1c2d1
movq -0x10(%rbp), %rdi
callq 0x31a0
jmp 0x1c66a
cmpq $0x0, -0x70(%rbp)
je 0x1c5cf
leaq 0x5ae9d(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c30a
movq -0x70(%rbp), %rsi
leaq 0x4d813(%rip), %rdi     # 0x69b10
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3180
movq %rax, -0x50(%rbp)
movq -0x70(%rbp), %rdi
leaq 0x4a6a9(%rip), %rsi     # 0x669cb
movl $0x4, %edx
callq 0x3080
cmpl $0x0, %eax
jne 0x1c589
movq -0x30(%rbp), %rdi
leaq 0x48622(%rip), %rsi     # 0x64962
leaq 0x49f53(%rip), %rdx     # 0x6629a
callq 0x20960
movq %rax, -0x80(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
leaq 0x5ae1d(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c398
movl -0x60(%rbp), %edi
callq 0x1ef50
movl %eax, -0x60(%rbp)
movq -0x50(%rbp), %rsi
movl -0x34(%rbp), %edx
addl $0x2, %edx
movl $0x40000, %edi          # imm = 0x40000
leaq 0x47d49(%rip), %rcx     # 0x640dc
callq 0x5ed0
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x3f70
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x1c4c3
movq -0x68(%rbp), %rdi
movl $0x40000, %esi          # imm = 0x40000
callq 0x55c0
cmpl $0x0, %eax
jne 0x1c4c3
movq -0x68(%rbp), %rax
cmpq $0x2a, 0x8(%rax)
jne 0x1c4c3
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movzwl (%rax), %esi
callq 0x4610
movq %rax, -0x48(%rbp)
leaq 0x5ad86(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c440
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x50(%rbp), %rcx
addq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
addq -0x48(%rbp), %r8
leaq 0x4b51c(%rip), %rdi     # 0x67944
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %edi
callq 0x1ef50
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rax
movw (%rax), %si
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x28(%rbp), %r9
movq -0x80(%rbp), %r10
movl -0x34(%rbp), %eax
addl $0x2, %eax
xorl %r8d, %r8d
xorl %r11d, %r11d
movzwl %si, %esi
movq %r10, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movl %eax, 0x20(%rsp)
callq 0x112e0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movzwl -0x5a(%rbp), %edx
addq %rdx, %rcx
addq $0x2, %rcx
cmpq %rcx, %rax
jae 0x1c4be
movq -0x18(%rbp), %rax
movzwl -0x5a(%rbp), %ecx
addq %rcx, %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
jmp 0x1c577
movq -0x18(%rbp), %rax
movzwl -0x5a(%rbp), %ecx
addq %rcx, %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
leaq 0x5aca3(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c575
movl -0x34(%rbp), %edi
addl $0x8, %edi
callq 0xb970
cmpq $0x0, -0x68(%rbp)
je 0x1c541
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movzwl %ax, %edi
callq 0xd580
movq -0x88(%rbp), %rsi
movq %rax, %rdx
leaq 0x4b437(%rip), %rdi     # 0x67969
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x1c555
leaq 0x4b455(%rip), %rdi     # 0x6799d
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movzwl -0x5a(%rbp), %eax
cmpl $0x30, %eax
jle 0x1c568
movq $0x30, -0x58(%rbp)
jmp 0x1c570
movzwl -0x5a(%rbp), %eax
movq %rax, -0x58(%rbp)
jmp 0x1c66a
jmp 0x1c577
cmpq $0x0, -0x80(%rbp)
je 0x1c587
movq -0x80(%rbp), %rdi
callq 0x3040
jmp 0x1c5cd
movq -0x18(%rbp), %rax
movzwl -0x5a(%rbp), %ecx
addq %rcx, %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
leaq 0x5abdd(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c5cb
leaq 0x4b3fd(%rip), %rdi     # 0x679b6
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x1c66a
jmp 0x1c5cd
jmp 0x1c606
leaq 0x5abaa(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c604
leaq 0x4b3dc(%rip), %rdi     # 0x679c8
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %edi
callq 0x1ef50
movl %eax, -0x60(%rbp)
jmp 0x1c606
leaq 0x5ab73(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c65b
movq -0x40(%rbp), %rsi
subq $0x1, %rsi
movl -0x34(%rbp), %edx
movl $0x40000, %edi          # imm = 0x40000
leaq 0x47ac6(%rip), %rcx     # 0x640f9
callq 0x5ed0
movq -0x78(%rbp), %rsi
leaq 0x484b7(%rip), %rdi     # 0x64afa
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %edi
callq 0x1ef50
movl %eax, -0x60(%rbp)
jmp 0x1c65d
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1c813
movzwl -0x5a(%rbp), %eax
cmpq $0x0, %rax
jle 0x1c803
leaq 0x5ab01(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x400000, %rax         # imm = 0x400000
cmpq $0x0, %rax
jne 0x1c699
cmpq $0x0, -0x58(%rbp)
jbe 0x1c75b
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
leaq 0x5bd73(%rip), %rax     # 0x78418
cmpq %rcx, (%rax)
je 0x1c6c3
leaq 0x5bd67(%rip), %rax     # 0x78418
movq (%rax), %rax
movzwl -0x5a(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jbe 0x1c6d2
movzwl -0x5a(%rbp), %eax
addl $0x2, %eax
cltq
movq %rax, -0x58(%rbp)
jmp 0x1c708
leaq 0x5bd3f(%rip), %rax     # 0x78418
cmpq $0x0, (%rax)
jbe 0x1c6ef
leaq 0x5bd32(%rip), %rax     # 0x78418
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x1c706
cmpq $0x0, -0x58(%rbp)
jne 0x1c704
leaq 0x5bd0b(%rip), %rax     # 0x78408
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x1c706
jmp 0x1c708
cmpq $0x0, -0x58(%rbp)
je 0x1c759
movl $0x1, %edi
callq 0x1ef50
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movzwl -0x5a(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdx
movq -0x58(%rbp), %rcx
movl -0x34(%rbp), %r9d
addl $0x2, %r9d
movl $0x10, %r8d
movl $0x2, (%rsp)
callq 0x8aa0
movl $0x1, %edi
callq 0x1ef50
movl %eax, -0x60(%rbp)
jmp 0x1c792
leaq 0x5aa1e(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x80000, %rax          # imm = 0x80000
cmpq $0x0, %rax
je 0x1c790
leaq 0x4b1aa(%rip), %rdi     # 0x67922
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %edi
callq 0x1ef50
movl %eax, -0x60(%rbp)
jmp 0x1c792
movq -0x18(%rbp), %rax
movzwl -0x5a(%rbp), %ecx
addq %rcx, %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rsi
movzwl -0x5a(%rbp), %eax
addq %rax, %rsi
addq $0x1, %rsi
movl -0x34(%rbp), %edx
movl $0x40000, %edi          # imm = 0x40000
leaq 0x47936(%rip), %rcx     # 0x640f9
callq 0x5ed0
leaq 0x5a9b1(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1c801
movq -0x78(%rbp), %rsi
leaq 0x48311(%rip), %rdi     # 0x64afa
movb $0x0, %al
callq 0x3110
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %edi
callq 0x1ef50
movl %eax, -0x60(%rbp)
jmp 0x1c803
movl -0x60(%rbp), %edi
callq 0x1ff00
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq