// File: /workspace/github_c_makefile_star2_O2/hfiguiere[P]exifprobe/process.c
// Function: process_pim
unsigned long
process_pim(FILE *inptr,unsigned short byteorder,unsigned long pim_offset,
                    unsigned long fileoffset_base, unsigned long count,
                    char *tagname,char *dirname,char *prefix,
                    int indent)
{
    unsigned long entry_offset,extra,value;
    unsigned long max_offset = 0L;
    unsigned long max_value_offset = 0L;
    unsigned char *pim_id,*pim_version,*valueptr;
    unsigned short tag;
    int tagwidth = PIMTAGWIDTH;
    int chpr = 0;
    int entry_num,num_entries;

    if(inptr == (FILE *)0)
    {
        fprintf(stderr,"%s: no open file pointer to read Print Image data\n",
                Progname);
        max_offset = 0L;
        return(0L);
    }

    entry_offset = pim_offset + fileoffset_base;
    max_offset = entry_offset + count;

    /* Always starts with "PrintIM\0"; read it as a sanity check      */
    pim_id = read_bytes(inptr,8,entry_offset);
    if((pim_id == (unsigned char *)0) || strncasecmp((char *)pim_id,"PrintIM",8) != 0)
    {
        /* Print the value as a comment here, since we are processing */
        /* no further.                                                */
        if(PRINT_SECTION)
        {
            print_tag_address(SECTION,entry_offset,indent,prefix);
            chpr += printf("%s",tagname);
            if((PRINT_VALUE))
                chpr += printf(": length %lu",count);
        }
        if(!(PRINT_SECTION))
        {
            chpr = newline(chpr);
            printred("# WARNING:");
        }
        printred(" INVALID PrintImage data...");
        return(0L);
    }
    chpr = newline(0);

    pim_version = read_bytes(inptr,6,HERE);
    num_entries = read_ushort(inptr,byteorder,HERE);

    if(PRINT_SECTION)
    {
        print_tag_address(SECTION,entry_offset,indent,prefix);
        chpr += printf("<%s> Version %s, size %lu, %d entries",tagname,pim_version,
                                                                count,num_entries);
        if((num_entries * 6) > (count - 16))
        {
            chpr = newline(chpr);
            num_entries = (count - 16) / 6;
            PUSHCOLOR(HI_RED);
            chpr += printf("# WARNING: PIM claims too many entries for section size, printing %d",num_entries);
            POPCOLOR();
        }
    }
    else
    {

        /* Make pseudo-tags for these                                 */
        if((PRINT_TAGINFO) || (PRINT_VALUE))
            print_tag_address(ENTRY,HERE,indent+SMALLINDENT,"*");
        if(PRINT_TAGINFO)
        {
            if((PRINT_LONGNAMES))
                chpr += printf("%s.",dirname);
            chpr += printf("%s.",tagname);
            chpr += printf("%-*.*s",tagwidth,tagwidth,"Offset");
        }
        if((PRINT_VALUE))
            chpr += printf(" = @%lu",entry_offset);
        chpr = newline(chpr);
        if((PRINT_TAGINFO) || (PRINT_VALUE))
            print_tag_address(ENTRY,HERE,indent+SMALLINDENT,"*");
        if(PRINT_TAGINFO)
        {
            if((PRINT_LONGNAMES))
                chpr += printf("%s.",dirname);
            chpr += printf("%s.",tagname);
            chpr += printf("%-*.*s",tagwidth,tagwidth,"Length");
        }
        if((PRINT_VALUE))
            chpr += printf(" = %lu",count);
        chpr = newline(chpr);
        if((PRINT_TAGINFO) || (PRINT_VALUE))
            print_tag_address(ENTRY,HERE,indent+SMALLINDENT,"*");
        if(PRINT_TAGINFO)
        {
            if((PRINT_LONGNAMES))
                chpr += printf("%s.",dirname);
            chpr += printf("%s.",tagname);
            chpr += printf("%-*.*s",tagwidth,tagwidth,"Version");
        }
        if((PRINT_VALUE))
            chpr += printf(" = %s",pim_version);
        chpr = newline(chpr);
        if((num_entries * 6) > (count - 16))
        {
            chpr = newline(chpr);
            chpr += printf("# WARNING: PIM claims too many entries (%d) for section size; ",num_entries);
            num_entries = (count - 16) / 6;
            PUSHCOLOR(HI_RED);
            chpr += printf("printing %d",num_entries);
            POPCOLOR();
        }
    }
    
    max_value_offset = entry_offset = ftell(inptr);

    indent += SMALLINDENT;
    for(entry_num = 0; entry_num < num_entries; ++entry_num)
    {
        int i;

        chpr = newline(chpr);
        tag = read_ushort(inptr,byteorder,HERE);
        if(ferror(inptr) || feof(inptr))
            goto blewit;
        if((PRINT_ENTRY))
        {
            print_tag_address(ENTRY,entry_offset,indent,prefix);
            if((PRINT_TAGINFO))
            {
                if((PRINT_LONGNAMES))
                    chpr += printf("%s.%s.",dirname,tagname);
                else if((LIST_MODE))
                    chpr += printf("%s.",tagname);
                chpr += printf("PIM_%#06X",(int)tag);
                if((PRINT_VALUE))
                {
                    putindent(tagwidth - 10);
                    chpr += printf(" = ");
                }
            }
        }
        valueptr = read_bytes(inptr,4,HERE);
        value = read_ulong(inptr,byteorder,entry_offset + 2);

        if(PRINT_SECTION)
        {
            if((PRINT_VALUE))
            {
                for(i = 0; i < 4; ++i)
                    chpr += printf("%02x ",(unsigned int)(valueptr[i] & 0xff));
                chpr += printf(" |");
                for(i = 0; i < 4; ++i)
                {
                    if(isprint(valueptr[i]))
                        putchar(valueptr[i]);
                    else
                        putchar('.');  /* can't win 'em all  */
                }
                chpr += printf("| = %#lx/%lu",value,value);
            }
        }
        else if((PRINT_VALUE))
            chpr += printf("%#lx/%lu",value,value);

        max_value_offset = entry_offset = ftell(inptr);
    }

    if(PRINT_SECTION)
    {
        chpr = newline(chpr);
        if((max_value_offset < max_offset) && PRINT_VALUE_AT_OFFSET)
        {
            int printlength = 0;

            print_tag_address(SECTION,max_value_offset,indent,"*");
            PUSHCOLOR(RED);
            chpr += printf("---- End of values before end of %s section",tagname);
            POPCOLOR();
            chpr = newline(chpr);
            extra = max_offset - max_value_offset;
            /* dump the extra as UNDEFINED                            */
            if(Max_undefined)
            {
                if((Max_undefined == DUMPALL) || (Max_undefined > extra))
                    printlength = extra;
                else if(Max_undefined > 0L)
                    printlength = Max_undefined;
                hexdump(inptr,max_value_offset,extra,printlength,6,indent,
                                                    SMALLINDENT+8);
            }
            chpr = newline(chpr);
        }
        indent -= SMALLINDENT;
        print_tag_address(SECTION,max_offset - 1,indent,"-");
        chpr += printf("</%s>",tagname);
    }

    setcharsprinted(chpr);
    return(max_value_offset - 1);
blewit:
    clearerr(inptr);
    return(0L);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
testq %rdi, %rdi
je 0x129ba
movq %r9, %r15
movq %r8, %r13
movl %esi, %ebx
addq %rdx, %rcx
pushq $0x8
popq %rsi
movq %rdi, 0x28(%rsp)
movq %rcx, %r12
movq %rcx, %rdx
callq 0x4410
testq %rax, %rax
je 0x125fc
leaq 0x2ecd9(%rip), %rsi     # 0x412c2
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x31f0
testl %eax, %eax
je 0x12691
leaq 0x44b7d(%rip), %r14     # 0x57180
movq (%r14), %rax
xorl %ebx, %ebx
btl $0x12, %eax
jae 0x12657
movl $0x40000, %edi          # imm = 0x40000
movq %r12, %rsi
movl 0x80(%rsp), %edx
movq 0x78(%rsp), %rcx
callq 0x5100
leaq 0x2ca69(%rip), %rdi     # 0x3f097
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
movq (%r14), %rax
testb $0x30, %al
je 0x12657
leaq 0x30d7e(%rip), %rdi     # 0x433c6
movq %r13, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq (%r14), %rax
btl $0x12, %eax
jb 0x12670
movl %ebx, %edi
callq 0x160f7
leaq 0x30d68(%rip), %rdi     # 0x433d3
callq 0x56e2
leaq 0x30d67(%rip), %rdi     # 0x433de
callq 0x56e2
xorl %r13d, %r13d
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x18(%rsp)
movq %r15, 0x8(%rsp)
xorl %edi, %edi
callq 0x160f7
movl %eax, %r15d
pushq $0x6
popq %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x4410
movq %rax, %r13
movzwl %bx, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r14, %rdi
movl %esi, 0x24(%rsp)
callq 0x416a
movzwl %ax, %r14d
leaq 0x44aa4(%rip), %rbp     # 0x57180
movq (%rbp), %rax
btl $0x12, %eax
jb 0x12938
testw $0x3033, %ax            # imm = 0x3033
je 0x12714
movl 0x80(%rsp), %eax
leal 0x2(%rax), %edx
leaq 0x2d258(%rip), %rcx     # 0x3f959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5100
movq (%rbp), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x12770
testb $0x40, %al
je 0x12734
leaq 0x30d82(%rip), %rdi     # 0x434a7
movq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r15d
leaq 0x30d6c(%rip), %rdi     # 0x434a7
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %r15d, %ebx
leaq 0x3438e(%rip), %rdi     # 0x46ae1
leaq 0x34f50(%rip), %rcx     # 0x476aa
pushq $0x11
popq %rdx
movl %edx, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl %ebx, %r15d
movq (%rbp), %rax
testb $0x30, %al
je 0x12788
leaq 0x3405e(%rip), %rdi     # 0x467d9
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r15d
movl %r15d, %edi
callq 0x160f7
movl %eax, %ebx
movq (%rbp), %rax
testw $0x3033, %ax            # imm = 0x3033
je 0x127c0
movl 0x80(%rsp), %eax
leal 0x2(%rax), %edx
leaq 0x2d1ac(%rip), %rcx     # 0x3f959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5100
movq (%rbp), %rax
testw $0x3003, %ax            # imm = 0x3003
movq 0x8(%rsp), %r15
je 0x12820
testb $0x40, %al
je 0x127e4
leaq 0x30cd1(%rip), %rdi     # 0x434a7
movq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x30cbc(%rip), %rdi     # 0x434a7
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
leaq 0x342e3(%rip), %rdi     # 0x46ae1
leaq 0x34eb2(%rip), %rcx     # 0x476b7
pushq $0x11
popq %rdx
movl %edx, %esi
xorl %eax, %eax
callq 0x3120
addl %ebp, %eax
addl %eax, %ebx
leaq 0x44964(%rip), %rbp     # 0x57180
movq (%rbp), %rax
testb $0x30, %al
je 0x12839
leaq 0x2c8a0(%rip), %rdi     # 0x3f0cb
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
movq (%rbp), %rax
testw $0x3033, %ax            # imm = 0x3033
je 0x12870
movl 0x80(%rsp), %eax
leal 0x2(%rax), %edx
leaq 0x2d0fc(%rip), %rcx     # 0x3f959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5100
movq (%rbp), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x128cb
testb $0x40, %al
je 0x1288f
leaq 0x30c26(%rip), %rdi     # 0x434a7
movq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
leaq 0x30c11(%rip), %rdi     # 0x434a7
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
leaq 0x34238(%rip), %rdi     # 0x46ae1
leaq 0x2ea4a(%rip), %rcx     # 0x412fa
pushq $0x11
popq %rdx
movl %edx, %esi
xorl %eax, %eax
callq 0x3120
addl %ebp, %eax
addl %eax, %ebx
leaq 0x448b9(%rip), %rbp     # 0x57180
movq (%rbp), %rax
testb $0x30, %al
je 0x128e2
leaq 0x2c7be(%rip), %rdi     # 0x3f094
movq %r13, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq 0x18(%rsp), %r13
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
imull $0x6, %r14d, %eax
movl %r14d, %r15d
leaq -0x10(%r13), %r14
cmpq %rax, %r14
jae 0x129e4
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
leaq 0x30b51(%rip), %rdi     # 0x43465
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
addl %ebx, %ebp
movl %r14d, %eax
xorl %edx, %edx
pushq $0x6
popq %rcx
divl %ecx
movl %eax, %r14d
leaq 0x30b23(%rip), %rdi     # 0x43459
jmp 0x129a4
movl $0x40000, %edi          # imm = 0x40000
movq %r12, %rsi
movl 0x80(%rsp), %edx
movq 0x78(%rsp), %rcx
callq 0x5100
leaq 0x30aa2(%rip), %rdi     # 0x433fa
movq 0x8(%rsp), %rsi
movq %r13, %rdx
movq 0x18(%rsp), %r13
movq %r13, %rcx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %r15d, %ebx
movl %r14d, %ecx
imull $0x6, %r14d, %eax
leaq -0x10(%r13), %r14
cmpq %rax, %r14
jae 0x129ee
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebp
movl %r14d, %eax
xorl %edx, %edx
pushq $0x6
popq %rcx
divl %ecx
movl %eax, %r14d
leaq 0x30a7c(%rip), %rdi     # 0x43420
movl %eax, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
leaq 0x447c8(%rip), %rbp     # 0x57180
jmp 0x129e7
movq 0x44637(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0x45a9d(%rip), %rax     # 0x58468
movq (%rax), %rdx
leaq 0x309be(%rip), %rsi     # 0x43393
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x3180
jmp 0x1267f
movl %r15d, %r14d
movq 0x8(%rsp), %r15
jmp 0x129f6
movq 0x8(%rsp), %r15
movl %ecx, %r14d
addq %r13, %r12
movq %r12, 0x30(%rsp)
movq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x3190
movq %rax, %r13
movl 0x80(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x10(%rsp)
xorl %eax, %eax
movl %r14d, 0x14(%rsp)
cmpl %r14d, %eax
je 0x12c2c
movl %eax, 0x18(%rsp)
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %rdi
movl 0x24(%rsp), %esi
callq 0x416a
movl %eax, %r14d
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x12c1f
movq %r12, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x12c1f
testl $0x4003333, (%rbp)      # imm = 0x4003333
je 0x12b0d
movl $0x4003333, %edi        # imm = 0x4003333
movq %r13, %rsi
movl 0x10(%rsp), %edx
movq 0x78(%rsp), %rcx
callq 0x5100
movq (%rbp), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x12b0d
testb $0x40, %al
jne 0x12ab8
testl $0x1040000, %eax        # imm = 0x1040000
jne 0x12ad0
leaq 0x309fb(%rip), %rdi     # 0x434a7
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
jmp 0x12ace
leaq 0x309e5(%rip), %rdi     # 0x434a4
movq 0x70(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %ebp
movzwl %r14w, %esi
leaq 0x309ce(%rip), %rdi     # 0x434ab
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
leaq 0x44691(%rip), %rbp     # 0x57180
testb $0x30, (%rbp)
je 0x12b0d
pushq $0x7
popq %rdi
callq 0x521b
leaq 0x35a54(%rip), %rdi     # 0x48558
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %rdi
pushq $0x4
popq %rsi
callq 0x4410
movq %rax, %r14
addq $0x2, %r13
movq %r12, %rdi
movl 0x24(%rsp), %esi
movq %r13, %rdx
callq 0x42ba
movq %rax, %r13
movq (%rbp), %rax
btl $0x12, %eax
jb 0x12b68
testb $0x30, %al
movl 0x14(%rsp), %r14d
je 0x12c09
leaq 0x2c598(%rip), %rdi     # 0x3f0ec
movq %r13, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
jmp 0x12c09
testb $0x30, %al
je 0x12c04
xorl %r15d, %r15d
leaq 0x2ce90(%rip), %r12     # 0x3fa0a
cmpq $0x4, %r15
je 0x12b96
movzbl (%r14,%r15), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
incq %r15
jmp 0x12b7a
leaq 0x2ce73(%rip), %rdi     # 0x3fa10
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
callq 0x32d0
movq %rax, %r12
xorl %r15d, %r15d
cmpq $0x4, %r15
je 0x12bd9
movq (%r12), %rcx
movzbl (%r14,%r15), %eax
movzwl (%rcx,%rax,2), %ecx
btl $0xe, %ecx
pushq $0x2e
popq %rdi
jae 0x12bcf
movl %eax, %edi
callq 0x3060
incq %r15
jmp 0x12bb1
addl %ebx, %ebp
leaq 0x308d3(%rip), %rdi     # 0x434b5
movq %r13, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
movq 0x8(%rsp), %r15
movq 0x28(%rsp), %r12
leaq 0x4457c(%rip), %rbp     # 0x57180
movl 0x14(%rsp), %r14d
movq %r12, %rdi
callq 0x3190
movq %rax, %r13
movl 0x18(%rsp), %eax
incl %eax
jmp 0x12a23
movq %r12, %rdi
callq 0x31b0
jmp 0x1267c
testb $0x4, 0x2(%rbp)
je 0x12d1a
movl %ebx, %edi
callq 0x160f7
movl %eax, %ebp
movq 0x30(%rsp), %rsi
movq %rsi, %rbx
subq %r13, %rbx
jbe 0x12cea
leaq 0x44529(%rip), %rax     # 0x57180
testb $0x1, 0x3(%rax)
je 0x12cea
leaq 0x2ccf1(%rip), %rcx     # 0x3f959
movl $0x40000, %edi          # imm = 0x40000
movq %r13, %rsi
movl 0x10(%rsp), %edx
callq 0x5100
leaq 0x30842(%rip), %rdi     # 0x434c2
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
leaq 0x4576c(%rip), %rax     # 0x58408
movq (%rax), %rax
testq %rax, %rax
je 0x12cdc
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rcx
cmpq %rdx, %rax
je 0x12cbb
cmpq %rbx, %rax
cmovaeq %rbx, %rax
movq %rax, %rcx
movslq %ecx, %rcx
movl $0xa, (%rsp)
pushq $0x6
popq %r8
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movl 0x10(%rsp), %r9d
callq 0x6e93
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
movq 0x30(%rsp), %rsi
decq %rsi
leaq 0x2c405(%rip), %rcx     # 0x3f0f9
movl $0x40000, %edi          # imm = 0x40000
movl 0x80(%rsp), %edx
callq 0x5100
leaq 0x2ce23(%rip), %rdi     # 0x3fb2f
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
movl %ebx, %edi
callq 0x16a4f
decq %r13
jmp 0x1267f