// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %r8, 0x20(%rsp)
testq %rdi, %rdi
je 0x13b28
movq %r9, %r12
movq %rcx, %r13
movl %esi, %r15d
movq %rdi, %r14
movl 0x90(%rsp), %ebp
addq %rdx, %r13
movl $0x8, %esi
movq %r13, %rdx
callq 0x4865
testq %rax, %rax
je 0x133da
leaq 0x2fefd(%rip), %rsi     # 0x432c2
movl $0x8, %edx
movq %rax, %rdi
callq 0x31f0
testl %eax, %eax
je 0x1346f
leaq 0x44d9f(%rip), %r14     # 0x58180
movq (%r14), %rax
xorl %ebx, %ebx
btl $0x12, %eax
jae 0x13435
movl $0x40000, %edi          # imm = 0x40000
movq %r13, %rsi
movl %ebp, %edx
movq 0x88(%rsp), %rcx
callq 0x55eb
leaq 0x2dc8d(%rip), %rdi     # 0x41097
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
movq (%r14), %rax
testb $0x30, %al
je 0x13435
leaq 0x31fe6(%rip), %rdi     # 0x4540a
movq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq (%r14), %rax
btl $0x12, %eax
jb 0x1344e
movl %ebx, %edi
callq 0x1707a
leaq 0x31fce(%rip), %rdi     # 0x45417
callq 0x5c26
leaq 0x31fcd(%rip), %rdi     # 0x45422
callq 0x5c26
xorl %r13d, %r13d
movq %r13, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
callq 0x1707a
movl %eax, %ebp
movl $0x6, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r14, %rdi
callq 0x4865
movq %rax, %rbx
movzwl %r15w, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r14, %rdi
movl %esi, 0x2c(%rsp)
callq 0x45af
movzwl %ax, %r15d
leaq 0x44cd3(%rip), %rax     # 0x58180
movq (%rax), %rax
btl $0x12, %eax
movq %r14, 0x18(%rsp)
movq %r13, 0x38(%rsp)
jb 0x13734
testl $0x3033, %eax           # imm = 0x3033
leaq 0x44cb0(%rip), %r14     # 0x58180
je 0x134f5
movl 0x90(%rsp), %eax
leal 0x2(%rax), %edx
leaq 0x2e476(%rip), %rcx     # 0x41959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x55eb
movq (%r14), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x1355d
testb $0x40, %al
je 0x13518
leaq 0x31fe4(%rip), %rdi     # 0x454eb
movq 0x80(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq 0x31fcc(%rip), %rdi     # 0x454eb
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl %ebp, %r14d
leaq 0x355fb(%rip), %rdi     # 0x48b31
leaq 0x361bd(%rip), %rcx     # 0x496fa
movl $0x11, %esi
movl $0x11, %edx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
addl %r14d, %ebp
leaq 0x44c26(%rip), %r14     # 0x58180
movq (%r14), %rax
testb $0x30, %al
je 0x13574
leaq 0x352c1(%rip), %rdi     # 0x48829
movq %r13, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x1707a
movl %eax, %ebp
movq (%r14), %rax
testl $0x3033, %eax           # imm = 0x3033
je 0x135aa
movl 0x90(%rsp), %eax
leal 0x2(%rax), %edx
leaq 0x2e3c1(%rip), %rcx     # 0x41959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x55eb
movq (%r14), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x1360f
testb $0x40, %al
je 0x135cd
leaq 0x31f2f(%rip), %rdi     # 0x454eb
movq 0x80(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq 0x31f17(%rip), %rdi     # 0x454eb
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
leaq 0x35549(%rip), %rdi     # 0x48b31
leaq 0x36118(%rip), %rcx     # 0x49707
movl $0x11, %esi
movl $0x11, %edx
xorl %eax, %eax
callq 0x3120
addl %r14d, %eax
addl %eax, %ebp
leaq 0x44b74(%rip), %r14     # 0x58180
movq (%r14), %rax
testb $0x30, %al
je 0x13628
leaq 0x2dab1(%rip), %rdi     # 0x410cb
movq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x1707a
movl %eax, %ebp
movq (%r14), %rax
testl $0x3033, %eax           # imm = 0x3033
je 0x1365e
movl 0x90(%rsp), %eax
leal 0x2(%rax), %edx
leaq 0x2e30d(%rip), %rcx     # 0x41959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x55eb
movq (%r14), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x136c3
testb $0x40, %al
je 0x13681
leaq 0x31e7b(%rip), %rdi     # 0x454eb
movq 0x80(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq 0x31e63(%rip), %rdi     # 0x454eb
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
leaq 0x35495(%rip), %rdi     # 0x48b31
leaq 0x2fc57(%rip), %rcx     # 0x432fa
movl $0x11, %esi
movl $0x11, %edx
xorl %eax, %eax
callq 0x3120
addl %r14d, %eax
addl %eax, %ebp
leaq 0x44ac0(%rip), %rax     # 0x58180
movq (%rax), %rax
testb $0x30, %al
je 0x136da
leaq 0x2d9c6(%rip), %rdi     # 0x41094
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x1707a
movl %eax, %ebx
leal (%r15,%r15), %eax
leal (%rax,%rax,2), %eax
movq 0x20(%rsp), %rcx
leaq -0x10(%rcx), %r14
cmpq %rax, %r14
jae 0x137b2
movl %ebx, %edi
callq 0x1707a
movl %eax, %ebx
leaq 0x31d9d(%rip), %rdi     # 0x454a9
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
addl %ebx, %ebp
movl %r14d, %eax
movl $0xaaaaaaab, %r15d      # imm = 0xAAAAAAAB
imulq %rax, %r15
shrq $0x22, %r15
leaq 0x31d6b(%rip), %rdi     # 0x4549d
jmp 0x137a4
movl $0x40000, %edi          # imm = 0x40000
movq %r13, %rsi
movl 0x90(%rsp), %edx
movq 0x88(%rsp), %rcx
callq 0x55eb
leaq 0x31ce7(%rip), %rdi     # 0x4543e
movq %r12, %rsi
movq %rbx, %rdx
movq 0x20(%rsp), %r14
movq %r14, %rcx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
leal (%r15,%r15), %eax
leal (%rax,%rax,2), %eax
addq $-0x10, %r14
cmpq %rax, %r14
jae 0x137b2
movl %ebx, %edi
callq 0x1707a
movl %eax, %ebp
movl %r14d, %eax
movl $0xaaaaaaab, %r15d      # imm = 0xAAAAAAAB
imulq %rax, %r15
shrq $0x22, %r15
leaq 0x31cc0(%rip), %rdi     # 0x45464
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
movl 0x90(%rsp), %r14d
movq 0x18(%rsp), %rdi
callq 0x3190
movq %rax, %r13
leal 0x2(%r14), %eax
movl %eax, 0x14(%rsp)
testl %r15d, %r15d
je 0x13a0d
xorl %ebp, %ebp
movq 0x18(%rsp), %r14
movq %r12, 0x40(%rsp)
movq %r15, 0x30(%rsp)
movl %ebx, %edi
callq 0x1707a
movl %eax, %ebx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r14, %rdi
movl 0x2c(%rsp), %esi
callq 0x45af
movl %eax, %r15d
movq %r14, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x13b1b
movq %r14, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x13b1b
movl %ebp, 0x10(%rsp)
movq %r12, %rbp
leaq 0x4494c(%rip), %r12     # 0x58180
testl $0x4003333, (%r12)      # imm = 0x4003333
je 0x13883
movl $0x4003333, %edi        # imm = 0x4003333
movq %r13, %rsi
movl 0x14(%rsp), %edx
movq 0x88(%rsp), %rcx
callq 0x55eb
movq (%r12), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x13883
testb $0x40, %al
jne 0x1388c
testl $0x1040000, %eax        # imm = 0x1040000
movq %rbp, %r12
jne 0x138aa
leaq 0x31c74(%rip), %rdi     # 0x454eb
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
jmp 0x138a8
movq %rbp, %r12
movl 0x10(%rsp), %ebp
jmp 0x138f3
leaq 0x31c55(%rip), %rdi     # 0x454e8
movq 0x80(%rsp), %rsi
movq %rbp, %r12
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %r14d
movzwl %r15w, %esi
leaq 0x31c37(%rip), %rdi     # 0x454ef
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %r14d, %ebx
leaq 0x448b5(%rip), %rax     # 0x58180
testb $0x30, (%rax)
movl 0x10(%rsp), %ebp
je 0x138ee
movl $0x7, %edi
callq 0x5716
leaq 0x36cc3(%rip), %rdi     # 0x4a5a8
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movq 0x18(%rsp), %r14
movl $0x4, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r14, %rdi
callq 0x4865
movq %rax, %r15
addq $0x2, %r13
movq %r14, %rdi
movl 0x2c(%rsp), %esi
movq %r13, %rdx
callq 0x4707
movq %rax, %r13
leaq 0x4485b(%rip), %rax     # 0x58180
movq (%rax), %rax
btl $0x12, %eax
jb 0x13956
testb $0x30, %al
movq 0x30(%rsp), %r15
je 0x139f7
leaq 0x2d7aa(%rip), %rdi     # 0x410ec
movq %r13, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
jmp 0x139f7
testb $0x30, %al
je 0x139f2
xorl %r14d, %r14d
leaq 0x2e0a2(%rip), %r12     # 0x41a0a
movzbl (%r15,%r14), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
incq %r14
cmpq $0x4, %r14
jne 0x13968
leaq 0x2e087(%rip), %rdi     # 0x41a10
xorl %eax, %eax
callq 0x3120
movl %eax, 0x10(%rsp)
callq 0x32d0
movq %rax, %r12
xorl %r14d, %r14d
movq (%r12), %rcx
movzbl (%r15,%r14), %eax
movzwl (%rcx,%rax,2), %ecx
btl $0xe, %ecx
movl $0x2e, %edi
jae 0x139b9
movl %eax, %edi
callq 0x3060
incq %r14
cmpq $0x4, %r14
jne 0x1399f
movl 0x10(%rsp), %r14d
addl %ebx, %r14d
leaq 0x31b23(%rip), %rdi     # 0x454f9
movq %r13, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %r14d, %ebx
movq 0x40(%rsp), %r12
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %r15
movq %r14, %rdi
callq 0x3190
movq %rax, %r13
incl %ebp
cmpl %r15d, %ebp
jne 0x137e9
leaq 0x4476c(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x13b0c
movq 0x38(%rsp), %r14
addq 0x20(%rsp), %r14
movl %ebx, %edi
callq 0x1707a
movl %eax, %ebp
movq %r14, %r15
movq %r14, %rbx
subq %r13, %rbx
jbe 0x13ad9
leaq 0x44739(%rip), %rax     # 0x58180
testb $0x1, 0x3(%rax)
je 0x13ad9
leaq 0x2df01(%rip), %rcx     # 0x41959
movl $0x40000, %edi          # imm = 0x40000
movq %r13, %rsi
movl 0x14(%rsp), %edx
callq 0x55eb
leaq 0x31a96(%rip), %rdi     # 0x45506
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x1707a
movl %eax, %ebp
leaq 0x4597c(%rip), %rax     # 0x59408
movq (%rax), %rax
testq %rax, %rax
je 0x13ad0
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rcx
cmpq %rdx, %rax
je 0x13aab
cmpq %rbx, %rax
cmovaeq %rbx, %rax
movq %rax, %rcx
movslq %ecx, %rcx
movl $0xa, (%rsp)
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
movl $0x6, %r8d
movl 0x14(%rsp), %r9d
callq 0x7480
movl %ebp, %edi
callq 0x1707a
movl %eax, %ebp
movq %r15, %rsi
decq %rsi
leaq 0x2d613(%rip), %rcx     # 0x410f9
movl $0x40000, %edi          # imm = 0x40000
movl 0x90(%rsp), %edx
callq 0x55eb
leaq 0x2e031(%rip), %rdi     # 0x41b2f
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
movl %ebx, %edi
callq 0x17a82
decq %r13
jmp 0x1345d
movq %r14, %rdi
callq 0x31b0
jmp 0x1345a
callq 0x3417
jmp 0x1345a