// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq $-0x1, -0x18(%rbp)
movl $0x2000, %edi           # imm = 0x2000
callq 0x2290
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x680f
leaq 0x13f37(%rip), %rdi     # 0x1a727
leaq 0x12cd8(%rip), %rsi     # 0x194cf
movl $0x7db, %edx            # imm = 0x7DB
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6966
movq -0x10(%rbp), %rdi
leaq 0x135b1(%rip), %rsi     # 0x19dcb
callq 0x2330
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x6854
movq -0x10(%rbp), %rcx
leaq 0x13f3f(%rip), %rdi     # 0x1a774
leaq 0x12c93(%rip), %rsi     # 0x194cf
movl $0x7e3, %edx            # imm = 0x7E3
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6966
cmpq $0x0, -0x38(%rbp)
je 0x6945
movq $0x0, -0x18(%rbp)
movq 0x1f76a(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
callq 0x2220
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x6887
jmp 0x690e
movq -0x20(%rbp), %rdi
movq 0x1f746(%rip), %rax     # 0x25fd8
movq (%rax), %rcx
movl $0x1, %esi
movl $0x1fff, %edx           # imm = 0x1FFF
callq 0x20b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jbe 0x6907
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x1, %esi
callq 0x2380
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x6905
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x10(%rbp), %r9
leaq 0x13ed7(%rip), %rdi     # 0x1a7c9
leaq 0x12bd6(%rip), %rsi     # 0x194cf
movl $0x7f6, %edx            # imm = 0x7F6
movb $0x0, %al
callq 0x117c0
jmp 0x6909
jmp 0x690e
jmp 0x6867
movq -0x38(%rbp), %rdi
callq 0x22b0
movq -0x38(%rbp), %rdi
callq 0x20e0
movq 0x1f6b1(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
callq 0x2220
cmpl $0x0, %eax
je 0x6943
movq 0x1f69d(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
callq 0x2240
jmp 0x6945
cmpq $0x0, -0x20(%rbp)
je 0x6955
movq -0x20(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
movl $0x400, %ecx            # imm = 0x400
cqto
idivq %rcx
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop