// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rsi, %rbx
movq %rdi, %r14
cmpb $0x0, (%rdi)
je 0x527d
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2340
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x527f
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xe45f(%rip), %rdi      # 0x136c8
leaq 0xd16f(%rip), %rsi      # 0x123df
movl $0x793, %edx            # imm = 0x793
movq %r14, %rcx
jmp 0x53b0
xorl %ebp, %ebp
leaq 0x1(%r15), %rdi
callq 0x22b0
testq %rax, %rax
je 0x5349
movq %rax, %r12
movq %rbx, %rdi
movl $0x41, %esi
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x2340
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x5368
movq %r14, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
xorl %r13d, %r13d
movl %ebp, %edi
movq %r12, %rsi
movq %r15, %rdx
callq 0x21d0
movq %rax, %rbx
testq %rax, %rax
je 0x5320
movl 0x4(%rsp), %edi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x20e0
cmpq $-0x1, %rax
je 0x538c
movq %rax, %r14
cmpq %rax, %rbx
je 0x531d
leaq 0xe4d8(%rip), %rdi      # 0x137d7
leaq 0xd0d9(%rip), %rsi      # 0x123df
movl $0x7b2, %edx            # imm = 0x7B2
movq %rbx, %rcx
movq %r14, %r8
movq 0x8(%rsp), %r9
xorl %eax, %eax
callq 0xc960
addq %r14, %r13
testq %rbx, %rbx
jne 0x52c2
movq 0x10(%rsp), %rax
cmpb $0x0, (%rax)
je 0x5336
movl %ebp, %edi
callq 0x21a0
movl 0x4(%rsp), %edi
callq 0x21a0
movq %r12, %rdi
callq 0x2030
jmp 0x53c1
leaq 0xe3b5(%rip), %rdi      # 0x13705
leaq 0xd088(%rip), %rsi      # 0x123df
movl $0x79b, %edx            # imm = 0x79B
movq %r15, %rcx
xorl %eax, %eax
callq 0xc960
jmp 0x53ba
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xe3d7(%rip), %rdi      # 0x13752
leaq 0xd05d(%rip), %rsi      # 0x123df
movl $0x7a2, %edx            # imm = 0x7A2
movq %rbx, %rcx
jmp 0x53b0
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xe3f1(%rip), %rdi      # 0x13790
leaq 0xd039(%rip), %rsi      # 0x123df
movl $0x7ad, %edx            # imm = 0x7AD
movq 0x8(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc960
movq $-0x1, %r13
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq