// File: /workspace/github_c_makefile_star2_O2/hfiguiere[P]exifprobe/print.c
// Function: process_private_ifd
unsigned long
process_private_ifd(FILE *inptr,unsigned short byteorder,
                    unsigned long subifd_offset,unsigned long fileoffset_base,
                    unsigned long max_offset,unsigned short subifd_ident,
                    struct image_summary *summary_entry,char *parent_name,
                    char *prefix,int make,int model,int indent)
{
    struct ifd_entry *entry_ptr;
    unsigned long max_value_offset = 0L;
    unsigned long next_ifd_offset,current_offset,max_subifd_offset;
    unsigned long start_entry_offset,entry_offset,value_offset;
    int entry_num,num_entries,value_is_offset,use_second_pass;
    int chpr = 0;

    if(inptr == (FILE *)0)
    {
        fprintf(stderr,"%s: no open file pointer to read makernote %s subifd\n",
                Progname,parent_name);
        return(0L);
    }
    if(summary_entry)
        summary_entry->filesubformat |= FILESUBFMT_MNSUBIFD;

    /* If the section appears to be beyond the end of the parent ifd, */
    /* mark the start address to call attention.                      */
    if(max_offset && ((subifd_offset + fileoffset_base) > max_offset))
        prefix = "+";

    max_subifd_offset = max_offset;
    print_tag_address(SECTION,subifd_offset + fileoffset_base,indent,prefix);
    if(PRINT_SECTION)
        chpr += printf("<%s SubIFD> (in MakerNote)",parent_name);

    num_entries = read_ushort(inptr,byteorder,subifd_offset + fileoffset_base);
    if(ferror(inptr) || feof(inptr))
        goto blewit;
    current_offset = entry_offset = start_entry_offset = ftell(inptr);
    if(PRINT_SECTION)
    {
        chpr += printf(" %d entries ",num_entries);
        chpr += printf("starting at file offset %#lx=%lu",
                                            current_offset,current_offset);
            chpr = newline(chpr);
    }
    use_second_pass = value_is_offset = 0;

    /* The direct entries                                             */
    for(entry_num = 0; entry_num < num_entries; ++entry_num)
    {
        entry_ptr = read_ifd_entry(inptr,byteorder,entry_offset);
        if((entry_ptr->value_type == 0) || (entry_ptr->value_type > DOUBLE) ||
            ferror(inptr) || feof(inptr))
        {
            int invalid_entry = 0;
            unsigned long limit_offset = 0L;

            print_tag_address(ENTRY,entry_offset,indent,prefix);
            chpr += printf(" INVALID MAKERNOTE SUBIFD ENTRY (%lu)",entry_ptr->value);
            chpr = newline(chpr);
            clearerr(inptr);
            current_offset = ftell(inptr);
            if(max_offset > 0)
                limit_offset = max_offset;
            else
            {
                if(fseek(inptr,0L,SEEK_END) != -1)
                {
                    limit_offset = ftell(inptr);
                    fseek(inptr,current_offset,SEEK_SET);
                }
            }
            /* If there's an error on input, or we can't check    */
            /* for absurd num_entries, give up.                   */
            if(!ferror(inptr) && (limit_offset > 0))
            {
                /* If the number of entries would read past the   */
                /* size of the IFD, or past EOF, give up          */
                if((entry_offset + (12 * num_entries)) < limit_offset)
                {
                    /* Limit the number of consecutive failures.  */
                    /* An apparently valid entry resets the count */
                    /* to 0.                                      */
                    if(invalid_entry++ < MAX_INVALID_ENTRIES)
                    {
                        entry_offset = current_offset;
                        continue;
                    }
                }
            }
            chpr = newline(chpr);
            goto blewit;
        }
        current_offset = ftell(inptr);

        print_tag_address(ENTRY,entry_offset,indent,prefix);
        value_offset = print_private_entry(inptr,byteorder,entry_ptr,fileoffset_base,
                                            subifd_ident,summary_entry,parent_name,
                                            prefix,make,model,SUBINDENT);
        if(value_offset == 0UL)
            value_offset = current_offset;
        if(value_offset > max_value_offset)
            max_value_offset = value_offset;
        if((PRINT_VALUE_AT_OFFSET) && (is_offset(entry_ptr)))
            ++use_second_pass;
        entry_offset = current_offset;
    }

    next_ifd_offset = read_ulong(inptr,byteorder,current_offset);

    /* offsets found in the next pass should be within the bounds of  */
    /* the parent ifd. The following helps to detect chunks that are  */
    /* written "out of place".                                        */

    /* There should be no next_ifd_offset (it should be 0)            */
    /* ###%%% prepare for chains?                                     */
    if(next_ifd_offset > 0L)
    {
        /* ###%%% report unwillingness to handle chained IFDs         */
        if((PRINT_ADDRESS) && (PRINT_VALUE) && (PRINT_VALUE_AT_OFFSET))
        {
            print_tag_address(ENTRY,current_offset,indent,prefix);
            extraindent(SUBINDENT);
            chpr += printf("**** next IFD offset %lu  ",next_ifd_offset);
            next_ifd_offset += fileoffset_base;
            if(next_ifd_offset < ftell(inptr))
            {
                printred("BAD NEXT IFD OFFSET");
                next_ifd_offset = 0L;
            }
            else
                chpr += printf("(+ %lu = %#lx/%lu)",fileoffset_base,
                                        next_ifd_offset,next_ifd_offset);
            chpr = newline(chpr);
        }
        else
            next_ifd_offset += fileoffset_base;
        /* This should never happen                                   */
        max_subifd_offset = next_ifd_offset;
    }
    else
    {
        if((PRINT_ADDRESS) && (PRINT_VALUE) && (PRINT_VALUE_AT_OFFSET))
        {
            print_tag_address(ENTRY,current_offset,indent,prefix);
            extraindent(SUBINDENT);
            chpr += printf("**** next IFD offset 0");
            chpr = newline(chpr);
        }
    }

    if(ferror(inptr) || feof(inptr))
    {
        chpr += printf(" READ NEXT IFD OFFSET FAILED ");
        chpr = newline(chpr);
        why(stdout);
        clearerr(inptr);    /* keep going...                          */
    }
    else
        current_offset = ftell(inptr);

    value_offset = current_offset;

    /* Second pass, to evaluate entries which are stored indirectly.  */
    /* This occurs when the value requires more than 4 bytes, AND for */
    /* certain LONG values which are intended to be used as offsets   */
    if(use_second_pass)
    {
        if((PRINT_VALUE) && (PRINT_ADDRESS) && (PRINT_VALUE_AT_OFFSET))
        {
            print_tag_address(ENTRY,value_offset,indent,prefix);
            extraindent(SUBINDENT);
            chpr += printf("============= VALUES, %s IFD ============",parent_name);
            chpr = newline(chpr);
        }

        entry_offset = start_entry_offset;
        for(entry_num = 0; entry_num < num_entries; ++entry_num)
        {
            entry_ptr = read_ifd_entry(inptr,byteorder,entry_offset);
            if((entry_ptr->value_type == 0) || (entry_ptr->value_type > DOUBLE) ||
                ferror(inptr) || feof(inptr))
            {
                /* If the first pass made it through invalid entries, */
                /* this pass should just ignore them and quietly      */
                /* continue.                                          */
                clearerr(inptr);
                entry_offset = current_offset = ftell(inptr);
                continue;
            }
            current_offset = entry_offset = ftell(inptr);
            if(is_offset(entry_ptr) ||
                        private_value_is_offset(make,subifd_ident,entry_ptr->tag))
            {
                value_offset = print_offset_pe_value(inptr,byteorder,
                                            entry_ptr,fileoffset_base,
                                            subifd_ident,summary_entry,
                                            parent_name,prefix,indent,
                                            make,model,1);
            }
            if(value_offset > max_value_offset)
                max_value_offset = value_offset;
        }
    }
    else if(current_offset > max_value_offset)
        max_value_offset = current_offset;

    if(max_offset && (max_value_offset > max_offset))
    {
        max_value_offset = max_offset;
        print_tag_address(SECTION,max_value_offset - 1,indent,">");
    }
    else
        print_tag_address(SECTION,max_value_offset - 1,indent,"-");
    if(PRINT_SECTION)
    {
        chpr += printf("</%s SubIFD> (in MakerNote)",parent_name);
        chpr = newline(chpr);
    }

    return(max_value_offset);
blewit:
    clearerr(inptr);
    current_offset = ftell(inptr);
    print_tag_address(SECTION,current_offset - 1,indent,"-");
    if(PRINT_SECTION)
    {
        chpr += printf("</EXIF IFD>");
        chpr = newline(chpr);
    }
    return(0L);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x30(%rsp)
testq %rdi, %rdi
je 0x9542
movl %r9d, %r15d
movq %rdx, %rbx
movl %esi, %r14d
movq %rdi, %r12
movl 0xa8(%rsp), %r13d
movq 0x90(%rsp), %rax
movq 0x80(%rsp), %rdx
testq %rdx, %rdx
je 0x916d
orb $0x2, 0x19(%rdx)
movq %rcx, 0x20(%rsp)
addq %rcx, %rbx
movq 0x30(%rsp), %rdx
cmpq %rdx, %rbx
leaq 0x369fe(%rip), %rcx     # 0x3fb82
cmovbeq %rax, %rcx
testq %rdx, %rdx
cmoveq %rax, %rcx
movl $0x40000, %edi          # imm = 0x40000
movq %rbx, %rsi
movl %r13d, %edx
movq %rcx, 0x8(%rsp)
callq 0x5100
leaq 0x4dfd5(%rip), %rax     # 0x57180
xorl %ebp, %ebp
testb $0x4, 0x2(%rax)
je 0x91cb
leaq 0x369ca(%rip), %rdi     # 0x3fb84
movq 0x88(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
movzwl %r14w, %r14d
movq %r12, %rdi
movl %r14d, %esi
movq %rbx, %rdx
callq 0x416a
movl %eax, %ebx
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x94dc
movl %r14d, (%rsp)
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x94dc
movzwl %bx, %ebx
movq %r12, %rdi
callq 0x3190
movq %rax, %r13
leaq 0x4df68(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x9253
leaq 0x3697a(%rip), %rdi     # 0x3fb9f
movl %ebx, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
leaq 0x36974(%rip), %rdi     # 0x3fbac
movq %r13, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
addl %r14d, %ebp
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
imull $0xc, %ebx, %eax
movq %rax, 0x40(%rsp)
movzwl %r15w, %eax
movl %eax, 0x4(%rsp)
movl %ebx, 0x3c(%rsp)
movq $0x0, 0x10(%rsp)
movq %r13, 0x28(%rsp)
movl $0x0, 0x1c(%rsp)
movq %r12, %rdi
subl $0x1, %ebx
jb 0x9426
movl (%rsp), %esi
movq %r13, %rdx
callq 0x476a
movq %rax, %r14
movzwl 0x2(%rax), %eax
addl $-0xd, %eax
cmpw $-0xc, %ax
jb 0x92c0
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x92c0
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
je 0x937f
movl $0x4003333, %edi        # imm = 0x4003333
movq %r13, %rsi
movl 0xa8(%rsp), %edx
movq 0x8(%rsp), %rcx
callq 0x5100
movq 0x10(%r14), %rsi
leaq 0x368e9(%rip), %rdi     # 0x3fbcd
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
movq %r12, %rdi
callq 0x31b0
movq %r12, %rdi
callq 0x3190
movq %rax, %r15
movq 0x30(%rsp), %rax
movq %rax, %r14
testq %rax, %rax
jne 0x9346
movq %r12, %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
callq 0x3210
movl $0x0, %r14d
cmpl $-0x1, %eax
je 0x9346
movq %r12, %rdi
callq 0x3190
movq %rax, %r14
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x3210
movq %r12, %rdi
callq 0x30b0
testq %r14, %r14
je 0x94cb
testl %eax, %eax
jne 0x94cb
addq 0x40(%rsp), %r13
cmpq %r14, %r13
jae 0x94cb
movq 0x10(%rsp), %r13
movq %r13, 0x10(%rsp)
movq %r15, %r13
jmp 0x927d
movq %r12, %rdi
callq 0x3190
movq %rax, %r15
movl $0x4003333, %edi        # imm = 0x4003333
movq %r13, %rsi
movl 0xa8(%rsp), %edx
movq 0x8(%rsp), %r13
movq %r13, %rcx
callq 0x5100
subq $0x8, %rsp
movq %r12, %rdi
movl 0x8(%rsp), %esi
movq %r14, %rdx
movq 0x28(%rsp), %rcx
movl 0xc(%rsp), %r8d
movq 0x88(%rsp), %r9
pushq $0x2
movl 0xb0(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
pushq %r13
pushq 0xb0(%rsp)
callq 0x9802
addq $0x30, %rsp
movq %rax, %r13
testq %rax, %rax
cmoveq %r15, %r13
movq 0x10(%rsp), %rax
cmpq %rax, %r13
cmovbeq %rax, %r13
leaq 0x4dd79(%rip), %rax     # 0x57180
testb $0x1, 0x3(%rax)
je 0x9372
movq %r14, %rdi
callq 0xf1c7
cmpl $0x1, %eax
sbbl $-0x1, 0x1c(%rsp)
jmp 0x9372
movl (%rsp), %ebx
movl %ebx, %esi
movq %r13, %rdx
callq 0x42ba
movq %rax, %r14
leaq 0x4dd43(%rip), %rax     # 0x57180
movq (%rax), %rax
testl $0x30000, %eax          # imm = 0x30000
sete %cl
testb $0x30, %al
sete %dl
orb %cl, %dl
btl $0x18, %eax
setae %al
orb %dl, %al
testq %r14, %r14
je 0x9571
testb %al, %al
jne 0x95d3
movl $0x4003333, %edi        # imm = 0x4003333
movq %r13, %rsi
movl 0xa8(%rsp), %edx
movq 0x8(%rsp), %rcx
callq 0x5100
pushq $0x2
popq %rdi
callq 0x8f6f
leaq 0x36762(%rip), %rdi     # 0x3fbf3
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl %ebp, %r15d
movq 0x20(%rsp), %rbx
addq %rbx, %r14
movq %r12, %rdi
callq 0x3190
cmpq %rax, %r14
jae 0x95ac
leaq 0x3c18f(%rip), %rdi     # 0x45650
callq 0x56e2
jmp 0x95c6
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
movl 0xa8(%rsp), %r13d
movq %r12, %rdi
callq 0x31b0
movq %r12, %rdi
callq 0x3190
leaq -0x1(%rax), %rsi
leaq 0x35c02(%rip), %rcx     # 0x3f0f9
movl $0x40000, %edi          # imm = 0x40000
movl %r13d, %edx
callq 0x5100
leaq 0x4dc75(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
jne 0x9516
xorl %r15d, %r15d
jmp 0x9530
leaq 0x36606(%rip), %rdi     # 0x3fb23
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4daaf(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0x4ef15(%rip), %rax     # 0x58468
movq (%rax), %rdx
leaq 0x365ef(%rip), %rsi     # 0x3fb4c
xorl %r15d, %r15d
movq 0x88(%rsp), %rcx
xorl %eax, %eax
callq 0x3180
jmp 0x9530
testb %al, %al
jne 0x95d3
movl $0x4003333, %edi        # imm = 0x4003333
movq %r13, %rsi
movl 0xa8(%rsp), %edx
movq 0x8(%rsp), %rcx
callq 0x5100
pushq $0x2
popq %rdi
callq 0x8f6f
leaq 0x36671(%rip), %rdi     # 0x3fc0e
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl %ebp, %r15d
jmp 0x95c9
leaq 0x39cd1(%rip), %rdi     # 0x43284
movq %rbx, %rsi
movq %r14, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x3120
addl %eax, %r15d
movl (%rsp), %ebx
movl %r15d, %edi
callq 0x160f7
movl %eax, %ebp
movq 0x10(%rsp), %r15
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x95f4
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
je 0x97f2
leaq 0x3662a(%rip), %rdi     # 0x3fc25
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
movq 0x4d9b4(%rip), %rax     # 0x56fc8
movq (%rax), %rdi
callq 0x16e8c
movq %r12, %rdi
callq 0x31b0
cmpl $0x0, 0x1c(%rsp)
je 0x9781
leaq 0x4db4a(%rip), %rax     # 0x57180
movq (%rax), %rax
btl $0x18, %eax
jae 0x9774
movl %eax, %ecx
andl $0x30, %ecx
je 0x9774
andl $0x30000, %eax          # imm = 0x30000
je 0x9774
movl $0x4003333, %edi        # imm = 0x4003333
movq %r13, %rsi
movl 0xa8(%rsp), %edx
movq 0x8(%rsp), %rcx
callq 0x5100
pushq $0x2
popq %rdi
callq 0x8f6f
leaq 0x365c2(%rip), %rdi     # 0x3fc43
movq 0x88(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
jmp 0x9774
movq %r12, %rdi
movl %ebx, %esi
movq 0x28(%rsp), %rdx
callq 0x476a
movq %rax, %r14
movzwl 0x2(%rax), %eax
addl $-0xd, %eax
cmpw $-0xc, %ax
jb 0x96d7
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x96d7
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
je 0x96f1
movq %r12, %rdi
callq 0x31b0
movq %r12, %rdi
callq 0x3190
movq %rax, 0x28(%rsp)
jmp 0x9774
movq %r12, %rdi
callq 0x3190
movq %rax, 0x28(%rsp)
movq %r14, %rdi
callq 0xf1c7
testl %eax, %eax
jne 0x9722
movzwl (%r14), %edx
movl 0x98(%rsp), %edi
movl 0x4(%rsp), %esi
callq 0x9a95
testl %eax, %eax
je 0x976d
movq %r12, %rdi
movl %ebx, %esi
movq %r14, %rdx
movq 0x20(%rsp), %rcx
movl 0x4(%rsp), %r8d
movq 0x80(%rsp), %r9
pushq $0x1
movl 0xa8(%rsp), %eax
pushq %rax
movl 0xa8(%rsp), %eax
pushq %rax
movl 0xc0(%rsp), %eax
pushq %rax
pushq 0x28(%rsp)
pushq 0xb0(%rsp)
callq 0x9aa8
addq $0x30, %rsp
movq %rax, %r13
cmpq %r15, %r13
cmovaq %r13, %r15
subl $0x1, 0x3c(%rsp)
jae 0x96a0
jmp 0x9788
cmpq %r15, %r13
cmovaq %r13, %r15
movq 0x30(%rsp), %rdx
testq %rdx, %rdx
setne %al
cmpq %rdx, %r15
seta %cl
testb %cl, %al
cmovneq %rdx, %r15
leaq 0x3e06c(%rip), %rax     # 0x47812
leaq 0x3594c(%rip), %rcx     # 0x3f0f9
cmovneq %rax, %rcx
leaq -0x1(%r15), %rsi
movl $0x40000, %edi          # imm = 0x40000
movl 0xa8(%rsp), %edx
callq 0x5100
leaq 0x4d9b3(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x9530
leaq 0x3648f(%rip), %rdi     # 0x3fc6d
movq 0x88(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
jmp 0x9527
movq %r12, %rdi
callq 0x3190
movq %rax, %r13
jmp 0x9624