// File: /workspace/github_c_makefile_star2_O3/inflex[P]ripMIME/mime.c
// Function: MIME_read
int MIME_read( char *mpname )
{
    long int fsize=-1;
    char *buffer;
    size_t readcount, writecount;
    FILE *fout;
    buffer = malloc( MIME_MIME_READ_BUFFER_SIZE *sizeof(char) );
    if ( !buffer )
    {
        LOGGER_log("%s:%d:MIME_read:ERROR: could not allocate 4K of memory for file read buffer\n",FL );
        return -1;
    }
    /* open up our input file */
    fout = fopen(mpname,"w");
    /* check that out file opened up okay */
    if (!fout)
    {
        LOGGER_log("%s:%d:MIME_read:ERROR: Cannot open file %s for writing... check permissions perhaps?",FL,mpname);
        //exit(_EXITERR_MIMEREAD_CANNOT_OPEN_OUTPUT);
        return -1;
    }
    /* assuming our file actually opened up */
    if (fout)
    {
        fsize=0;
        /* while there is more data, consume it */
        while ( !feof(stdin) )
        {
            readcount = fread( buffer, 1, ((MIME_MIME_READ_BUFFER_SIZE -1) *sizeof(char)), stdin );
            if ( readcount > 0 )
            {
                writecount = fwrite( buffer, 1, readcount, fout );
                fsize += writecount;

                if ( readcount != writecount )
                {
                    LOGGER_log("%s:%d:MIME_read:ERROR: Attempted to write %d bytes, but only managed %d to file '%s'",FL, readcount, writecount, mpname );
                }

            } else {
                break;
            }
        }
        /* clean up our buffers and close */
        fflush(fout);
        fclose(fout);
        if ( feof(stdin) ) clearerr(stdin);
    } /* end if fout was received okay */
    if ( buffer ) free( buffer );
    /* return our byte count in KB */
    return (int)(fsize /1024);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movl $0x2000, %edi           # imm = 0x2000
callq 0x22a0
testq %rax, %rax
je 0x5459
movq %rax, %rbx
leaq 0xdb80(%rip), %rsi      # 0x12f2b
movq %r14, %rdi
callq 0x2340
testq %rax, %rax
je 0x5475
movq %rax, %r15
movq 0x1ac12(%rip), %rbp     # 0x1ffd8
movq (%rbp), %rdi
callq 0x2230
xorl %r12d, %r12d
testl %eax, %eax
jne 0x54af
movq %r14, (%rsp)
xorl %r13d, %r13d
movq %rbp, %r14
movq (%rbp), %rcx
movl $0x1, %esi
movl $0x1fff, %edx           # imm = 0x1FFF
movq %rbx, %rdi
callq 0x20c0
testq %rax, %rax
je 0x549a
movq %rax, %rbp
movl $0x1, %esi
movq %rbx, %rdi
movq %rax, %rdx
movq %r15, %rcx
callq 0x2390
movq %rax, %r12
cmpq %rax, %rbp
je 0x5445
leaq 0xe4da(%rip), %rdi      # 0x13902
leaq 0xcfb0(%rip), %rsi      # 0x123df
movl $0x7f6, %edx            # imm = 0x7F6
movq %rbp, %rcx
movq %r12, %r8
movq (%rsp), %r9
xorl %eax, %eax
callq 0xc84f
addq %r12, %r13
movq %r14, %rbp
movq (%r14), %rdi
callq 0x2230
testl %eax, %eax
je 0x53e1
jmp 0x549d
leaq 0xe400(%rip), %rdi      # 0x13860
leaq 0xcf78(%rip), %rsi      # 0x123df
movl $0x7db, %edx            # imm = 0x7DB
xorl %eax, %eax
callq 0xc84f
jmp 0x5492
leaq 0xe431(%rip), %rdi      # 0x138ad
leaq 0xcf5c(%rip), %rsi      # 0x123df
movl $0x7e3, %edx            # imm = 0x7E3
movq %r14, %rcx
xorl %eax, %eax
callq 0xc84f
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x54dd
movq %r14, %rbp
leaq 0x3ff(%r13), %r12
testq %r13, %r13
cmovnsq %r13, %r12
shrq $0xa, %r12
movq %r15, %rdi
callq 0x22c0
movq %r15, %rdi
callq 0x20f0
movq (%rbp), %rdi
callq 0x2230
testl %eax, %eax
je 0x54d5
movq (%rbp), %rdi
callq 0x2250
movq %rbx, %rdi
callq 0x2030
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq