// File: /workspace/github_c_makefile_star2_O3/Matthias-Wandel[P]imgcomp/src/exif.c
// Function: process_EXIF
void process_EXIF (unsigned char * ExifSection, unsigned int length)
{
    unsigned int FirstOffset;

    FocalplaneXRes = 0;
    FocalplaneUnits = 0;
    ExifImageWidth = 0;

    if (ShowTags){
        printf("Exif header %u bytes long\n",length);
    }

    {   // Check the EXIF header component
        static uchar ExifHeader[] = "Exif\0\0";
        if (memcmp(ExifSection+2, ExifHeader,6)){
            ErrNonfatal("Incorrect Exif header",0,0);
            return;
        }
    }

    if (memcmp(ExifSection+8,"II",2) == 0){
        if (ShowTags) printf("Exif section in Intel order\n");
        MotorolaOrder = 0;
    }else{
        if (memcmp(ExifSection+8,"MM",2) == 0){
            if (ShowTags) printf("Exif section in Motorola order\n");
            MotorolaOrder = 1;
        }else{
            ErrNonfatal("Invalid Exif alignment marker.",0,0);
            return;
        }
    }

    // Check the next value for correctness.
    if (Get16u(ExifSection+10) != 0x2a){
        ErrNonfatal("Invalid Exif start (1)",0,0);
        return;
    }

    FirstOffset = Get32u(ExifSection+12);
    if (FirstOffset < 8 || FirstOffset > 16){
        if (FirstOffset < 16 || FirstOffset > length-16){
            ErrNonfatal("invalid offset for first Exif IFD value",0,0);
            return;
        }
        // Usually set to 8, but other values valid too.
        ErrNonfatal("Suspicious offset of first Exif IFD value",0,0);
    }

    DirWithThumbnailPtrs = NULL;

    // First directory starts 16 bytes in.  All offset are relative to 8 bytes in.
    ProcessExifDir(ExifSection+8+FirstOffset, ExifSection+8, length-8, 0);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r15
movl $0x0, 0xc660(%rip)      # 0x14520
leaq 0xb589(%rip), %r12      # 0x13450
cmpl $0x0, (%r12)
je 0x7ede
leaq 0x4fe8(%rip), %rdi      # 0xcebd
movl %ebx, %esi
xorl %eax, %eax
callq 0x3170
movl 0x2(%r15), %eax
xorl 0xa3d4(%rip), %eax      # 0x122bc
movzwl 0x6(%r15), %ecx
xorw 0xa3cc(%rip), %cx       # 0x122c0
movzwl %cx, %ecx
orl %eax, %ecx
je 0x7f16
leaq 0x4fd6(%rip), %rdi      # 0xced8
xorl %esi, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x781c
leaq 0x8(%r15), %r14
cmpw $0x4949, 0x8(%r15)      # imm = 0x4949
je 0x7f34
cmpw $0x4d4d, (%r14)         # imm = 0x4D4D
je 0x7f58
leaq 0x4fc2(%rip), %rdi      # 0xcef4
jmp 0x7f02
cmpl $0x0, (%r12)
je 0x7f47
leaq 0x5ce2(%rip), %rdi      # 0xdc24
callq 0x30c0
movl $0x0, 0xc5cb(%rip)      # 0x1451c
movzwl 0xa(%r15), %eax
jmp 0x7f81
cmpl $0x0, (%r12)
je 0x7f6b
leaq 0x5c9f(%rip), %rdi      # 0xdc05
callq 0x30c0
movl $0x1, 0xc5a7(%rip)      # 0x1451c
movzwl 0xa(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %eax
cmpl $0x2a, %eax
jne 0x7fbe
addq $0xc, %r15
movq %r15, %rdi
callq 0x7b8c
movl %eax, %r15d
leal -0x11(%r15), %eax
cmpl $-0xa, %eax
ja 0x7fda
cmpl $0x10, %r15d
setae %al
leal -0x10(%rbx), %ecx
cmpl %ecx, %r15d
setbe %cl
testb %cl, %al
jne 0x7fca
leaq 0x4f71(%rip), %rdi      # 0xcf2a
jmp 0x7f02
leaq 0x4f4e(%rip), %rdi      # 0xcf13
jmp 0x7f02
leaq 0x4f81(%rip), %rdi      # 0xcf52
xorl %esi, %esi
xorl %edx, %edx
callq 0x781c
movl %r15d, %edi
addq %r14, %rdi
addl $-0x8, %ebx
movq %r14, %rsi
movl %ebx, %edx
xorl %ecx, %ecx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x7ff7