// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r15
movl $0x0, 0xc72f(%rip)      # 0x14520
leaq 0xb658(%rip), %r12      # 0x13450
cmpl $0x0, (%r12)
je 0x7e0f
leaq 0x5047(%rip), %rdi      # 0xce4d
movl %ebx, %esi
xorl %eax, %eax
callq 0x3170
movl 0x2(%r15), %eax
xorl 0xa49b(%rip), %eax      # 0x122b4
movzwl 0x6(%r15), %ecx
xorw 0xa493(%rip), %cx       # 0x122b8
movzwl %cx, %ecx
orl %eax, %ecx
je 0x7e4a
leaq 0x5035(%rip), %rdi      # 0xce68
xorl %esi, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x76e0
leaq 0x8(%r15), %rcx
movzwl 0x8(%r15), %eax
xorl %ebp, %ebp
cmpl $0x4949, %eax           # imm = 0x4949
setne %r13b
cmpw $0x4949, %ax            # imm = 0x4949
je 0x7e74
cmpw $0x4d4d, (%rcx)         # imm = 0x4D4D
je 0x7e8a
leaq 0x5012(%rip), %rdi      # 0xce84
jmp 0x7e33
xorl %r14d, %r14d
cmpl $0x0, (%r12)
je 0x7ea8
movq %rcx, %r12
leaq 0x5d2c(%rip), %rdi      # 0xdbb4
jmp 0x7ea1
movl $0x1, %r14d
cmpl $0x0, (%r12)
je 0x7ea8
movq %rcx, %r12
leaq 0x5cf4(%rip), %rdi      # 0xdb95
callq 0x30c0
jmp 0x7eab
movq %rcx, %r12
movb %r13b, %bpl
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movl %r14d, 0xc660(%rip)     # 0x1451c
movzbl 0xa(%r15,%rax), %ecx
xorq $0xb, %rax
shll $0x8, %ecx
movzbl (%r15,%rax), %eax
orl %ecx, %eax
cmpl $0x2a, %eax
jne 0x7f0d
addq $0xc, %r15
movq %r15, %rdi
callq 0x7a83
movl %eax, %r15d
leal -0x11(%r15), %eax
cmpl $-0xa, %eax
ja 0x7f29
cmpl $0x10, %r15d
setae %al
leal -0x10(%rbx), %ecx
cmpl %ecx, %r15d
setbe %cl
testb %cl, %al
jne 0x7f19
leaq 0x4fb2(%rip), %rdi      # 0xceba
jmp 0x7e33
leaq 0x4f8f(%rip), %rdi      # 0xcea3
jmp 0x7e33
leaq 0x4fc2(%rip), %rdi      # 0xcee2
xorl %esi, %esi
xorl %edx, %edx
callq 0x76e0
movl %r15d, %edi
movq %r12, %rsi
addq %r12, %rdi
addl $-0x8, %ebx
movl %ebx, %edx
xorl %ecx, %ecx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7f49