// File: /workspace/github_c_makefile_star2_O3/hfiguiere[P]exifprobe/readfile.c
// Function: read_imageheader
struct fileheader *
read_imageheader(FILE *inptr,unsigned long offset)
{
    static struct fileheader fileheader;
    struct ciff_header *ciffheader;
    struct jp2_header jp2header;
    struct mrw_header mrwheader;
    struct x3f_header *x3fheader;
    unsigned short marker,magic;
    unsigned char *type;
    unsigned long umagic,length;
    char *string;

    marker = 0;
    fileheader.probe_magic = PROBE_NOMAGIC;
    fileheader.file_marker = 0;
    fileheader.ciff_header = NULL;
    fileheader.x3f_header = NULL;
    memset(&fileheader.jp2_header,'\0',sizeof(struct jp2_header));
    memset(&fileheader.mrw_header,'\0',sizeof(struct mrw_header));
    if(inptr && !feof(inptr) && !ferror(inptr))
    {
        /* The order of bytes for this read does not matter for TIFF, */
        /* but must be high-byte first for JPEG.                      */
        marker = read_ushort(inptr,TIFF_MOTOROLA,offset);
        switch(marker)
        {
            case TIFF_MOTOROLA:
            case TIFF_INTEL:
                if((magic = read_ushort(inptr,marker,HERE)) == TIFF_MAGIC)
                {
                    fileheader.probe_magic = TIFF_MAGIC;
                    fileheader.file_marker = marker;
                }
                else if(magic == ORF1_MAGIC)
                {
                    fileheader.probe_magic = ORF1_MAGIC;
                    fileheader.file_marker = marker;
                }
                else if(magic == ORF2_MAGIC)
                {
                    fileheader.probe_magic = ORF2_MAGIC;
                    fileheader.file_marker = marker;
                }
                else if(magic == RW2_MAGIC)
                {
                    fileheader.probe_magic = RW2_MAGIC;
                    fileheader.file_marker = marker;
                }
                else if((ciffheader = read_ciffheader(inptr,marker,offset)))
                {
                    fileheader.file_marker = ciffheader->byteorder;
                    fileheader.probe_magic = PROBE_CIFFMAGIC;
                    fileheader.ciff_header = ciffheader;
                }
                else
                {
                    fileheader.probe_magic = PROBE_NOMAGIC;
                    fileheader.file_marker = 0;
                    printf(" invalid TIFF magic (%#06x)",magic);
                    printf(", apparent TIFF byteorder is ");
                    print_byteorder(marker,1);
                    (void)newline(0);
                }
                break;
            case JPEG_SOI:
                fileheader.probe_magic = JPEG_SOI;
                fileheader.file_marker = marker;
                break;
            default:
                fileheader.probe_magic = PROBE_NOMAGIC;
                fileheader.file_marker = 0;
                if(marker == 0)
                {
                    /* check for jpeg2000                             */
                    length = read_ulong(inptr,TIFF_MOTOROLA,offset);
                    if(length == 12)
                    {
                        type = read_bytes(inptr,4,HERE);
                        if(type && ((strncmp((char *)type,"jP\040\040  ",4) == 0) ||
                                    (strncmp((char *)type,"jP\032\032  ",4) == 0)))
                        {
                            umagic = read_ulong(inptr,TIFF_MOTOROLA,HERE);
                            if(umagic == 0x0d0a870a)
                            {
                                fileheader.probe_magic = PROBE_JP2MAGIC;
                                fileheader.file_marker = 0;
                                jp2header.length = length;
                                jp2header.type = to_ulong(type,TIFF_MOTOROLA);
                                if(!ferror(inptr) && !feof(inptr))
                                {
                                    jp2header.magic = umagic;
                                    fileheader.jp2_header = jp2header;
                                }
                            }
                        }
                    }
                }
                else if(marker == 0x004d)
                {
                    umagic = read_ulong(inptr,TIFF_MOTOROLA,offset);
                    if(umagic == 0x004d524d)
                    {
                        /* Minolta MRW */
                        mrwheader.mrw_magic = umagic;
                        mrwheader.mrw_dataoffset = read_ulong(inptr,TIFF_MOTOROLA,HERE);
                        if(!ferror(inptr) && !feof(inptr))
                        {
                            fileheader.probe_magic = PROBE_MRWMAGIC;
                            fileheader.mrw_header = mrwheader;
                        }
                    }
                }
                else if((marker == 0x5546) || (marker == 0x4655))
                {
                    /* Fujifile RAF */
                    string = read_string(inptr,offset,16);
                    if(string && (strncmp(string,"FUJIFILMCCD-RAW ",16) == 0))
                        fileheader.probe_magic = PROBE_RAFMAGIC;
                }
                else if(marker == 0x464f) /* "FO" */
                {
                    /* Sigma/Foveon X3F */
                    umagic = read_ulong(inptr,TIFF_INTEL,offset);
                    if(umagic == PROBE_X3FMAGIC)
                    {
                        x3fheader = read_x3fheader(inptr,offset);
                        if(x3fheader)
                        {   fileheader.x3f_header = x3fheader;
                            fileheader.probe_magic = PROBE_X3FMAGIC;
                        }
                    }
                }
                else
                {
                    /* Unknown format                                 */
                    fileheader.probe_magic = PROBE_NOMAGIC;
                    fileheader.file_marker = 0;
                    fileheader.ciff_header = NULL;
                    fileheader.x3f_header = NULL;
                }
                break;
        }
    }
    return(&fileheader);
}

// Assembly:
movw $0x0, 0x552bb(%rip)     # 0x59470
pxor %xmm0, %xmm0
movdqu %xmm0, 0x552b7(%rip)    # 0x59478
movdqu %xmm0, 0x552bf(%rip)    # 0x59488
movdqu %xmm0, 0x552c7(%rip)    # 0x59498
movdqu %xmm0, 0x552cf(%rip)    # 0x594a8
testq %rdi, %rdi
je 0x420a
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
callq 0x31a0
testl %eax, %eax
jne 0x4200
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
je 0x4212
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
leaq 0x5525f(%rip), %rax     # 0x59470
retq
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r14, %rdx
callq 0x45af
movzwl %ax, %ebp
cmpl $0x4949, %ebp           # imm = 0x4949
je 0x4241
cmpl $0xffd8, %ebp           # imm = 0xFFD8
je 0x4281
cmpl $0x4d4d, %ebp           # imm = 0x4D4D
jne 0x42c4
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl %ebp, %esi
callq 0x45af
movzwl %ax, %r15d
cmpl $0x4f51, %r15d          # imm = 0x4F51
jg 0x429a
cmpl $0x2a, %r15d
je 0x43f7
cmpl $0x55, %r15d
jne 0x43c0
movq $0x55, 0x551fc(%rip) # 0x59478
jmp 0x440f
movq $0xffd8, 0x551ec(%rip) # imm = 0xFFD8
movw $0xffd8, 0x551db(%rip)  # imm = 0xFFD8
jmp 0x4200
cmpl $0x4f52, %r15d          # imm = 0x4F52
je 0x4404
cmpl $0x5352, %r15d          # imm = 0x5352
jne 0x43c0
movq $0x5352, 0x551b9(%rip) # imm = 0x5352
jmp 0x440f
movq $0x0, 0x551a9(%rip) # 0x59478
movw $0x0, 0x55198(%rip)     # 0x59470
cmpl $0x464e, %ebp           # imm = 0x464E
jle 0x433f
cmpl $0x464f, %ebp           # imm = 0x464F
je 0x441b
cmpl $0x4655, %ebp           # imm = 0x4655
je 0x4300
cmpl $0x5546, %ebp           # imm = 0x5546
jne 0x4548
movl $0x10, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a17
movdqa 0x571b8(%rip), %xmm0    # 0x5b4d0
pcmpeqb 0x3ce20(%rip), %xmm0    # 0x41140
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x4200
movq $0x4655, 0x5513e(%rip) # imm = 0x4655
jmp 0x4200
testl %ebp, %ebp
je 0x4462
cmpl $0x4d, %ebp
jne 0x4548
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r14, %rdx
callq 0x4707
cmpq $0x4d524d, %rax         # imm = 0x4D524D
jne 0x4200
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x4707
movq %rax, %r14
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x4200
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x4200
movl $0x4d524d, %eax         # imm = 0x4D524D
movq %rax, 0x550cb(%rip)     # 0x59478
movq %rax, 0x550ec(%rip)     # 0x594a0
movq %r14, 0x550ed(%rip)     # 0x594a8
jmp 0x4200
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x20690
testq %rax, %rax
je 0x4564
movzwl (%rax), %ecx
movw %cx, 0x55090(%rip)      # 0x59470
movq $0x1a, 0x5508d(%rip) # 0x59478
movq %rax, 0x5508e(%rip)     # 0x59480
jmp 0x4200
movq $0x2a, 0x55076(%rip) # 0x59478
jmp 0x440f
movq $0x4f52, 0x55069(%rip) # imm = 0x4F52
movw %bp, 0x5505a(%rip)      # 0x59470
jmp 0x4200
movq %rbx, %rdi
movl $0x4949, %esi           # imm = 0x4949
movq %r14, %rdx
callq 0x4707
cmpq $0x62564f46, %rax       # imm = 0x62564F46
jne 0x4200
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28c04
testq %rax, %rax
je 0x4200
movq %rax, 0x5505e(%rip)     # 0x594b0
movq $0x62564f46, 0x5501b(%rip) # imm = 0x62564F46
jmp 0x4200
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r14, %rdx
callq 0x4707
cmpq $0xc, %rax
jne 0x4200
movl $0x4, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x4865
testq %rax, %rax
je 0x4200
movq %rax, %r14
leaq 0x3cce9(%rip), %rsi     # 0x4118a
movl $0x4, %edx
movq %rax, %rdi
callq 0x3090
testl %eax, %eax
je 0x44ce
leaq 0x3ccd8(%rip), %rsi     # 0x41191
movl $0x4, %edx
movq %r14, %rdi
callq 0x3090
testl %eax, %eax
jne 0x4200
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x4707
cmpq $0xd0a870a, %rax        # imm = 0xD0A870A
jne 0x4200
movq $0xd0a870a, 0x54f81(%rip) # imm = 0xD0A870A
movw $0x0, 0x54f70(%rip)     # 0x59470
movl (%r14), %r14d
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x4200
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x4200
bswapl %r14d
movq $0xc, 0x54f57(%rip) # 0x59488
movq %r14, 0x54f58(%rip)     # 0x59490
movq $0xd0a870a, 0x54f55(%rip) # imm = 0xD0A870A
jmp 0x4200
movq $0x0, 0x54f5d(%rip) # 0x594b0
pxor %xmm0, %xmm0
movdqu %xmm0, 0x54f19(%rip)    # 0x59478
jmp 0x4200
movq $0x0, 0x54f09(%rip) # 0x59478
movw $0x0, 0x54ef8(%rip)     # 0x59470
leaq 0x3cbd1(%rip), %rdi     # 0x41150
movl %r15d, %esi
xorl %eax, %eax
callq 0x3120
leaq 0x3cbdc(%rip), %rdi     # 0x4116c
xorl %eax, %eax
callq 0x3120
movl %ebp, %edi
movl $0x1, %esi
callq 0x538a
xorl %edi, %edi
callq 0x1707a
jmp 0x4200