// File: /workspace/github_c_makefile_star2_O2/inflex[P]ripMIME/mime.c
// Function: MIME_handle_multipart
int MIME_handle_multipart( FFGET_FILE *f, char *unpackdir, struct MIMEH_header_info *h, int current_recursion_level, struct SS_object *ss )
{
    int result = 0;
    if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_multipart:DEBUG: Decoding multipart/embedded \n",FL);
    // If there is no filename, then we have a "standard"
    // embedded message, which can be just read off as a
    // continuous stream (simply with new boundaries
    //
    if (( h->content_transfer_encoding != _CTRANS_ENCODING_B64)&&( h->filename[0] == '\0' ))
    {
        char *p;

        // If this is a simple 'wrapped' RFC822 email which has no encoding applied to it
        //      (ie, it's just the existing email with a new set of headers around it
        //      then rather than saving it to a file, we'll just peel off these outter
        //      layer of headers and get into the core of the message.  This is why we
        //      call unpack_stage2() because this function just reads the next set of
        //      headers and decodes.
        if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_multipart:DEBUG: Non base64 encoding AND no filename, embedded message\n",FL);
        h->boundary_located = 0;
        result = MIME_unpack_stage2(f, unpackdir, h, current_recursion_level , ss);
        p = BS_top();
        if (p) PLD_strncpy(h->boundary, p,sizeof(h->boundary));
    } else {
        if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_multipart:DEBUG: Embedded message has a filename, decoding to file %s",FL,h->filename);
        result = MIME_decode_encoding( f, unpackdir, h, ss );
        if (result == 0)
        {
            // Because we're calling MIME_unpack_single again [ie, recursively calling it
            // we need to now adjust the input-filename so that it correctly is prefixed
            // with the directory we unpacked to.

            snprintf(scratch,sizeof(scratch),"%s/%s",unpackdir, h->filename);
            snprintf(h->filename,sizeof(h->filename),"%s",scratch);

            //result = MIME_unpack_single( unpackdir, h->filename, current_recursion_level +1, ss);
            result = MIME_unpack_single( unpackdir, h->filename, current_recursion_level, ss );
        }

    } // else-if transfer-encoding != B64 && filename was empty
    if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_multipart:DEBUG: done handling '%s' result = %d",FL,h->filename, result);
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r14
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
cmpl $0x0, 0x1a2c0(%rip)     # 0x20300
jle 0x605c
leaq 0xcf59(%rip), %rdi      # 0x12fa2
leaq 0xb38f(%rip), %rsi      # 0x113df
movl $0x9f3, %edx            # imm = 0x9F3
xorl %eax, %eax
callq 0xc2a1
cmpl $0x64, 0x166f8(%rbx)
jne 0x606d
movl 0x1a295(%rip), %eax     # 0x20300
jmp 0x6080
cmpb $0x0, 0x5efd(%rbx)
movl 0x1a286(%rip), %eax     # 0x20300
je 0x6119
testl %eax, %eax
jle 0x60a5
leaq 0x5efd(%rbx), %rcx
leaq 0xcfab(%rip), %rdi      # 0x1303d
leaq 0xb346(%rip), %rsi      # 0x113df
movl $0xa08, %edx            # imm = 0xA08
xorl %eax, %eax
callq 0xc2a1
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x561f
movl %eax, %r12d
testl %eax, %eax
jne 0x6172
leaq 0x5efd(%rbx), %r12
leaq 0x1d691(%rip), %r13     # 0x23760
leaq 0xb336(%rip), %rdx      # 0x1140c
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x2140
leaq 0x10f6e(%rip), %rdx     # 0x17060
movl $0x1001, %esi           # imm = 0x1001
movq %r12, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x2140
movq %r15, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0x5d29
movl %eax, %r12d
jmp 0x6172
testl %eax, %eax
jle 0x6137
leaq 0xcebf(%rip), %rdi      # 0x12fe3
leaq 0xb2b4(%rip), %rsi      # 0x113df
movl $0xa02, %edx            # imm = 0xA02
xorl %eax, %eax
callq 0xc2a1
andl $0x0, 0x59f8(%rbx)
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
movq %r14, %r8
callq 0x61b4
movl %eax, %r12d
callq 0xce57
testq %rax, %rax
je 0x6172
leaq 0x31fe(%rbx), %rdi
movl $0x27f7, %edx           # imm = 0x27F7
movq %rax, %rsi
callq 0xba3e
cmpl $0x0, 0x1a187(%rip)     # 0x20300
jle 0x61a2
addq $0x5efd, %rbx           # imm = 0x5EFD
leaq 0xcf0c(%rip), %rdi      # 0x13095
leaq 0xb24f(%rip), %rsi      # 0x113df
movl $0xa18, %edx            # imm = 0xA18
movq %rbx, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0xc2a1
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq