// File: /workspace/github_c_makefile_star2_O2/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
andl $0x0, 0xcf0c(%rip)      # 0x14530
movq %rdi, %r15
leaq 0xbe32(%rip), %r12      # 0x13460
cmpl $0x0, (%r12)
je 0x7645
leaq 0x5851(%rip), %rdi      # 0xce8d
movl %ebx, %esi
xorl %eax, %eax
callq 0x3170
leaq 0x2(%r15), %rdi
leaq 0xac74(%rip), %rsi      # 0x122c4
pushq $0x6
popq %rdx
callq 0x33a0
testl %eax, %eax
je 0x7677
leaq 0x5845(%rip), %rdi      # 0xcea8
xorl %esi, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x6fc0
leaq 0x8(%r15), %r14
cmpw $0x4949, 0x8(%r15)      # imm = 0x4949
je 0x7695
cmpw $0x4d4d, (%r14)         # imm = 0x4D4D
je 0x76b6
leaq 0x5831(%rip), %rdi      # 0xcec4
jmp 0x7663
cmpl $0x0, (%r12)
je 0x76a8
leaq 0x6551(%rip), %rdi      # 0xdbf4
callq 0x30c0
andl $0x0, 0xce7d(%rip)      # 0x1452c
movzwl 0xa(%r15), %eax
jmp 0x76df
cmpl $0x0, (%r12)
je 0x76c9
leaq 0x6511(%rip), %rdi      # 0xdbd5
callq 0x30c0
movl $0x1, 0xce59(%rip)      # 0x1452c
movzwl 0xa(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %eax
cmpl $0x2a, %eax
jne 0x771c
addq $0xc, %r15
movq %r15, %rdi
callq 0x7318
movl %eax, %r15d
leal -0x11(%r15), %eax
cmpl $-0xa, %eax
ja 0x7738
cmpl $0x10, %r15d
setae %al
leal -0x10(%rbx), %ecx
cmpl %ecx, %r15d
setbe %cl
testb %cl, %al
jne 0x7728
leaq 0x57e3(%rip), %rdi      # 0xcefa
jmp 0x7663
leaq 0x57c0(%rip), %rdi      # 0xcee3
jmp 0x7663
leaq 0x57f3(%rip), %rdi      # 0xcf22
xorl %esi, %esi
xorl %edx, %edx
callq 0x6fc0
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 0x7755