// File: /workspace/github_c_makefile_star2_O1/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 0x13707
movq %r9, %r13
movq %rcx, %r14
movl %esi, %r15d
movq %rdi, %r12
movq 0x88(%rsp), %rbp
addq %rdx, %r14
movl $0x8, %esi
movq %r14, %rdx
callq 0x4832
testq %rax, %rax
je 0x12f83
leaq 0x30354(%rip), %rsi     # 0x432c2
movl $0x8, %edx
movq %rax, %rdi
callq 0x31f0
testl %eax, %eax
je 0x13013
movq %r14, %rsi
leaq 0x451f3(%rip), %r14     # 0x58180
xorl %ebx, %ebx
testb $0x4, 0x2(%r14)
je 0x12fd8
movl $0x40000, %edi          # imm = 0x40000
movl 0x90(%rsp), %edx
movq %rbp, %rcx
callq 0x5605
leaq 0x2e0e6(%rip), %rdi     # 0x41097
movq %r13, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
testb $0x30, (%r14)
je 0x12fd8
leaq 0x323fc(%rip), %rdi     # 0x453c6
movq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
testb $0x4, 0x2(%r14)
jne 0x12ff2
movl %ebx, %edi
callq 0x16b56
leaq 0x323e6(%rip), %rdi     # 0x453d3
callq 0x5c33
leaq 0x323e5(%rip), %rdi     # 0x453de
callq 0x5c33
xorl %r12d, %r12d
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x8(%rsp)
xorl %edi, %edi
callq 0x16b56
movl %eax, %ebp
movl $0x6, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %rdi
callq 0x4832
movq %rax, %rbx
movzwl %r15w, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %rdi
movl %esi, 0x30(%rsp)
callq 0x4574
movzwl %ax, %r13d
leaq 0x4512a(%rip), %r15     # 0x58180
movq (%r15), %rax
btl $0x12, %eax
jb 0x132ec
testl $0x3033, %eax           # imm = 0x3033
je 0x1308a
movl 0x90(%rsp), %eax
leal 0x2(%rax), %edx
leaq 0x2e8de(%rip), %rcx     # 0x41959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5605
movq (%r15), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x130f4
testb $0x40, %al
je 0x130b0
leaq 0x32408(%rip), %rdi     # 0x454a7
movq 0x80(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq 0x323f0(%rip), %rdi     # 0x454a7
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl %ebp, %r15d
leaq 0x35a21(%rip), %rdi     # 0x48af1
leaq 0x365e3(%rip), %rcx     # 0x496ba
movl $0x11, %esi
movl $0x11, %edx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
addl %r15d, %ebp
leaq 0x4508c(%rip), %r15     # 0x58180
testb $0x30, (%r15)
je 0x1310d
leaq 0x356e8(%rip), %rdi     # 0x487e9
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x16b56
movl %eax, %ebp
movzwl (%r15), %eax
testl $0x3033, %eax           # imm = 0x3033
je 0x13141
movl 0x90(%rsp), %eax
leal 0x2(%rax), %edx
leaq 0x2e827(%rip), %rcx     # 0x41959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5605
movq (%r15), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x131a8
testb $0x40, %al
je 0x13167
leaq 0x32351(%rip), %rdi     # 0x454a7
movq 0x80(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq 0x32339(%rip), %rdi     # 0x454a7
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
leaq 0x3596d(%rip), %rdi     # 0x48af1
leaq 0x3653c(%rip), %rcx     # 0x496c7
movl $0x11, %esi
movl $0x11, %edx
xorl %eax, %eax
callq 0x3120
addl %r15d, %eax
addl %eax, %ebp
leaq 0x44fd8(%rip), %r15     # 0x58180
testb $0x30, (%r15)
je 0x131c3
leaq 0x2df16(%rip), %rdi     # 0x410cb
movq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x16b56
movl %eax, %ebp
movzwl (%r15), %eax
testl $0x3033, %eax           # imm = 0x3033
je 0x131f7
movl 0x90(%rsp), %eax
leal 0x2(%rax), %edx
leaq 0x2e771(%rip), %rcx     # 0x41959
movl $0x4003333, %edi        # imm = 0x4003333
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5605
movq (%r15), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x1325e
testb $0x40, %al
je 0x1321d
leaq 0x3229b(%rip), %rdi     # 0x454a7
movq 0x80(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq 0x32283(%rip), %rdi     # 0x454a7
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
leaq 0x358b7(%rip), %rdi     # 0x48af1
leaq 0x300b9(%rip), %rcx     # 0x432fa
movl $0x11, %esi
movl $0x11, %edx
xorl %eax, %eax
callq 0x3120
addl %r15d, %eax
addl %eax, %ebp
leaq 0x44f22(%rip), %r15     # 0x58180
testb $0x30, (%r15)
je 0x13277
leaq 0x2de29(%rip), %rdi     # 0x41094
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x16b56
movl %eax, %ebx
leal (,%r13,2), %eax
leal (%rax,%rax,2), %eax
movq 0x20(%rsp), %rcx
leaq -0x10(%rcx), %r15
cmpq %rax, %r15
jae 0x13378
movl %ebx, %edi
callq 0x16b56
movl %eax, %ebp
leaq 0x321b8(%rip), %rdi     # 0x45465
movl %r13d, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %r13d
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
movq %r15, %rax
mulq %rcx
movq %rdx, %r15
shrq $0x2, %r15
leaq 0x32181(%rip), %rdi     # 0x45459
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %r13d, %ebx
jmp 0x13374
movl $0x40000, %edi          # imm = 0x40000
movq %r14, %rsi
movl 0x90(%rsp), %edx
movq 0x88(%rsp), %rcx
callq 0x5605
leaq 0x320eb(%rip), %rdi     # 0x453fa
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
movq 0x20(%rsp), %r15
movq %r15, %rcx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
leal (,%r13,2), %eax
leal (%rax,%rax,2), %eax
addq $-0x10, %r15
cmpq %rax, %r15
jae 0x13378
movl %ebx, %edi
callq 0x16b56
movl %eax, %ebp
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
movq %r15, %rax
mulq %rcx
movq %rdx, %r15
shrq $0x2, %r15
leaq 0x320b8(%rip), %rdi     # 0x45420
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
jmp 0x1337b
movq %r13, %r15
movq %r14, 0x38(%rsp)
movq %r12, 0x28(%rsp)
movq %r12, %rdi
callq 0x3190
movq %rax, 0x10(%rsp)
movl 0x90(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x1c(%rsp)
testl %r15d, %r15d
jle 0x135d9
leaq 0x2e65a(%rip), %r13     # 0x41a0a
xorl %r14d, %r14d
movq %r15, 0x40(%rsp)
movq %r13, %r12
movl %ebx, %edi
callq 0x16b56
movl %eax, %ebx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x28(%rsp), %r13
movq %r13, %rdi
movl 0x30(%rsp), %esi
callq 0x4574
movl %eax, %ebp
movq %r13, %rdi
callq 0x30b0
movl $0x5, %r15d
testl %eax, %eax
jne 0x133fa
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
je 0x13418
movq %r12, %r13
testl %r15d, %r15d
jne 0x135f1
incl %r14d
movq 0x40(%rsp), %r15
cmpl %r15d, %r14d
jne 0x133b8
jmp 0x135d9
leaq 0x44d61(%rip), %r15     # 0x58180
testl $0x4003333, (%r15)      # imm = 0x4003333
je 0x134ce
movl $0x4003333, %edi        # imm = 0x4003333
movq 0x10(%rsp), %rsi
movl 0x1c(%rsp), %edx
movq 0x88(%rsp), %rcx
callq 0x5605
movq (%r15), %rax
testl $0x3003, %eax           # imm = 0x3003
je 0x134ce
testb $0x40, %al
jne 0x13471
testl $0x1040000, %eax        # imm = 0x1040000
jne 0x1348e
leaq 0x32044(%rip), %rdi     # 0x454a7
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
jmp 0x1348c
leaq 0x3202c(%rip), %rdi     # 0x454a4
movq 0x80(%rsp), %rsi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %r15d
movzwl %bp, %esi
leaq 0x32010(%rip), %rdi     # 0x454ab
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %r15d, %ebx
leaq 0x44cd2(%rip), %r15     # 0x58180
testb $0x30, (%r15)
je 0x134ce
movl $0x7, %edi
callq 0x5730
leaq 0x370a3(%rip), %rdi     # 0x4a568
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl $0x4, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0x4832
movq %rax, %rbp
movq 0x10(%rsp), %rdx
addq $0x2, %rdx
movq %r13, %rdi
movl 0x30(%rsp), %esi
callq 0x46cc
movq %rax, %rdx
movq (%r15), %rax
btl $0x12, %eax
jb 0x1352c
testb $0x30, %al
movq %r12, %r13
je 0x135c2
leaq 0x2dbd1(%rip), %rdi     # 0x410ec
movq %rdx, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
jmp 0x135c2
testb $0x30, %al
movq %r12, %r13
je 0x135c2
movq %rdx, 0x10(%rsp)
xorl %r15d, %r15d
movzbl (%rbp,%r15), %esi
movq %r13, %rdi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
incq %r15
cmpq $0x4, %r15
jne 0x1353f
leaq 0x2e4af(%rip), %rdi     # 0x41a10
xorl %eax, %eax
callq 0x3120
movl %eax, 0x34(%rsp)
callq 0x32d0
movq %rax, %r15
xorl %r13d, %r13d
movq (%r15), %rcx
movzbl (%rbp,%r13), %eax
movzwl (%rcx,%rax,2), %ecx
btl $0xe, %ecx
movl $0x2e, %edi
jae 0x13591
movl %eax, %edi
callq 0x3060
incq %r13
cmpq $0x4, %r13
jne 0x13577
movl 0x34(%rsp), %ebp
addl %ebx, %ebp
leaq 0x31f09(%rip), %rdi     # 0x454b5
movq 0x10(%rsp), %rdx
movq %rdx, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
movq %r12, %r13
movq 0x28(%rsp), %rdi
callq 0x3190
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
jmp 0x133fd
leaq 0x44ba0(%rip), %r15     # 0x58180
testb $0x4, 0x2(%r15)
jne 0x1360a
movq 0x10(%rsp), %r12
jmp 0x136f8
cmpl $0x5, %r15d
jne 0x13711
movq 0x28(%rsp), %rdi
callq 0x31b0
jmp 0x12ffe
movq 0x38(%rsp), %r14
addq 0x20(%rsp), %r14
movl %ebx, %edi
callq 0x16b56
movl %eax, %ebp
movq %r14, %rbx
movq 0x10(%rsp), %r12
subq %r12, %rbx
jbe 0x136c3
testb $0x1, 0x3(%r15)
je 0x136c3
leaq 0x2e319(%rip), %rcx     # 0x41959
movl $0x40000, %edi          # imm = 0x40000
movq %r12, %rsi
movl 0x1c(%rsp), %edx
callq 0x5605
leaq 0x31e6a(%rip), %rdi     # 0x454c2
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x16b56
movl %eax, %ebp
leaq 0x45d92(%rip), %rax     # 0x59408
movq (%rax), %rax
testq %rax, %rax
je 0x136ba
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rcx
cmpq %rdx, %rax
je 0x13695
cmpq %rbx, %rax
cmovaeq %rbx, %rax
movq %rax, %rcx
movslq %ecx, %rcx
movl $0xa, (%rsp)
movq 0x28(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movl $0x6, %r8d
movl 0x1c(%rsp), %r9d
callq 0x7446
movl %ebp, %edi
callq 0x16b56
movl %eax, %ebp
decq %r14
leaq 0x2da2c(%rip), %rcx     # 0x410f9
movl $0x40000, %edi          # imm = 0x40000
movq %r14, %rsi
movl 0x90(%rsp), %edx
callq 0x5605
leaq 0x2e447(%rip), %rdi     # 0x41b2f
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
addl %ebp, %ebx
movl %ebx, %edi
callq 0x17530
decq %r12
jmp 0x13001
callq 0x3417
jmp 0x12ffe
jmp 0x13001