// File: /workspace/github_c_makefile_star2_O1/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 0x22b0
testq %rax, %rax
je 0x54ac
movq %rax, %rbx
leaq 0xdafd(%rip), %rsi      # 0x12efb
movq %r14, %rdi
callq 0x2350
testq %rax, %rax
je 0x54c8
movq %rax, %r15
movq 0x1abbf(%rip), %rbp     # 0x1ffd8
movq (%rbp), %rdi
callq 0x2240
xorl %r12d, %r12d
testl %eax, %eax
jne 0x5502
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 0x54ed
movq %rax, %rbp
movl $0x1, %esi
movq %rbx, %rdi
movq %rax, %rdx
movq %r15, %rcx
callq 0x23a0
movq %rax, %r12
cmpq %rax, %rbp
je 0x5498
leaq 0xe457(%rip), %rdi      # 0x138d2
leaq 0xcf5d(%rip), %rsi      # 0x123df
movl $0x7f6, %edx            # imm = 0x7F6
movq %rbp, %rcx
movq %r12, %r8
movq (%rsp), %r9
xorl %eax, %eax
callq 0xc960
addq %r12, %r13
movq %r14, %rbp
movq (%r14), %rdi
callq 0x2240
testl %eax, %eax
je 0x5434
jmp 0x54f0
leaq 0xe37d(%rip), %rdi      # 0x13830
leaq 0xcf25(%rip), %rsi      # 0x123df
movl $0x7db, %edx            # imm = 0x7DB
xorl %eax, %eax
callq 0xc960
jmp 0x54e5
leaq 0xe3ae(%rip), %rdi      # 0x1387d
leaq 0xcf09(%rip), %rsi      # 0x123df
movl $0x7e3, %edx            # imm = 0x7E3
movq %r14, %rcx
xorl %eax, %eax
callq 0xc960
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x5530
movq %r14, %rbp
leaq 0x3ff(%r13), %r12
testq %r13, %r13
cmovnsq %r13, %r12
shrq $0xa, %r12
movq %r15, %rdi
callq 0x22d0
movq %r15, %rdi
callq 0x20f0
movq (%rbp), %rdi
callq 0x2240
testl %eax, %eax
je 0x5528
movq (%rbp), %rdi
callq 0x2260
movq %rbx, %rdi
callq 0x2030
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq