// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw $0x0, -0x4a(%rbp)
movq $0x0, 0x744e4(%rip) # 0x78478
movw $0x0, 0x744d3(%rip)     # 0x78470
movq $0x0, 0x744d8(%rip) # 0x78480
movq $0x0, 0x744fd(%rip) # 0x784b0
leaq 0x744b6(%rip), %rdi     # 0x78470
addq $0x18, %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3130
leaq 0x7449f(%rip), %rdi     # 0x78470
addq $0x30, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3130
cmpq $0x0, -0x8(%rbp)
je 0x446c
movq -0x8(%rbp), %rdi
callq 0x3190
cmpl $0x0, %eax
jne 0x446c
movq -0x8(%rbp), %rdi
callq 0x30a0
cmpl $0x0, %eax
jne 0x446c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x4480
movw %ax, -0x4a(%rbp)
movzwl -0x4a(%rbp), %eax
movl %eax, -0x74(%rbp)
subl $0x4949, %eax           # imm = 0x4949
je 0x4055
jmp 0x4036
movl -0x74(%rbp), %eax
subl $0x4d4d, %eax           # imm = 0x4D4D
je 0x4055
jmp 0x4042
movl -0x74(%rbp), %eax
subl $0xffd8, %eax           # imm = 0xFFD8
je 0x4198
jmp 0x41b3
movq -0x8(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movzwl -0x4a(%rbp), %esi
callq 0x4480
movw %ax, -0x4c(%rbp)
movzwl %ax, %eax
cmpl $0x2a, %eax
jne 0x408e
movq $0x2a, 0x743fa(%rip) # 0x78478
movw -0x4a(%rbp), %ax
movw %ax, 0x743e7(%rip)      # 0x78470
jmp 0x4193
movzwl -0x4c(%rbp), %eax
cmpl $0x4f52, %eax           # imm = 0x4F52
jne 0x40b4
movq $0x4f52, 0x743d4(%rip) # imm = 0x4F52
movw -0x4a(%rbp), %ax
movw %ax, 0x743c1(%rip)      # 0x78470
jmp 0x4191
movzwl -0x4c(%rbp), %eax
cmpl $0x5352, %eax           # imm = 0x5352
jne 0x40da
movq $0x5352, 0x743ae(%rip) # imm = 0x5352
movw -0x4a(%rbp), %ax
movw %ax, 0x7439b(%rip)      # 0x78470
jmp 0x418f
movzwl -0x4c(%rbp), %eax
cmpl $0x55, %eax
jne 0x40fe
movq $0x55, 0x7438a(%rip) # 0x78478
movw -0x4a(%rbp), %ax
movw %ax, 0x74377(%rip)      # 0x78470
jmp 0x418d
movq -0x8(%rbp), %rdi
movw -0x4a(%rbp), %ax
movq -0x10(%rbp), %rdx
movzwl %ax, %esi
callq 0x2e490
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x4142
movq -0x18(%rbp), %rax
movw (%rax), %ax
movw %ax, 0x74346(%rip)      # 0x78470
movq $0x1a, 0x74343(%rip) # 0x78478
movq -0x18(%rbp), %rax
movq %rax, 0x74340(%rip)     # 0x78480
jmp 0x418b
movq $0x0, 0x7432b(%rip) # 0x78478
movw $0x0, 0x7431a(%rip)     # 0x78470
movzwl -0x4c(%rbp), %esi
leaq 0x5ffd0(%rip), %rdi     # 0x64131
movb $0x0, %al
callq 0x3110
leaq 0x5ffde(%rip), %rdi     # 0x6414d
movb $0x0, %al
callq 0x3110
movl $0x1, %esi
movzwl -0x4a(%rbp), %edi
callq 0x59e0
xorl %edi, %edi
callq 0x1ef50
jmp 0x418d
jmp 0x418f
jmp 0x4191
jmp 0x4193
jmp 0x446a
movq $0xffd8, 0x742d5(%rip) # imm = 0xFFD8
movw -0x4a(%rbp), %ax
movw %ax, 0x742c2(%rip)      # 0x78470
jmp 0x446a
movq $0x0, 0x742ba(%rip) # 0x78478
movw $0x0, 0x742a9(%rip)     # 0x78470
movzwl -0x4a(%rbp), %eax
cmpl $0x0, %eax
jne 0x42ee
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x4610
movq %rax, -0x68(%rbp)
cmpq $0xc, -0x68(%rbp)
jne 0x42e9
movq -0x8(%rbp), %rdi
movl $0x4, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x47a0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x42e7
movq -0x58(%rbp), %rdi
leaq 0x5ff49(%rip), %rsi     # 0x6416b
movl $0x4, %edx
callq 0x3080
cmpl $0x0, %eax
je 0x424f
movq -0x58(%rbp), %rdi
leaq 0x5ff36(%rip), %rsi     # 0x64172
movl $0x4, %edx
callq 0x3080
cmpl $0x0, %eax
jne 0x42e7
movq -0x8(%rbp), %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4610
movq %rax, -0x60(%rbp)
cmpq $0xd0a870a, -0x60(%rbp) # imm = 0xD0A870A
jne 0x42e5
movq $0xd0a870a, 0x741fd(%rip) # imm = 0xD0A870A
movw $0x0, 0x741ec(%rip)     # 0x78470
movq -0x68(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x4990
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x30a0
cmpl $0x0, %eax
jne 0x42e3
movq -0x8(%rbp), %rdi
callq 0x3190
cmpl $0x0, %eax
jne 0x42e3
movq -0x60(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rax
movq %rax, 0x741bb(%rip)     # 0x78488
movq -0x28(%rbp), %rax
movq %rax, 0x741b8(%rip)     # 0x78490
movq -0x20(%rbp), %rax
movq %rax, 0x741b5(%rip)     # 0x78498
jmp 0x42e5
jmp 0x42e7
jmp 0x42e9
jmp 0x4468
movzwl -0x4a(%rbp), %eax
cmpl $0x4d, %eax
jne 0x437e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x4610
movq %rax, -0x60(%rbp)
cmpq $0x4d524d, -0x60(%rbp)  # imm = 0x4D524D
jne 0x4379
movq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4610
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x30a0
cmpl $0x0, %eax
jne 0x4377
movq -0x8(%rbp), %rdi
callq 0x3190
cmpl $0x0, %eax
jne 0x4377
movq $0x4d524d, 0x74117(%rip) # imm = 0x4D524D
movq -0x40(%rbp), %rax
movq %rax, 0x74134(%rip)     # 0x784a0
movq -0x38(%rbp), %rax
movq %rax, 0x74131(%rip)     # 0x784a8
jmp 0x4379
jmp 0x4466
movzwl -0x4a(%rbp), %eax
cmpl $0x5546, %eax           # imm = 0x5546
je 0x4394
movzwl -0x4a(%rbp), %eax
cmpl $0x4655, %eax           # imm = 0x4655
jne 0x43db
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x10, %edx
callq 0x4a00
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x43d6
movq -0x70(%rbp), %rdi
leaq 0x5fdbd(%rip), %rsi     # 0x64179
movl $0x10, %edx
callq 0x3080
cmpl $0x0, %eax
jne 0x43d6
movq $0x4655, 0x740a2(%rip) # imm = 0x4655
jmp 0x4464
movzwl -0x4a(%rbp), %eax
cmpl $0x464f, %eax           # imm = 0x464F
jne 0x4438
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x4949, %esi           # imm = 0x4949
callq 0x4610
movq %rax, -0x60(%rbp)
cmpq $0x62564f46, -0x60(%rbp) # imm = 0x62564F46
jne 0x4436
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x39fa0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x4434
movq -0x48(%rbp), %rax
movq %rax, 0x74087(%rip)     # 0x784b0
movq $0x62564f46, 0x74044(%rip) # imm = 0x62564F46
jmp 0x4436
jmp 0x4462
movq $0x0, 0x74035(%rip) # 0x78478
movw $0x0, 0x74024(%rip)     # 0x78470
movq $0x0, 0x74029(%rip) # 0x78480
movq $0x0, 0x7404e(%rip) # 0x784b0
jmp 0x4464
jmp 0x4466
jmp 0x4468
jmp 0x446a
jmp 0x446c
leaq 0x73ffd(%rip), %rax     # 0x78470
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)