// File: /workspace/github_c_makefile_star2_O2/inflex[P]ripMIME/mime.c
// Function: MIME_read_raw
size_t MIME_read_raw( char *src_mpname, char *dest_mpname, size_t rw_buffer_size )
{
    size_t readcount, writecount;
    size_t fsize=-1;
    char *rw_buffer;
    int fin;
    int fout;

    rw_buffer = NULL;

    if (*src_mpname == '\0') {
        fin = STDIN_FILENO;
    } else {
        fin = open(src_mpname, O_RDONLY);
        if (fin == -1) {
            LOGGER_log("%s:%d:MIME_read_raw:ERROR: Cannot open '%s' for reading (%s)", FL, src_mpname, strerror(errno));
            return -1;
        }
    }

    rw_buffer = malloc( (rw_buffer_size +1) *sizeof(char) );
    if ( !rw_buffer )
    {
        LOGGER_log("%s:%d:MIME_read:ERROR: could not allocate %d of memory for file read buffer\n",FL, rw_buffer_size );
        return -1;
    }

    /* open up our input file */
    fout = open(dest_mpname,O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
    if (fout == -1) {
        LOGGER_log("%s:%d:MIME_read_raw:ERROR: Cannot open '%s' for writing. (%s)",FL, dest_mpname, strerror(errno));
        return -1;
    }

    fsize=0;
    /* while there is more data, consume it */
    do {
        readcount = read( fin, rw_buffer, rw_buffer_size );
        if (readcount > 0) {
            writecount = write( fout, rw_buffer, readcount );
            if (writecount == -1) {
                LOGGER_log("%s:%d:MIME_read_raw:ERROR: While attempting to write data to '%s' (%s)", FL, dest_mpname, strerror(errno));
                return -1;
            }
            if ( readcount != writecount )
            {
                LOGGER_log("%s:%d:MIME_read_raw:ERROR: Attempted to write %d bytes, but only managed %d to file '%s'",FL, readcount, writecount, dest_mpname );
            }
            fsize += writecount;
        }
    } while (readcount > 0);

    if ((*src_mpname != '\0')&&(readcount >= 0)) {
        close(fin);
    }
    if (readcount == -1) {
        LOGGER_log("%s:%d:MIME_read_raw:ERROR: read() '%s'",FL, strerror(errno));
        return -1;
    }
    close(fout);
    if ( rw_buffer != NULL ) free( rw_buffer );
    return (size_t)(fsize);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r15
cmpb $0x0, (%rdi)
je 0x5086
movq %r15, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2340
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
jne 0x508e
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xd686(%rip), %rdi      # 0x126f8
leaq 0xc366(%rip), %rsi      # 0x113df
movl $0x793, %edx            # imm = 0x793
movq %r15, %rcx
jmp 0x51bf
movl $0x0, 0x4(%rsp)
leaq 0x1(%rbp), %rdi
callq 0x22a0
testq %rax, %rax
je 0x5133
movq %rax, %r12
pushq $0x41
popq %rsi
movq %rbx, %rdi
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x2340
cmpl $-0x1, %eax
je 0x5152
movl %eax, %r14d
movq %r15, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
xorl %r13d, %r13d
movl 0x4(%rsp), %edi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x21d0
testq %rax, %rax
je 0x5176
movq %rax, %rbx
movl %r14d, %edi
movq %r12, %rsi
movq %rax, %rdx
callq 0x20e0
cmpq $-0x1, %rax
je 0x519b
movq %rax, %r15
cmpq %rax, %rbx
je 0x512e
leaq 0xd6f7(%rip), %rdi      # 0x12807
leaq 0xc2c8(%rip), %rsi      # 0x113df
movl $0x7b2, %edx            # imm = 0x7B2
movq %rbx, %rcx
movq %r15, %r8
movq 0x8(%rsp), %r9
xorl %eax, %eax
callq 0xc2a1
addq %r15, %r13
jmp 0x50ce
leaq 0xd5fb(%rip), %rdi      # 0x12735
leaq 0xc29e(%rip), %rsi      # 0x113df
movl $0x79b, %edx            # imm = 0x79B
movq %rbp, %rcx
xorl %eax, %eax
callq 0xc2a1
jmp 0x51c9
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xd61d(%rip), %rdi      # 0x12782
leaq 0xc273(%rip), %rsi      # 0x113df
movl $0x7a2, %edx            # imm = 0x7A2
movq %rbx, %rcx
jmp 0x51bf
movq 0x10(%rsp), %rax
cmpb $0x0, (%rax)
je 0x5189
movl 0x4(%rsp), %edi
callq 0x21a0
movl %r14d, %edi
callq 0x21a0
movq %r12, %rdi
callq 0x2030
jmp 0x51cd
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xd612(%rip), %rdi      # 0x127c0
leaq 0xc22a(%rip), %rsi      # 0x113df
movl $0x7ad, %edx            # imm = 0x7AD
movq 0x8(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc2a1
pushq $-0x1
popq %r13
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq