// File: /workspace/github_c_makefile_star2_O3/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, %r14
cmpb $0x0, (%rdi)
je 0x520a
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x2330
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
jne 0x5212
callq 0x2060
movl (%rax), %edi
callq 0x23b0
leaq 0xe502(%rip), %rdi      # 0x136f8
leaq 0xd1e2(%rip), %rsi      # 0x123df
movl $0x793, %edx            # imm = 0x793
movq %r14, %rcx
jmp 0x535d
movl $0x0, 0x4(%rsp)
leaq 0x1(%rbp), %rdi
callq 0x22a0
testq %rax, %rax
je 0x52cf
movq %rax, %r12
movq %rbx, %rdi
movl $0x41, %esi
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x2330
cmpl $-0x1, %eax
je 0x52ee
movl %eax, %r13d
movq %r14, 0x10(%rsp)
movl 0x4(%rsp), %edi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x21d0
testq %rax, %rax
je 0x5312
movq %rax, %r14
movq %rbx, 0x8(%rsp)
xorl %ebx, %ebx
movl %r13d, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x20e0
cmpq $-0x1, %rax
je 0x5339
movq %rax, %r15
cmpq %rax, %r14
je 0x52b3
leaq 0xe572(%rip), %rdi      # 0x13807
leaq 0xd143(%rip), %rsi      # 0x123df
movl $0x7b2, %edx            # imm = 0x7B2
movq %r14, %rcx
movq %r15, %r8
movq 0x8(%rsp), %r9
xorl %eax, %eax
callq 0xc84f
addq %r15, %rbx
movl 0x4(%rsp), %edi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x21d0
movq %rax, %r14
testq %rax, %rax
jne 0x526e
jmp 0x5314
leaq 0xe45f(%rip), %rdi      # 0x13735
leaq 0xd102(%rip), %rsi      # 0x123df
movl $0x79b, %edx            # imm = 0x79B
movq %rbp, %rcx
xorl %eax, %eax
callq 0xc84f
jmp 0x5367
callq 0x2060
movl (%rax), %edi
callq 0x23b0
leaq 0xe481(%rip), %rdi      # 0x13782
leaq 0xd0d7(%rip), %rsi      # 0x123df
movl $0x7a2, %edx            # imm = 0x7A2
movq %rbx, %rcx
jmp 0x535d
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
cmpb $0x0, (%rax)
je 0x5327
movl 0x4(%rsp), %edi
callq 0x21a0
movl %r13d, %edi
callq 0x21a0
movq %r12, %rdi
callq 0x2030
jmp 0x536e
callq 0x2060
movl (%rax), %edi
callq 0x23b0
leaq 0xe474(%rip), %rdi      # 0x137c0
leaq 0xd08c(%rip), %rsi      # 0x123df
movl $0x7ad, %edx            # imm = 0x7AD
movq 0x8(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc84f
movq $-0x1, %rbx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq