// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %r9, 0x10(%rsp)
testq %rdi, %rdi
je 0x101c4
movq %r8, %rbp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
movl 0x90(%rsp), %edx
testq %r8, %r8
setne %al
cmpq %r8, %r14
seta %sil
andb %al, %sil
movq %rcx, 0x18(%rsp)
addq %rcx, %r14
leaq 0x32dc0(%rip), %rax     # 0x42ce0
leaq 0x2f1b5(%rip), %rcx     # 0x3f0dc
movb %sil, 0xf(%rsp)
testb %sil, %sil
cmovneq %rax, %rcx
movl $0x40000, %edi          # imm = 0x40000
movq %r14, %rsi
callq 0x5100
leaq 0x47239(%rip), %rcx     # 0x57180
xorl %eax, %eax
movq %rcx, %r12
testb $0x4, 0x2(%rcx)
je 0xff67
leaq 0x32d89(%rip), %rdi     # 0x42ce2
movl 0x88(%rsp), %esi
xorl %eax, %eax
callq 0x3120
movl %eax, 0x4(%rsp)
movzwl %r15w, %r13d
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0x416a
movl %eax, %r15d
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0xff9d
movl %r13d, 0x8(%rsp)
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
je 0x10011
xorl %r14d, %r14d
movl 0x90(%rsp), %eax
movl %eax, %r13d
movq %r12, %rbp
movq %rbx, %rdi
callq 0x31b0
movq %rbx, %rdi
callq 0x3190
leaq -0x1(%rax), %rsi
leaq 0x2f131(%rip), %rcx     # 0x3f0f9
movl $0x40000, %edi          # imm = 0x40000
movl %r13d, %edx
callq 0x5100
testb $0x4, 0x2(%rbp)
je 0xfff4
leaq 0x32d50(%rip), %rdi     # 0x42d32
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
callq 0x160f7
movq %r14, %rdi
callq 0x3050
xorl %r14d, %r14d
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl %r15w, %r13d
movq %rbx, %rdi
callq 0x3190
movq %rax, %r14
testb $0x4, 0x2(%r12)
movq %rbp, 0x40(%rsp)
je 0x10067
leaq 0x2fb6b(%rip), %rdi     # 0x3fb9f
movl %r13d, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
leaq 0x2fb64(%rip), %rdi     # 0x3fbac
movq %r14, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
addl %r15d, %edi
callq 0x160f7
movl %eax, 0x4(%rsp)
movl 0x8(%rsp), %r15d
leaq 0x2f924(%rip), %rsi     # 0x3f997
leaq 0x32285(%rip), %rdx     # 0x422ff
movq 0x80(%rsp), %rdi
callq 0x16f1d
movq %rax, 0x30(%rsp)
movl 0x90(%rsp), %eax
leal 0x2(%rax), %ebp
xorl %r12d, %r12d
movl %r13d, 0x3c(%rsp)
movq %r14, 0x20(%rsp)
movl $0x0, 0x2c(%rsp)
subl $0x1, %r13d
jb 0x101ee
movl $0x4003333, %edi        # imm = 0x4003333
movq %r14, %rsi
movl %ebp, %edx
leaq 0x2f016(%rip), %rcx     # 0x3f0dc
callq 0x5100
movq %rbx, %rdi
movl %r15d, %esi
movq %r14, %rdx
callq 0x476a
movq %rax, %r15
movzwl 0x2(%rax), %eax
addl $-0xd, %eax
cmpw $-0xc, %ax
jb 0x10175
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x10175
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x10175
movq %rbx, %rdi
callq 0x3190
movq %rax, %r14
movq %rbx, %rdi
movl 0x8(%rsp), %esi
movq %r15, %rdx
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %r9
pushq $0x2
pushq $-0x1
movl 0x98(%rsp), %eax
pushq %rax
pushq $0x4
callq 0x524a
addq $0x20, %rsp
movq %r14, %rcx
testq %rax, %rax
je 0x1014b
movq %rax, %rcx
cmpq %r12, %rcx
cmovaq %rcx, %r12
leaq 0x47027(%rip), %rax     # 0x57180
testb $0x1, 0x3(%rax)
je 0x1016b
movq %r15, %rdi
callq 0xf1c7
addl %eax, 0x2c(%rsp)
movl 0x8(%rsp), %r15d
jmp 0x100ab
leaq 0x47004(%rip), %rax     # 0x57180
movq %rbp, %r13
movq %rax, %rbp
leaq 0x2ef53(%rip), %rcx     # 0x3f0dc
movl $0x4003333, %edi        # imm = 0x4003333
movq %r14, %rsi
movl %r13d, %edx
callq 0x5100
movq 0x10(%r15), %rsi
leaq 0x32b54(%rip), %rdi     # 0x42cf8
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
callq 0x160f7
movl %eax, 0x4(%rsp)
movq 0x30(%rsp), %r14
jmp 0xffad
movq 0x46e2d(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0x48293(%rip), %rax     # 0x58468
movq (%rax), %rdx
leaq 0x32ad7(%rip), %rsi     # 0x42cb6
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3180
jmp 0xffff
movq %rbx, %rdi
movl %r15d, %esi
movq %r14, %rdx
callq 0x42ba
leaq 0x46f7d(%rip), %r13     # 0x57180
movq (%r13), %rdx
testb $0x30, %dl
sete %cl
notl %edx
testl $0x1040000, %edx        # imm = 0x1040000
setne %dl
orb %cl, %dl
testq %rax, %rax
je 0x10235
testb %dl, %dl
movq %rbp, %r13
je 0x1024a
addq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x102f8
testb %dl, %dl
movq %rbp, %r13
je 0x102bb
movq $0x0, 0x10(%rsp)
jmp 0x102f8
leaq 0x2ee8b(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq %r14, %rsi
movl %r13d, %edx
movq %rax, 0x10(%rsp)
callq 0x5100
leaq 0x2f986(%rip), %rdi     # 0x3fbf3
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl 0x4(%rsp), %r15d
movq 0x18(%rsp), %rax
addq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0x3190
movq 0x10(%rsp), %rcx
cmpq %rax, %rcx
leaq 0x46ede(%rip), %rbp     # 0x57180
jae 0x10301
leaq 0x353a5(%rip), %rdi     # 0x45650
callq 0x56e2
movq $0x0, 0x10(%rsp)
jmp 0x1031a
leaq 0x2ee1a(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq %r14, %rsi
movl %r13d, %edx
callq 0x5100
leaq 0x2f935(%rip), %rdi     # 0x3fc0e
movq $0x0, 0x10(%rsp)
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
callq 0x160f7
movl %eax, 0x4(%rsp)
leaq 0x46e81(%rip), %rbp     # 0x57180
jmp 0x1032b
leaq 0x32f7c(%rip), %rdi     # 0x43284
movq 0x18(%rsp), %rsi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %r15d
movl %r15d, %edi
callq 0x160f7
movl %eax, 0x4(%rsp)
movl 0x8(%rsp), %r15d
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x10347
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
je 0x1059f
leaq 0x2f8d7(%rip), %rdi     # 0x3fc25
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
callq 0x160f7
movl %eax, 0x4(%rsp)
movq 0x46c5d(%rip), %rax     # 0x56fc8
movq (%rax), %rdi
callq 0x16e8c
movq %rbx, %rdi
callq 0x31b0
cmpl $0x0, 0x2c(%rsp)
je 0x103a6
movq (%rbp), %rax
testb $0x30, %al
sete %cl
notl %eax
testl $0x1040000, %eax        # imm = 0x1040000
setne %al
orb %cl, %al
je 0x10482
movl 0x4(%rsp), %eax
jmp 0x104b2
cmpq %r12, %r14
cmovaq %r14, %r12
leaq -0x1(%r12), %rsi
leaq 0x37459(%rip), %rax     # 0x47812
leaq 0x2ed39(%rip), %rcx     # 0x3f0f9
xorl %r14d, %r14d
cmpb $0x0, 0xf(%rsp)
cmovneq %rax, %rcx
cmoveq %r12, %r14
movl $0x40000, %edi          # imm = 0x40000
movl 0x90(%rsp), %edx
callq 0x5100
testb $0x4, 0x2(%rbp)
je 0x10400
leaq 0x32944(%rip), %rdi     # 0x42d32
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
callq 0x160f7
movq 0x10(%rsp), %rbp
testq %rbp, %rbp
movq 0x30(%rsp), %r15
movq 0x40(%rsp), %r12
movq 0x18(%rsp), %r13
je 0x10475
leaq 0x3291d(%rip), %rdi     # 0x42d3d
callq 0x56e2
pushq $0x1
popq %rdi
callq 0x160f7
subq $0x30, %rsp
orl $-0x1, 0x18(%rsp)
movl 0xc0(%rsp), %eax
movl %eax, 0x20(%rsp)
orl $-0x1, 0x10(%rsp)
movq %r15, (%rsp)
movl $0x4, 0x8(%rsp)
movq %rbx, %rdi
movl 0x38(%rsp), %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xc004
addq $0x30, %rsp
cmpq %r14, %rax
cmovaq %rax, %r14
movq %r15, %rdi
callq 0x3050
jmp 0xffff
leaq 0x2ec53(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq %r14, %rsi
movl %r13d, %edx
callq 0x5100
leaq 0x32867(%rip), %rdi     # 0x42d07
xorl %eax, %eax
callq 0x3120
movl 0x4(%rsp), %edi
addl %eax, %edi
callq 0x160f7
movl %eax, 0x4(%rsp)
subl $0x1, 0x3c(%rsp)
jb 0x103ad
movq %rbx, %rdi
movl %r15d, %esi
movq 0x20(%rsp), %rdx
callq 0x476a
movq %rax, %r15
movzwl 0x2(%rax), %eax
addl $-0xd, %eax
cmpw $-0xc, %ax
jb 0x10595
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x10595
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x10595
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 0x10584
movq %r15, %rdi
callq 0xf1c7
testl %eax, %eax
je 0x10584
movq 0x10(%r15), %rsi
movq 0x18(%rsp), %r14
addq %r14, %rsi
movl $0x4003333, %edi        # imm = 0x4003333
movl %r13d, %edx
leaq 0x2eb8f(%rip), %rcx     # 0x3f0dc
callq 0x5100
movq %r15, %rdi
pushq $0x2
popq %rsi
pushq $0x4
popq %rdx
callq 0x62b2
movq %rbx, %rdi
movl 0x8(%rsp), %esi
movq %r15, %rdx
movq %r14, %rcx
movq 0x30(%rsp), %r8
pushq $0x4
popq %r9
pushq $0x1
pushq %r13
callq 0x56fc
popq %rcx
popq %rdx
movq %rax, %r14
cmpq %r12, %r14
cmovaq %r14, %r12
movl 0x8(%rsp), %r15d
jmp 0x104b6
movq 0x20(%rsp), %r14
jmp 0x10182
movq %rbx, %rdi
callq 0x3190
movq %rax, %r14
jmp 0x1037b