// File: /workspace/github_c_makefile_star2_O2/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 0x52d1
movq %rax, %rbx
leaq 0xcd21(%rip), %rsi      # 0x11f2b
movq %r14, %rdi
callq 0x2350
testq %rax, %rax
je 0x52ed
movq %rax, %r12
movq %r14, (%rsp)
movq 0x19daf(%rip), %r14     # 0x1efd8
pushq $0x1
popq %r13
xorl %r15d, %r15d
movq (%r14), %rdi
callq 0x2230
testl %eax, %eax
jne 0x5296
movq (%r14), %rcx
movl $0x1fff, %edx           # imm = 0x1FFF
movq %rbx, %rdi
movq %r13, %rsi
callq 0x20c0
testq %rax, %rax
je 0x5296
movq %rax, %rbp
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
movq %r12, %rcx
callq 0x23a0
addq %rax, %r15
cmpq %rax, %rbp
je 0x5230
leaq 0xd68b(%rip), %rdi      # 0x12902
leaq 0xc161(%rip), %rsi      # 0x113df
movl $0x7f6, %edx            # imm = 0x7F6
movq %rbp, %rcx
movq %rax, %r8
movq (%rsp), %r9
xorl %eax, %eax
callq 0xc2a1
jmp 0x5230
movq %r12, %rdi
callq 0x22c0
movq %r12, %rdi
callq 0x20f0
movq (%r14), %rdi
callq 0x2230
testl %eax, %eax
je 0x52ba
movq (%r14), %rdi
callq 0x2250
movq %rbx, %rdi
callq 0x2030
movl $0x400, %ecx            # imm = 0x400
movq %r15, %rax
cqto
idivq %rcx
jmp 0x530d
leaq 0xd588(%rip), %rdi      # 0x12860
leaq 0xc100(%rip), %rsi      # 0x113df
movl $0x7db, %edx            # imm = 0x7DB
xorl %eax, %eax
callq 0xc2a1
jmp 0x530a
leaq 0xd5b9(%rip), %rdi      # 0x128ad
leaq 0xc0e4(%rip), %rsi      # 0x113df
movl $0x7e3, %edx            # imm = 0x7E3
movq %r14, %rcx
xorl %eax, %eax
callq 0xc2a1
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq