// File: /workspace/github_c_makefile_star2_O1/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, 0x552db(%rip)     # 0x59470
pxor %xmm0, %xmm0
movdqu %xmm0, 0x552d7(%rip)    # 0x59478
movdqu %xmm0, 0x552df(%rip)    # 0x59488
movdqu %xmm0, 0x552e7(%rip)    # 0x59498
movdqu %xmm0, 0x552ef(%rip)    # 0x594a8
testq %rdi, %rdi
je 0x43e2
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
callq 0x31a0
testl %eax, %eax
jne 0x43da
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x43da
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r14, %rdx
callq 0x4574
movl %eax, %r15d
movzwl %ax, %ebp
cmpl $0x4949, %ebp           # imm = 0x4949
je 0x421b
cmpl $0xffd8, %ebp           # imm = 0xFFD8
je 0x425b
cmpl $0x4d4d, %ebp           # imm = 0x4D4D
jne 0x4295
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl %ebp, %esi
callq 0x4574
movzwl %ax, %r12d
cmpl $0x4f51, %r12d          # imm = 0x4F51
jg 0x426b
cmpl $0x2a, %r12d
je 0x43ba
cmpl $0x55, %r12d
jne 0x4386
movq $0x55, 0x55222(%rip) # 0x59478
jmp 0x43d2
movq $0xffd8, 0x55212(%rip) # imm = 0xFFD8
jmp 0x43d2
cmpl $0x4f52, %r12d          # imm = 0x4F52
je 0x43c7
cmpl $0x5352, %r12d          # imm = 0x5352
jne 0x4386
movq $0x5352, 0x551e8(%rip) # imm = 0x5352
jmp 0x43d2
movq $0x0, 0x551d8(%rip) # 0x59478
movw $0x0, 0x551c7(%rip)     # 0x59470
cmpl $0x464e, %ebp           # imm = 0x464E
jle 0x4310
cmpl $0x464f, %ebp           # imm = 0x464F
je 0x43ea
cmpl $0x4655, %ebp           # imm = 0x4655
je 0x42d1
cmpl $0x5546, %ebp           # imm = 0x5546
jne 0x4504
movl $0x10, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49e6
movdqa 0x571e7(%rip), %xmm0    # 0x5b4d0
pcmpeqb 0x3ce4f(%rip), %xmm0    # 0x41140
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x43da
movq $0x4655, 0x5516d(%rip) # imm = 0x4655
jmp 0x43da
testl %ebp, %ebp
je 0x4426
cmpl $0x4d, %ebp
jne 0x4504
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r14, %rdx
callq 0x46cc
cmpq $0x4d524d, %rax         # imm = 0x4D524D
jne 0x43da
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x46cc
movq %rax, %r14
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x43da
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x43da
movl $0x4d524d, %eax         # imm = 0x4D524D
movq %rax, 0x55102(%rip)     # 0x59478
movq %rax, 0x55123(%rip)     # 0x594a0
movq %r14, 0x55124(%rip)     # 0x594a8
jmp 0x43da
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x200cd
testq %rax, %rax
je 0x4529
movzwl (%rax), %ecx
movw %cx, 0x550ca(%rip)      # 0x59470
movq $0x1a, 0x550c7(%rip) # 0x59478
movq %rax, 0x550c8(%rip)     # 0x59480
jmp 0x43da
movq $0x2a, 0x550b3(%rip) # 0x59478
jmp 0x43d2
movq $0x4f52, 0x550a6(%rip) # imm = 0x4F52
movw %r15w, 0x55096(%rip)    # 0x59470
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
leaq 0x55087(%rip), %rax     # 0x59470
retq
movq %rbx, %rdi
movl $0x4949, %esi           # imm = 0x4949
movq %r14, %rdx
callq 0x46cc
cmpq $0x62564f46, %rax       # imm = 0x62564F46
jne 0x43da
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28490
testq %rax, %rax
je 0x43da
movq %rax, 0x55097(%rip)     # 0x594b0
movq $0x62564f46, 0x55054(%rip) # imm = 0x62564F46
jmp 0x43da
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r14, %rdx
callq 0x46cc
cmpq $0xc, %rax
jne 0x43da
movl $0x4, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x4832
testq %rax, %rax
je 0x43da
movq %rax, %r14
leaq 0x3cd2d(%rip), %rsi     # 0x4118a
movl $0x4, %edx
movq %rax, %rdi
callq 0x3090
testl %eax, %eax
je 0x448a
leaq 0x3cd1c(%rip), %rsi     # 0x41191
movl $0x4, %edx
movq %r14, %rdi
callq 0x3090
testl %eax, %eax
jne 0x43da
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x46cc
cmpq $0xd0a870a, %rax        # imm = 0xD0A870A
jne 0x43da
movq $0xd0a870a, 0x54fc5(%rip) # imm = 0xD0A870A
movw $0x0, 0x54fb4(%rip)     # 0x59470
movl (%r14), %r14d
movq %rbx, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x43da
movq %rbx, %rdi
callq 0x31a0
testl %eax, %eax
jne 0x43da
bswapl %r14d
movq $0xc, 0x54f9b(%rip) # 0x59488
movq %r14, 0x54f9c(%rip)     # 0x59490
movq $0xd0a870a, 0x54f99(%rip) # imm = 0xD0A870A
jmp 0x43da
movw $0x0, 0x54f63(%rip)     # 0x59470
movq $0x0, 0x54f98(%rip) # 0x594b0
pxor %xmm0, %xmm0
movdqu %xmm0, 0x54f54(%rip)    # 0x59478
jmp 0x43da
movq $0x0, 0x54f44(%rip) # 0x59478
movw $0x0, 0x54f33(%rip)     # 0x59470
leaq 0x3cc0c(%rip), %rdi     # 0x41150
movl %r12d, %esi
xorl %eax, %eax
callq 0x3120
leaq 0x3cc17(%rip), %rdi     # 0x4116c
xorl %eax, %eax
callq 0x3120
movl %ebp, %edi
movl $0x1, %esi
callq 0x53d5
xorl %edi, %edi
callq 0x16b56
jmp 0x43da