// File: /workspace/github_c_makefile_star2_O1/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
movl %r9d, 0x24(%rsp)
testq %rdi, %rdi
je 0x9b25
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %r12
movl 0xa8(%rsp), %r13d
movq 0x90(%rsp), %rax
movq 0x80(%rsp), %rdx
testq %rdx, %rdx
je 0x97da
orb $0x2, 0x19(%rdx)
movq %rcx, 0x28(%rsp)
addq %rcx, %rbx
cmpq %r8, %rbx
leaq 0x38396(%rip), %rcx     # 0x41b82
cmovbeq %rax, %rcx
movq %r8, 0x38(%rsp)
testq %r8, %r8
cmoveq %rax, %rcx
movl $0x40000, %edi          # imm = 0x40000
movq %rbx, %rsi
movl %r13d, %edx
movq %rcx, 0x10(%rsp)
callq 0x5605
leaq 0x4e968(%rip), %rax     # 0x58180
xorl %r14d, %r14d
testb $0x4, 0x2(%rax)
je 0x983a
leaq 0x3835c(%rip), %rdi     # 0x41b84
movq 0x88(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
movzwl %r15w, %r15d
movq %r12, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x4574
movl %eax, %ebx
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x9866
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
je 0x98cc
movq %r12, %rdi
callq 0x31b0
movq %r12, %rdi
callq 0x3190
leaq -0x1(%rax), %rsi
leaq 0x37878(%rip), %rcx     # 0x410f9
movl $0x40000, %edi          # imm = 0x40000
movl %r13d, %edx
callq 0x5605
leaq 0x4e8eb(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
jne 0x989f
xorl %ebx, %ebx
jmp 0x98ba
leaq 0x3827d(%rip), %rdi     # 0x41b23
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
movl %r14d, %edi
callq 0x16b56
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl %bx, %r13d
movq %r12, %rdi
callq 0x3190
movq %rax, %rbx
leaq 0x4e89e(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
movq %rbx, 0x18(%rsp)
je 0x9925
leaq 0x382ab(%rip), %rdi     # 0x41b9f
movl %r13d, %esi
xorl %eax, %eax
callq 0x3120
movq %rbx, %rdx
movl %eax, %ebx
leaq 0x382a2(%rip), %rdi     # 0x41bac
movq %rdx, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
addl %ebx, %r14d
movl %r14d, %edi
callq 0x16b56
movl %eax, %r14d
testl %r13d, %r13d
movl %r15d, 0x4(%rsp)
movq %r13, 0x30(%rsp)
je 0x9b4d
leal (,%r13,4), %eax
leal (%rax,%rax,2), %eax
movq %rax, 0x40(%rsp)
movl $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rbx
movq $0x0, 0x8(%rsp)
movq %r12, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x4b9b
movq %rax, %r15
movzwl 0x2(%rax), %eax
addl $-0xd, %eax
cmpw $-0xc, %ax
jb 0x9998
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x9998
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
je 0x9a78
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbx, %rsi
movl 0xa8(%rsp), %edx
movq 0x10(%rsp), %rcx
callq 0x5605
movq 0x10(%r15), %rsi
leaq 0x38211(%rip), %rdi     # 0x41bcd
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
movl %r14d, %edi
callq 0x16b56
movl %eax, %r14d
movq %r12, %rdi
callq 0x31b0
movq %r12, %rdi
callq 0x3190
movq %rax, %rbp
movq 0x38(%rsp), %rax
movq %rax, %r15
testq %rax, %rax
jne 0x9a23
movq %r12, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x3210
movl $0x0, %r15d
cmpl $-0x1, %eax
je 0x9a23
movq %r12, %rdi
callq 0x3190
movq %rax, %r15
movq %r12, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x3210
movq %r12, %rdi
callq 0x30b0
testq %r15, %r15
je 0x9a4c
testl %eax, %eax
jne 0x9a4c
movq 0x40(%rsp), %rax
leaq (%rbx,%rax), %rcx
movl $0x5, %eax
cmpq %r15, %rcx
jae 0x9a4c
movq %rbp, %rbx
jmp 0x9a5c
movl %r14d, %edi
callq 0x16b56
movl %eax, %r14d
movl $0x2, %eax
cmpl $0x5, %eax
movl 0x4(%rsp), %r15d
jne 0x9b37
decl %r13d
jne 0x995e
jmp 0x9b60
movq %r12, %rdi
callq 0x3190
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbx, %rsi
movq %rax, %rbx
movl 0xa8(%rsp), %edx
movq 0x10(%rsp), %rbp
movq %rbp, %rcx
callq 0x5605
subq $0x8, %rsp
movzwl 0x2c(%rsp), %r8d
movq %r12, %rdi
movl 0xc(%rsp), %esi
movq %r15, %rdx
movq 0x30(%rsp), %rcx
movq 0x88(%rsp), %r9
pushq $0x2
movl 0xb0(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
pushq %rbp
pushq 0xb0(%rsp)
callq 0x9f07
addq $0x30, %rsp
testq %rax, %rax
cmoveq %rbx, %rax
movq 0x8(%rsp), %rcx
cmpq %rcx, %rax
cmovaq %rax, %rcx
movq %rcx, 0x8(%rsp)
leaq 0x4e67e(%rip), %rax     # 0x58180
testb $0x1, 0x3(%rax)
je 0x9b18
movq %r15, %rdi
callq 0xfe62
cmpl $0x1, %eax
sbbl $-0x1, 0x20(%rsp)
movq %rbx, %rbp
movl 0x4(%rsp), %r15d
jmp 0x9a6a
movq 0x88(%rsp), %rdi
callq 0x336a
jmp 0x989b
cmpl $0x2, %eax
jne 0x9c74
movl 0xa8(%rsp), %r13d
jmp 0x9866
movb $0x1, %r13b
movq $0x0, 0x8(%rsp)
movq 0x18(%rsp), %rdx
jmp 0x9b6c
cmpl $0x0, 0x20(%rsp)
sete %r13b
movq %rbp, %rdx
movq %r12, %rdi
movl %r15d, %esi
movq %rdx, %rbp
callq 0x46cc
movq %rax, %rbx
leaq 0x4e5fc(%rip), %rax     # 0x58180
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 %rbx, %rbx
je 0x9c2a
testb %al, %al
jne 0x9ca3
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl 0xa8(%rsp), %edx
movq 0x10(%rsp), %rcx
callq 0x5605
leaq 0x4e5b0(%rip), %rax     # 0x58180
testb $0x30, 0x3(%rax)
je 0x9be0
movl $0x2, %edi
callq 0x5730
leaq 0x3800c(%rip), %rdi     # 0x41bf3
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl %r14d, %r15d
movq 0x28(%rsp), %r14
addq %r14, %rbx
movq %r12, %rdi
callq 0x3190
cmpq %rax, %rbx
jae 0x9c79
leaq 0x37484(%rip), %rdi     # 0x41097
leaq 0x3da46(%rip), %rsi     # 0x47660
xorl %eax, %eax
callq 0x3120
movl %eax, %edi
callq 0x17530
jmp 0x9c93
testb %al, %al
jne 0x9ca3
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl 0xa8(%rsp), %edx
movq 0x10(%rsp), %rcx
callq 0x5605
leaq 0x4e532(%rip), %rax     # 0x58180
testb $0x30, 0x3(%rax)
je 0x9c5e
movl $0x2, %edi
callq 0x5730
leaq 0x37fa9(%rip), %rdi     # 0x41c0e
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl %r14d, %r15d
jmp 0x9c93
jmp 0x98ba
leaq 0x3b604(%rip), %rdi     # 0x45284
movq %r14, %rsi
movq %rbx, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3120
addl %eax, %r15d
movl %r15d, %edi
callq 0x16b56
movl %eax, %r14d
movl 0x4(%rsp), %r15d
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x9cbf
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
je 0x9ef7
leaq 0x37f5f(%rip), %rdi     # 0x41c25
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
movl %r14d, %edi
callq 0x16b56
movl %eax, %r14d
movq 0x4e2e6(%rip), %rax     # 0x57fc8
movq (%rax), %rdi
callq 0x179a5
movq %r12, %rdi
callq 0x31b0
testb %r13b, %r13b
je 0x9d10
movq 0x8(%rsp), %rbx
cmpq %rbx, %rbp
cmovaq %rbp, %rbx
movl 0xa8(%rsp), %r13d
jmp 0x9e91
leaq 0x4e469(%rip), %rax     # 0x58180
movq (%rax), %rax
btl $0x18, %eax
movl 0xa8(%rsp), %r13d
jae 0x9d86
movl %eax, %ecx
andl $0x30, %ecx
je 0x9d86
andl $0x30000, %eax          # imm = 0x30000
je 0x9d86
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl %r13d, %edx
movq 0x10(%rsp), %rcx
callq 0x5605
leaq 0x4e42e(%rip), %rax     # 0x58180
testb $0x30, 0x3(%rax)
je 0x9d62
movl $0x2, %edi
callq 0x5730
leaq 0x37eda(%rip), %rdi     # 0x41c43
movq 0x88(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
movl %r14d, %edi
callq 0x16b56
movl %eax, %r14d
cmpl $0x0, 0x30(%rsp)
je 0x9e8c
movzwl 0x24(%rsp), %ebx
movq %r12, %rdi
movl %r15d, %esi
movq 0x18(%rsp), %rdx
callq 0x4b9b
movq %rax, %r15
movzwl 0x2(%rax), %eax
addl $-0xd, %eax
cmpw $-0xc, %ax
jb 0x9dce
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x9dce
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
je 0x9dfb
movq %r12, %rdi
callq 0x31b0
movq %r12, %rdi
callq 0x3190
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
decl %eax
movq %rax, 0x30(%rsp)
movl 0x4(%rsp), %r15d
jne 0x9d96
jmp 0x9e8c
movq %r12, %rdi
callq 0x3190
movq %rax, 0x18(%rsp)
movq %r15, %rdi
callq 0xfe62
testl %eax, %eax
je 0x9e5b
movq %r12, %rdi
movl 0x4(%rsp), %esi
movq %r15, %rdx
movq 0x28(%rsp), %rcx
movl %ebx, %r8d
movq 0x80(%rsp), %r9
pushq $0x1
movl 0xa8(%rsp), %eax
pushq %rax
movl 0xa8(%rsp), %eax
pushq %rax
pushq %r13
pushq 0x30(%rsp)
pushq 0xb0(%rsp)
callq 0xa1e1
addq $0x30, %rsp
movq %rax, %rbp
jmp 0x9e76
movl 0x98(%rsp), %eax
cmpl $0xd, %eax
jne 0x9e76
movzwl (%r15), %esi
movl %ebx, %edi
callq 0x302b9
testl %eax, %eax
jne 0x9e14
movq 0x8(%rsp), %rax
cmpq %rax, %rbp
cmovaq %rbp, %rax
movq %rax, 0x8(%rsp)
jmp 0x9de3
movq 0x8(%rsp), %rbx
movq 0x38(%rsp), %rdx
testq %rdx, %rdx
setne %al
cmpq %rdx, %rbx
seta %cl
testb %cl, %al
cmovneq %rdx, %rbx
leaq 0x3f973(%rip), %rax     # 0x49822
leaq 0x37243(%rip), %rcx     # 0x410f9
cmovneq %rax, %rcx
leaq -0x1(%rbx), %rsi
movl $0x40000, %edi          # imm = 0x40000
movl %r13d, %edx
callq 0x5605
leaq 0x4e2ae(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x98ba
leaq 0x37d8a(%rip), %rdi     # 0x41c6d
movq 0x88(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
jmp 0x98af
movq %r12, %rdi
callq 0x3190
movq %rax, %rbp
jmp 0x9cf2