// File: /workspace/github_c_makefile_star2_O1/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 0xeb5d(%rip), %rsi      # 0x12560
leaq 0x10(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x2270
cmpl $0x0, 0x1d8e7(%rip)     # 0x21300
jle 0x3a38
leaq 0xee63(%rip), %rdi      # 0x12885
leaq 0xe9b6(%rip), %rsi      # 0x123df
movl $0x437, %edx            # imm = 0x437
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc960
leaq 0x12a95(%rip), %rsi     # 0x164d4
movq %rbx, %rdi
callq 0x2350
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x3be3
movl $0x401, %edi            # imm = 0x401
callq 0x22b0
testq %rax, %rax
je 0x3c20
movq %rax, %rbx
movl $0x64, %r14d
leaq 0xeed8(%rip), %r15      # 0x12950
leaq 0xe960(%rip), %r12      # 0x123df
xorl %ebp, %ebp
movl $0x0, (%rsp)
movq %rbx, %rdi
movl $0x400, %esi            # imm = 0x400
movq 0x8(%rsp), %rdx
callq 0x21f0
testq %rax, %rax
je 0x3b94
subl $0x1, %r14d
jb 0x3b94
cmpl $0x0, 0x1e098(%rip)     # 0x21b4c
jne 0x3acb
movzbl (%rbx), %eax
cmpl $0xa, %eax
je 0x3b94
cmpl $0xd, %eax
je 0x3b94
movl %r14d, 0x4(%rsp)
xorl %r13d, %r13d
cmpl $0xa, 0x1d826(%rip)     # 0x21300
leaq 0x10(%rsp,%r13), %r14
jl 0x3af9
movq %r15, %rdi
movq %r12, %rsi
movl $0x453, %edx            # imm = 0x453
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0xc960
movq %r14, %rdi
callq 0x2110
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x22c0
testl %eax, %eax
jne 0x3b66
cmpl $0x0, 0x1d7e6(%rip)     # 0x21300
jle 0x3b35
leaq 0xee65(%rip), %rdi      # 0x12988
movq %r12, %rsi
movl $0x458, %edx            # imm = 0x458
movq %r14, %rcx
xorl %eax, %eax
callq 0xc960
incl %ebp
cmpq $0xb0, %r13
jne 0x3b66
movl $0x1, (%rsp)
cmpl $0x0, 0x1d7b2(%rip)     # 0x21300
jle 0x3b66
leaq 0xee5c(%rip), %rdi      # 0x129b3
movq %r12, %rsi
movl $0x45c, %edx            # imm = 0x45C
xorl %eax, %eax
callq 0xc960
addq $0x10, %r13
cmpq $0xc0, %r13
jne 0x3ad3
cmpl $0x0, (%rsp)
sete %al
cmpl $0x2, %ebp
setl %cl
orb %al, %cl
cmpb $0x1, %cl
movl 0x4(%rsp), %r14d
je 0x3a88
movq 0x8(%rsp), %rdi
callq 0x20f0
cmpl $0x2, %ebp
setge %al
cmpl $0x0, (%rsp)
setne %cl
andb %al, %cl
movzbl %cl, %r14d
movq %rbx, %rdi
callq 0x2030
cmpl $0x0, 0x1d740(%rip)     # 0x21300
jle 0x3c3d
leaq 0xee25(%rip), %rdi      # 0x129ee
leaq 0xe80f(%rip), %rsi      # 0x123df
movl $0x466, %edx            # imm = 0x466
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0xc960
jmp 0x3c3d
xorl %r14d, %r14d
cmpl $0x0, 0x1d717(%rip)     # 0x21304
jne 0x3c3d
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xecc2(%rip), %rdi      # 0x128c4
leaq 0xe7d6(%rip), %rsi      # 0x123df
xorl %r14d, %r14d
movl $0x43e, %edx            # imm = 0x43E
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc960
jmp 0x3c3d
leaq 0xece3(%rip), %rdi      # 0x1290a
leaq 0xe7b1(%rip), %rsi      # 0x123df
xorl %r14d, %r14d
movl $0x446, %edx            # imm = 0x446
xorl %eax, %eax
callq 0xc960
movl %r14d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq