// File: /workspace/github_c_makefile_star2_O3/inflex[P]ripMIME/mime.c
// Function: MIME_handle_rfc822
int MIME_handle_rfc822( FFGET_FILE *f, char *unpackdir, struct MIMEH_header_info *h, int current_recursion_level, struct SS_object *ss )
{
    /** Decode a RFC822 encoded stream of data from *f  **/
    int result = 0;
    if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Decoding RFC822 message\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
     **/
    DMIME LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Filename='%s', encoding = %d",FL, h->filename, h->content_transfer_encoding);

    //  if ((0)&&( h->content_transfer_encoding != _CTRANS_ENCODING_B64)&&( h->filename[0] == '0' )) 20041217-1635:PLD:
    if (( h->content_transfer_encoding != _CTRANS_ENCODING_B64)&&( h->filename[0] == '\0' ))
    {
        /** Handle a simple plain text wrapped RFC822 email with no encoding applied to it **/
        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.
        DMIME LOGGER_log("%s:%d:MIME_handle_rfc822: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 {
        /** ...else... if the section has a filename or B64 type encoding, we need to put it through extra decoding **/
        if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Embedded message has a filename, decoding to file %s",FL,h->filename);
        result = MIME_decode_encoding( f, unpackdir, h, ss );
        if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Result of extracting %s is %d",FL,h->filename, result);
        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. **/

            if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Now attempting to extract contents of '%s'",FL,h->filename);
            snprintf(scratch,sizeof(scratch),"%s/%s",unpackdir, h->filename);
            snprintf(h->filename,sizeof(h->filename),"%s",scratch);

            if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822:DEBUG: Now attempting to extract contents of '%s'",FL,scratch);
            result = MIME_unpack_single( unpackdir, scratch, current_recursion_level, ss );
            result = 0;
        }
    } /** else-if transfer-encoding != B64 && filename was empty **/
    if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_handle_rfc822: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, 0x1a642(%rip)     # 0x21300
jle 0x6d0b
leaq 0xd410(%rip), %rdi      # 0x140d7
leaq 0xb711(%rip), %rsi      # 0x123df
movl $0xa33, %edx            # imm = 0xA33
xorl %eax, %eax
callq 0xc84f
cmpl $0x0, 0x1a61f(%rip)     # 0x21300
jle 0x6d0b
leaq 0x5efd(%rbx), %rcx
movl 0x166f8(%rbx), %r8d
leaq 0xd418(%rip), %rdi      # 0x14110
leaq 0xb6e0(%rip), %rsi      # 0x123df
movl $0xa38, %edx            # imm = 0xA38
xorl %eax, %eax
callq 0xc84f
cmpl $0x64, 0x166f8(%rbx)
jne 0x6d1c
movl 0x1a5e6(%rip), %eax     # 0x21300
jmp 0x6d2f
cmpb $0x0, 0x5efd(%rbx)
movl 0x1a5d7(%rip), %eax     # 0x21300
je 0x6e54
testl %eax, %eax
jle 0x6d54
leaq 0x5efd(%rbx), %rcx
leaq 0xd463(%rip), %rdi      # 0x141a4
leaq 0xb697(%rip), %rsi      # 0x123df
movl $0xa4d, %edx            # imm = 0xA4D
xorl %eax, %eax
callq 0xc84f
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x580c
movl %eax, %r12d
cmpl $0x0, 0x1a591(%rip)     # 0x21300
jle 0x6d95
leaq 0x5efd(%rbx), %rcx
leaq 0xd47a(%rip), %rdi      # 0x141f9
leaq 0xb659(%rip), %rsi      # 0x123df
movl $0xa4f, %edx            # imm = 0xA4F
movl %r12d, %r8d
xorl %eax, %eax
callq 0xc84f
testl %r12d, %r12d
jne 0x6eb0
movl %ebp, 0x4(%rsp)
cmpl $0x0, 0x1a557(%rip)     # 0x21300
jle 0x6dcc
leaq 0x5efd(%rbx), %rcx
leaq 0xd47e(%rip), %rdi      # 0x14237
leaq 0xb61f(%rip), %rsi      # 0x123df
movl $0xa55, %edx            # imm = 0xA55
xorl %eax, %eax
callq 0xc84f
leaq 0x5efd(%rbx), %r13
leaq 0x1d986(%rip), %rbp     # 0x24760
leaq 0xb62b(%rip), %rdx      # 0x1240c
xorl %r12d, %r12d
movl $0x400, %esi            # imm = 0x400
movq %rbp, %rdi
movq %r15, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x2140
leaq 0x11260(%rip), %rdx     # 0x18060
movl $0x1001, %esi           # imm = 0x1001
movq %r13, %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2140
cmpl $0x0, 0x1a4e7(%rip)     # 0x21300
jle 0x6e3c
leaq 0xd415(%rip), %rdi      # 0x14237
leaq 0xb5b6(%rip), %rsi      # 0x123df
leaq 0x1d930(%rip), %rcx     # 0x24760
movl $0xa59, %edx            # imm = 0xA59
xorl %eax, %eax
callq 0xc84f
leaq 0x1d91d(%rip), %rsi     # 0x24760
movq %r15, %rdi
movl 0x4(%rsp), %edx
movq %r14, %rcx
callq 0x5f1a
jmp 0x6eb0
testl %eax, %eax
jle 0x6e72
leaq 0xd2ee(%rip), %rdi      # 0x1414d
leaq 0xb579(%rip), %rsi      # 0x123df
movl $0xa46, %edx            # imm = 0xA46
xorl %eax, %eax
callq 0xc84f
movl $0x0, 0x59f8(%rbx)
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
movq %r14, %r8
callq 0x63aa
movl %eax, %r12d
callq 0xd483
testq %rax, %rax
je 0x6eb0
leaq 0x31fe(%rbx), %rdi
movl $0x27f7, %edx           # imm = 0x27F7
movq %rax, %rsi
callq 0xbede
cmpl $0x0, 0x1a449(%rip)     # 0x21300
jle 0x6ee0
addq $0x5efd, %rbx           # imm = 0x5EFD
leaq 0xd3bb(%rip), %rdi      # 0x14282
leaq 0xb511(%rip), %rsi      # 0x123df
movl $0xa5e, %edx            # imm = 0xA5E
movq %rbx, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0xc84f
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq