// File: /workspace/github_c_makefile_star2_O2/hfiguiere[P]exifprobe/readfile.c
// Function: read_bytes
unsigned char *
read_bytes(FILE *inptr,unsigned long nbytes,unsigned long offset)
{
    static unsigned char rbuf[MAXBUFLEN];
    unsigned long curoffset;
    unsigned char *value = NULL;
    int chpr = 0;

    memset(rbuf,0,MAXBUFLEN);
    if(inptr)
    {
        if(nbytes > MAXBUFLEN)
        {
            chpr += printf(" read %lu bytes would overrun buffer; truncating to %d\n",
                                                                nbytes,MAXBUFLEN);
            nbytes = MAXBUFLEN;
        }
        if(nbytes)
        {
            if(inptr) /* ###%%% redundant; FIXME                      */
            {
                clearerr(inptr);
                curoffset = ftell(inptr);
                if((offset != HERE) && (fseek(inptr,offset,SEEK_SET) == -1))
                {
                    printred(" SEEK FAILED to read unsigned bytes at offset ");
                    chpr += printf("%lu",offset);
                }
                else
                {
                    if(fread(rbuf,1,nbytes,inptr) == nbytes)
                        value = rbuf;
                    else
                    {
                        if(offset == HERE)
                            offset = curoffset;
                        PUSHCOLOR(RED);
                        chpr += printf(" FAILED to read %lu unsigned bytes at offset ",nbytes);
                        chpr += printf("%lu",offset);
                        POPCOLOR();
                    }
                }
                if(ferror(inptr))
                {
                    chpr += printf(" (");
                    setcharsprinted(chpr);
                    chpr = 0;
                    printred(strerror(errno));
                    chpr += printf(")");
                    chpr = newline(chpr);
                }
                else if(feof(inptr))
                {
                    printred(" (EOF)");
                    chpr = newline(chpr);
                }
            }
        }
    }
    return(value);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r14
leaq 0x540a5(%rip), %rbx     # 0x584d0
movl $0x2000, %edx           # imm = 0x2000
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3140
testq %r14, %r14
je 0x44fc
cmpq $0x2001, %r13           # imm = 0x2001
jb 0x446d
leaq 0x3aeb4(%rip), %rdi     # 0x3f307
movq %r13, %rsi
movl $0x2000, %edx           # imm = 0x2000
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
movl $0x2000, %r13d          # imm = 0x2000
jmp 0x4479
xorl %r15d, %r15d
testq %r13, %r13
je 0x44fc
movq %r14, %rdi
callq 0x31b0
movq %r14, %rdi
callq 0x3190
movq %rax, %rbp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r12
je 0x44a8
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x3210
cmpl $-0x1, %eax
je 0x4503
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %r13, %rdx
movq %r14, %rcx
callq 0x30d0
cmpq %r13, %rax
je 0x4528
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r12
cmovneq %r12, %rbp
leaq 0x3ae9d(%rip), %rdi     # 0x3f36e
xorl %ebx, %ebx
movq %r13, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r12d
addl %r15d, %r12d
leaq 0x423fb(%rip), %rdi     # 0x468e5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl %r12d, %r15d
jmp 0x4528
xorl %ebx, %ebx
jmp 0x4594
leaq 0x3ae35(%rip), %rdi     # 0x3f33f
callq 0x56e2
leaq 0x423cf(%rip), %rdi     # 0x468e5
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x3120
addl %r15d, %eax
movl %eax, %r15d
movq %r14, %rdi
callq 0x30b0
testl %eax, %eax
je 0x4574
leaq 0x3accd(%rip), %rdi     # 0x3f208
xorl %eax, %eax
callq 0x3120
addl %eax, %r15d
movl %r15d, %edi
callq 0x16a4f
callq 0x3070
movl (%rax), %edi
callq 0x32c0
movq %rax, %rdi
callq 0x56e2
leaq 0x425fd(%rip), %rdi     # 0x46b65
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
jmp 0x458c
movq %r14, %rdi
callq 0x31a0
testl %eax, %eax
je 0x4594
leaq 0x3ac84(%rip), %rdi     # 0x3f20b
callq 0x56e2
movl %r15d, %edi
callq 0x160f7
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq