// File: /workspace/github_c_makefile_star2_O1/hfiguiere[P]exifprobe/process.c
// Function: process_gps_ifd
unsigned long
process_gps_ifd(FILE *inptr,unsigned short byteorder,
                    unsigned long gps_offset,unsigned long fileoffset_base,
                    unsigned long max_offset,struct image_summary *summary_entry,
                    char *parent_name,int ifdnum,int indent)
{
    struct ifd_entry *entry_ptr;
    unsigned long max_value_offset = 0L;
    unsigned long next_ifd_offset,current_offset,max_gps_offset;
    unsigned long start_entry_offset,entry_offset,value_offset;
    int entry_num,num_entries,value_is_offset,use_second_pass;
    int chpr = 0;
    char *fulldirname = CNULL;

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

    PUSHCOLOR(GPS_COLOR);
    /* If the gps segment appears to be beyond the start of the       */
    /* parent ifd, mark the start address funny.                      */
    if(max_offset && (gps_offset > max_offset))
        print_tag_address(SECTION,gps_offset + fileoffset_base,indent,"^");
    else
        print_tag_address(SECTION,gps_offset + fileoffset_base,indent,"@");
    if(PRINT_SECTION)
        chpr += printf("<GPS IFD> (in IFD %d)",ifdnum);

    num_entries = read_ushort(inptr,byteorder,gps_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;
    fulldirname = splice(parent_name,".","Gps");

    indent += SMALLINDENT;
    /* The direct entries                                             */
    for(entry_num = 0; entry_num < num_entries; ++entry_num)
    {
        print_tag_address(ENTRY,entry_offset,indent,"@");
        entry_ptr = read_ifd_entry(inptr,byteorder,entry_offset);
        if((entry_ptr->value_type == 0) || (entry_ptr->value_type > DOUBLE) ||
            ferror(inptr) || feof(inptr))
        {
            print_tag_address(ENTRY,entry_offset,indent,"@");
            chpr += printf(" INVALID (%lu)",entry_ptr->value);
            chpr = newline(chpr);
            /* ###%%% replace with check code from process_tiff_ifd() */
            goto blewit;
        }
        entry_offset = current_offset = ftell(inptr);
        value_offset = print_entry(inptr,byteorder,entry_ptr,fileoffset_base,
                                            summary_entry,fulldirname,GPS_IFD,
                                            ifdnum,-1,SMALLINDENT);
        if(value_offset == 0UL)
            value_offset = entry_offset;
        if(value_offset > max_value_offset)
            max_value_offset = value_offset;
        if((PRINT_VALUE_AT_OFFSET) && (is_offset(entry_ptr)))
            ++use_second_pass;
    }

    next_ifd_offset = read_ulong(inptr,byteorder,current_offset);

    /* offsets found in the next pass should be within the bounds of  */
    /* the ifd. The following helps to detect chunks that are written */
    /* "out of place".                                                */
    if(next_ifd_offset > 0L)
    {
        if((PRINT_VALUE) && (PRINT_SECTION) && (PRINT_VALUE_AT_OFFSET))
        {
            print_tag_address(SECTION,current_offset,indent,"@");
            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_gps_offset = next_ifd_offset;
        if(max_offset && (max_gps_offset > max_offset))
            max_gps_offset = max_offset;
    }
    else
    {
        max_gps_offset = max_offset;    
        if((PRINT_VALUE) && (PRINT_SECTION) && (PRINT_VALUE_AT_OFFSET))
        {
            print_tag_address(SECTION,current_offset,indent,"@");
            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;

    /* Make a second pass to print offset values.                     */
    if(use_second_pass)
    {
        if((PRINT_VALUE) && (PRINT_SECTION) && (PRINT_VALUE_AT_OFFSET))
        {
            print_tag_address(SECTION,value_offset,indent,"@");
            chpr += printf("============= VALUES, GPS IFD ============");
            chpr = newline(chpr);
        }

        /* Second pass, to evaluate entries which are stored          */
        /* indirectly (the value requires more than 4 bytes).         */
        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))
            {
                print_tag_address(ENTRY,entry_offset,indent,"@");
                chpr += printf(" INVALID (%lu)",entry_ptr->value);
                chpr = newline(chpr);
                goto blewit;
            }
            current_offset = entry_offset = ftell(inptr);
            switch(entry_ptr->tag)
            {
                default:
                    if((PRINT_VALUE) && ((PRINT_VALUE_AT_OFFSET) && is_offset(entry_ptr)))
                    {
                        print_tag_address(ENTRY,fileoffset_base + entry_ptr->value,
                                            indent,"@");
                        print_tagid(entry_ptr,SMALLINDENT,GPS_IFD);
                        value_offset =
                                    print_offset_value(inptr,byteorder,entry_ptr,
                                                    fileoffset_base,fulldirname,
                                                    GPS_IFD,indent,1);
                    }
                    break;
            }
            if(value_offset > max_value_offset)
                max_value_offset = value_offset;
        }
    }
    else if(current_offset > max_value_offset)
        max_value_offset = current_offset;

    indent -= SMALLINDENT;
    if(max_offset && (gps_offset > max_offset))
    {
        print_tag_address(SECTION,max_value_offset - 1,indent,">");
        max_value_offset = 0L;  /* let the caller know.               */
    }
    else
        print_tag_address(SECTION,max_value_offset - 1,indent,"-");
    if(PRINT_SECTION)
    {
        chpr += printf("</GPS IFD>");
        chpr = newline(chpr);
    }
    POPCOLOR();
    if(next_ifd_offset)
    {
        printred("#========= WARNING! CHAINING NEXT IFD FROM GPS IFD =========");
        chpr = newline(1);
        value_offset = process_tiff_ifd(inptr,byteorder,next_ifd_offset,
                                fileoffset_base,max_offset,NULL,fulldirname,
                                GPS_IFD,-1,-1,indent);
        if(value_offset > max_value_offset)
            max_value_offset = value_offset;
    }
    if(fulldirname)
        free(fulldirname);
    return(max_value_offset);
blewit:
    clearerr(inptr);
    current_offset = ftell(inptr);
    print_tag_address(SECTION,current_offset - 1,indent,"-");
    if(PRINT_SECTION)
    {
        chpr += printf("</GPS IFD>");
        chpr = newline(chpr);
    }
    if(fulldirname)
        free(fulldirname);
    POPCOLOR();
    return(0L);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
testq %rdi, %rdi
je 0x10eb3
movq %r9, %r14
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %rbx
movl 0xa0(%rsp), %edx
testq %r8, %r8
setne %al
movq %r8, 0x50(%rsp)
cmpq %r8, %r15
seta %sil
andb %al, %sil
movq %rcx, 0x30(%rsp)
addq %rcx, %r15
leaq 0x340c4(%rip), %rax     # 0x44ce0
leaq 0x304b9(%rip), %rcx     # 0x410dc
movb %sil, 0x13(%rsp)
testb %sil, %sil
cmovneq %rax, %rcx
movl $0x40000, %edi          # imm = 0x40000
movq %r15, %rsi
callq 0x5605
leaq 0x4753d(%rip), %rbp     # 0x58180
xorl %eax, %eax
testb $0x4, 0x2(%rbp)
je 0x10c60
leaq 0x34090(%rip), %rdi     # 0x44ce2
movl 0x98(%rsp), %esi
xorl %eax, %eax
callq 0x3120
movl %eax, 0xc(%rsp)
movzwl %r12w, %r12d
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0x4574
movl %eax, %r13d
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x10c91
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
je 0x10d07
xorl %r14d, %r14d
movl 0xa0(%rsp), %eax
movl %eax, %r15d
movq %rbx, %rdi
callq 0x31b0
movq %rbx, %rdi
callq 0x3190
leaq -0x1(%rax), %rsi
leaq 0x30440(%rip), %rcx     # 0x410f9
movl $0x40000, %edi          # imm = 0x40000
movl %r15d, %edx
callq 0x5605
testb $0x4, 0x2(%rbp)
je 0x10ce5
leaq 0x3405f(%rip), %rdi     # 0x44d32
xorl %eax, %eax
callq 0x3120
movl 0xc(%rsp), %edi
addl %eax, %edi
callq 0x16b56
testq %r14, %r14
je 0x10cf2
movq %r14, %rdi
callq 0x3050
xorl %r14d, %r14d
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, 0x18(%rsp)
movq 0x90(%rsp), %r15
movzwl %r13w, %r14d
movq %rbx, %rdi
callq 0x3190
testb $0x4, 0x2(%rbp)
movq %rax, 0x20(%rsp)
je 0x10d68
movq %rax, %r13
leaq 0x30e6a(%rip), %rdi     # 0x41b9f
movl %r14d, %esi
xorl %eax, %eax
callq 0x3120
movq %r13, %rdx
movl %eax, %r13d
leaq 0x30e60(%rip), %rdi     # 0x41bac
movq %rdx, %rsi
xorl %eax, %eax
callq 0x3120
movl 0xc(%rsp), %edi
addl %eax, %edi
addl %r13d, %edi
callq 0x16b56
movl %eax, 0xc(%rsp)
movl %r12d, 0x14(%rsp)
leaq 0x30c23(%rip), %rsi     # 0x41997
leaq 0x33584(%rip), %rdx     # 0x442ff
movq %r15, %rdi
callq 0x17a47
movq %rax, 0x40(%rsp)
movl 0xa0(%rsp), %eax
leal 0x2(%rax), %r13d
testl %r14d, %r14d
movl %r14d, 0x3c(%rsp)
je 0x10ebd
movq $0x0, 0x28(%rsp)
movl %r14d, %ebp
movq 0x20(%rsp), %r14
xorl %r12d, %r12d
movl $0x4003333, %edi        # imm = 0x4003333
movq %r14, %rsi
movq %r13, %r15
movl %r13d, %edx
leaq 0x30312(%rip), %rcx     # 0x410dc
callq 0x5605
movq %rbx, %rdi
movl 0x14(%rsp), %esi
movq %r14, %rdx
callq 0x4b9b
movq %rax, %r13
movzwl 0x2(%rax), %eax
addl $-0xd, %eax
cmpw $-0xc, %ax
jb 0x10ea7
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x10ea7
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x10ea7
movq %rbx, %rdi
callq 0x3190
movq %rax, %r14
movq %rbx, %rdi
movl 0x14(%rsp), %esi
movq %r13, %rdx
movq 0x30(%rsp), %rcx
movq 0x18(%rsp), %r8
movq 0x40(%rsp), %r9
pushq $0x2
pushq $-0x1
movl 0xa8(%rsp), %eax
pushq %rax
pushq $0x4
callq 0x5763
addq $0x20, %rsp
testq %rax, %rax
cmoveq %r14, %rax
cmpq %r12, %rax
cmovaq %rax, %r12
leaq 0x4731e(%rip), %rax     # 0x58180
testb $0x1, 0x3(%rax)
je 0x10e8a
movzwl 0x2(%r13), %edi
callq 0x15f20
cltq
imulq 0x8(%r13), %rax
cmpq $0x5, %rax
movq 0x28(%rsp), %rax
sbbl $-0x1, %eax
movq %rax, 0x28(%rsp)
movq %r15, %r13
decl %ebp
jne 0x10db5
cmpl $0x0, 0x28(%rsp)
sete %r15b
leaq 0x472db(%rip), %rbp     # 0x58180
jmp 0x10ec8
leaq 0x472d2(%rip), %rbp     # 0x58180
jmp 0x1127b
callq 0x33f5
jmp 0x10cf2
movb $0x1, %r15b
xorl %r12d, %r12d
movq 0x20(%rsp), %r14
movq %rbx, %rdi
movl 0x14(%rsp), %esi
movq %r14, %rdx
callq 0x46cc
movq (%rbp), %rdx
testb $0x30, %dl
sete %cl
notl %edx
testl $0x1040000, %edx        # imm = 0x1040000
setne %dl
orb %cl, %dl
testq %rax, %rax
je 0x10f06
testb %dl, %dl
je 0x10f1c
addq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x10ffc
testb %dl, %dl
je 0x10f90
movq $0x0, 0x18(%rsp)
jmp 0x10ffc
movb %r15b, 0x28(%rsp)
leaq 0x301b4(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq %r14, %rsi
movq %r13, 0x48(%rsp)
movl %r13d, %edx
movq %rax, 0x18(%rsp)
callq 0x5605
leaq 0x30caa(%rip), %rdi     # 0x41bf3
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl 0xc(%rsp), %r15d
movq 0x30(%rsp), %r13
addq %r13, 0x18(%rsp)
movq %rbx, %rdi
callq 0x3190
movq 0x18(%rsp), %rcx
cmpq %rax, %rcx
jae 0x10fcf
leaq 0x366e0(%rip), %rdi     # 0x47660
callq 0x5c33
movq $0x0, 0x18(%rsp)
jmp 0x10fe6
leaq 0x30145(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq %r14, %rsi
movl %r13d, %edx
callq 0x5605
leaq 0x30c60(%rip), %rdi     # 0x41c0e
movq $0x0, 0x18(%rsp)
xorl %eax, %eax
callq 0x3120
movl 0xc(%rsp), %edi
addl %eax, %edi
callq 0x16b56
movl %eax, 0xc(%rsp)
jmp 0x10ffc
leaq 0x342ae(%rip), %rdi     # 0x45284
movq %r13, %rsi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %r15d
movl %r15d, %edi
callq 0x16b56
movl %eax, 0xc(%rsp)
movq 0x48(%rsp), %r13
movb 0x28(%rsp), %r15b
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x11018
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
je 0x112bd
leaq 0x30c06(%rip), %rdi     # 0x41c25
xorl %eax, %eax
callq 0x3120
movl 0xc(%rsp), %edi
addl %eax, %edi
callq 0x16b56
movl %eax, 0xc(%rsp)
movq 0x46f8c(%rip), %rax     # 0x57fc8
movq (%rax), %rdi
callq 0x179a5
movq %rbx, %rdi
callq 0x31b0
testb %r15b, %r15b
je 0x1105d
cmpq %r12, %r14
cmovaq %r14, %r12
jmp 0x111a5
movq (%rbp), %rax
testb $0x30, %al
sete %cl
notl %eax
testl $0x1040000, %eax        # imm = 0x1040000
setne %al
orb %cl, %al
jne 0x110a8
leaq 0x30061(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq %r14, %rsi
movl %r13d, %edx
callq 0x5605
leaq 0x33c75(%rip), %rdi     # 0x44d07
xorl %eax, %eax
callq 0x3120
movl 0xc(%rsp), %edi
addl %eax, %edi
callq 0x16b56
movl %eax, 0xc(%rsp)
cmpl $0x0, 0x3c(%rsp)
je 0x111a5
movq %r13, %r15
movq %r13, 0x48(%rsp)
movq %rbx, %rdi
movl 0x14(%rsp), %esi
movq 0x20(%rsp), %rdx
callq 0x4b9b
movq %rax, %r13
movzwl 0x2(%rax), %eax
addl $-0xd, %eax
cmpw $-0xc, %ax
jb 0x11276
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x11276
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x11276
movq %rbx, %rdi
callq 0x3190
movq %rax, 0x20(%rsp)
movq (%rbp), %rax
testb $0x30, %al
sete %cl
btl $0x18, %eax
setae %al
orb %cl, %al
jne 0x11194
movzwl 0x2(%r13), %edi
callq 0x15f20
cltq
imulq 0x8(%r13), %rax
cmpq $0x5, %rax
jb 0x11194
movq 0x10(%r13), %rsi
movq 0x30(%rsp), %r14
addq %r14, %rsi
movl $0x4003333, %edi        # imm = 0x4003333
movq %r15, %rdx
leaq 0x2ff89(%rip), %rcx     # 0x410dc
callq 0x5605
movq %r13, %rdi
movl $0x2, %esi
movl $0x4, %edx
callq 0x67d3
movq %rbx, %rdi
movl 0x14(%rsp), %esi
movq %r13, %rdx
movq %r14, %rcx
movq 0x40(%rsp), %r8
movl $0x4, %r9d
pushq $0x1
pushq 0x50(%rsp)
callq 0x5c4d
addq $0x10, %rsp
movq %rax, %r14
cmpq %r12, %r14
cmovaq %r14, %r12
decl 0x3c(%rsp)
jne 0x110bb
leaq -0x1(%r12), %rsi
leaq 0x38671(%rip), %rax     # 0x49822
leaq 0x2ff41(%rip), %rcx     # 0x410f9
xorl %r14d, %r14d
cmpb $0x0, 0x13(%rsp)
cmovneq %rax, %rcx
cmoveq %r12, %r14
movl $0x40000, %edi          # imm = 0x40000
movl 0xa0(%rsp), %edx
callq 0x5605
testb $0x4, 0x2(%rbp)
movq 0x40(%rsp), %r15
je 0x111fd
leaq 0x33b47(%rip), %rdi     # 0x44d32
xorl %eax, %eax
callq 0x3120
movl 0xc(%rsp), %edi
addl %eax, %edi
callq 0x16b56
movq 0x18(%rsp), %r13
testq %r13, %r13
movq 0x30(%rsp), %r12
je 0x11260
leaq 0x33b2a(%rip), %rdi     # 0x44d3d
callq 0x5c33
movl $0x1, %edi
callq 0x16b56
subq $0x8, %rsp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl 0x1c(%rsp), %esi
movq %r13, %rdx
movq %r12, %rcx
movq 0x58(%rsp), %r8
xorl %r9d, %r9d
movl 0xa8(%rsp), %r10d
pushq %r10
pushq %rax
pushq %rax
pushq $0x4
pushq %r15
callq 0xc93c
addq $0x30, %rsp
cmpq %r14, %rax
cmovaq %rax, %r14
testq %r15, %r15
je 0x10cf5
movq %r15, %rdi
callq 0x3050
jmp 0x10cf5
movq 0x20(%rsp), %r14
leaq 0x2fe5a(%rip), %rcx     # 0x410dc
movl $0x4003333, %edi        # imm = 0x4003333
movq %r14, %rsi
movl %r15d, %edx
callq 0x5605
movq 0x10(%r13), %rsi
leaq 0x33a5b(%rip), %rdi     # 0x44cf8
xorl %eax, %eax
callq 0x3120
movl 0xc(%rsp), %edi
addl %eax, %edi
callq 0x16b56
movl %eax, 0xc(%rsp)
movq 0x40(%rsp), %r14
jmp 0x10c9e
movq %rbx, %rdi
callq 0x3190
movq %rax, %r14
jmp 0x1104c