// File: /workspace/github_c_makefile_star2_O3/inflex[P]ripMIME/mime.c
// Function: MIME_is_file_RFC822
int MIME_is_file_RFC822( char *fname )
{
    char conditions[16][16] = {
        "Received: ", "From: ", "Subject: ", "Date: ", "Content-", "content-", "from: ", "subject: ", "date: ", "boundary=", "Boundary=", "MIME-Version"        };
    int result = 0;
    int flag_mime_version = 0;
    int hitcount = 0;
    int linecount = 100; // We should only need to read the first 10 lines of any file.
    char *line;
    FILE *f;

    if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_is_file_RFC822:DEBUG: Testing %s for RFC822 headers",FL,fname);

    f = fopen(fname,"r");
    if (!f)
    {
        if (glb.quiet == 0)
        {
            LOGGER_log("%s:%d:MIME_is_file_mime:ERROR: cannot open file '%s' for reading (%s)", FL, fname,strerror(errno));
        }
        return 0;
    }

    line = malloc(sizeof(char) *1025);
    if (!line)
    {
        LOGGER_log("%s:%d:MIME_is_file_mime:ERROR: cannot allocate memory for read buffer", FL);
        return 0;
    }

    while (((!flag_mime_version)||(hitcount < 2))&&(fgets(line,1024,f))&&(linecount--))
    {
        /** test every line for possible headers, until we get a blank line **/

        if ((glb.header_longsearch == 0)&&(*line == '\n' || *line == '\r')) break;

        for (result = 0; result < 12; result++)
        {
            /** Test for every possible MIME header prefix, ie, From: Subject: etc **/
            if (MIME_DPEDANTIC) LOGGER_log("%s:%d:MIME_is_file_mime:DEBUG: Testing for '%s' in '%s'", FL, line, conditions[result]);
            if (strncasecmp(line,conditions[result],strlen(conditions[result]))==0)
            {
                /** If we get a match, then increment the hit counter **/
                hitcount++;
                if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_is_file_RFC822:DEBUG: Hit on %s",FL,conditions[result]);
                if (result == 11)
                {
                    flag_mime_version = 1;
                    if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_is_file_RFC822:DEBUG: Find 'MIME Version' field",FL);
                }
            }
        }
    }

    fclose(f);
    if (hitcount >= 2 && flag_mime_version) result = 1;
    else result = 0;
    if (line) free(line);
    if (MIME_DNORMAL) LOGGER_log("%s:%d:MIME_is_file_RFC822:DEBUG: Hit count = %d, result = %d",FL,hitcount,result);
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
leaq 0xeb9b(%rip), %rsi      # 0x12560
leaq 0x10(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x2260
cmpl $0x0, 0x1d925(%rip)     # 0x21300
jle 0x39fa
leaq 0xeed1(%rip), %rdi      # 0x128b5
leaq 0xe9f4(%rip), %rsi      # 0x123df
movl $0x437, %edx            # imm = 0x437
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc84f
leaq 0x12b03(%rip), %rsi     # 0x16504
movq %rbx, %rdi
callq 0x2340
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x3b9c
movl $0x401, %edi            # imm = 0x401
callq 0x22a0
testq %rax, %rax
je 0x3bd9
movq %rax, %rbx
movl $0x64, %r13d
leaq 0xe9a5(%rip), %r12      # 0x123df
xorl %ebp, %ebp
movl $0x0, 0x4(%rsp)
movq %rbx, %rdi
movl $0x400, %esi            # imm = 0x400
movq 0x8(%rsp), %rdx
callq 0x21f0
testq %rax, %rax
je 0x3b4c
subl $0x1, %r13d
jb 0x3b4c
cmpl $0x0, 0x1e0dc(%rip)     # 0x21b4c
jne 0x3a87
movzbl (%rbx), %eax
cmpl $0xa, %eax
je 0x3b4c
cmpl $0xd, %eax
je 0x3b4c
xorl %r15d, %r15d
cmpl $0xa, 0x1d86f(%rip)     # 0x21300
leaq 0x10(%rsp,%r15), %r14
jl 0x3ab4
leaq 0xeee1(%rip), %rdi      # 0x12980
movq %r12, %rsi
movl $0x453, %edx            # imm = 0x453
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0xc84f
movq %r14, %rdi
callq 0x2110
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x22b0
testl %eax, %eax
jne 0x3afb
cmpl $0x0, 0x1d82b(%rip)     # 0x21300
jle 0x3af0
leaq 0xeeda(%rip), %rdi      # 0x129b8
movq %r12, %rsi
movl $0x458, %edx            # imm = 0x458
movq %r14, %rcx
xorl %eax, %eax
callq 0xc84f
incl %ebp
cmpq $0xb0, %r15
je 0x3b23
addq $0x10, %r15
cmpq $0xc0, %r15
jne 0x3a8a
cmpl $0x0, 0x4(%rsp)
sete %al
cmpl $0x2, %ebp
setl %cl
orb %al, %cl
cmpb $0x1, %cl
je 0x3a44
jmp 0x3b4c
movl $0x1, 0x4(%rsp)
cmpl $0x0, 0x1d7ce(%rip)     # 0x21300
jle 0x3b08
leaq 0xeea8(%rip), %rdi      # 0x129e3
movq %r12, %rsi
movl $0x45c, %edx            # imm = 0x45C
xorl %eax, %eax
callq 0xc84f
jmp 0x3b08
movq 0x8(%rsp), %rdi
callq 0x20f0
cmpl $0x2, %ebp
setge %al
cmpl $0x0, 0x4(%rsp)
setne %cl
andb %al, %cl
movzbl %cl, %r14d
movq %rbx, %rdi
callq 0x2030
cmpl $0x0, 0x1d787(%rip)     # 0x21300
jle 0x3bf6
leaq 0xee9c(%rip), %rdi      # 0x12a1e
leaq 0xe856(%rip), %rsi      # 0x123df
movl $0x466, %edx            # imm = 0x466
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0xc84f
jmp 0x3bf6
xorl %r14d, %r14d
cmpl $0x0, 0x1d75e(%rip)     # 0x21304
jne 0x3bf6
callq 0x2060
movl (%rax), %edi
callq 0x23b0
leaq 0xed39(%rip), %rdi      # 0x128f4
leaq 0xe81d(%rip), %rsi      # 0x123df
xorl %r14d, %r14d
movl $0x43e, %edx            # imm = 0x43E
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc84f
jmp 0x3bf6
leaq 0xed5a(%rip), %rdi      # 0x1293a
leaq 0xe7f8(%rip), %rsi      # 0x123df
xorl %r14d, %r14d
movl $0x446, %edx            # imm = 0x446
xorl %eax, %eax
callq 0xc84f
movl %r14d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq