// File: /workspace/github_c_makefile_star2_O2/inflex[P]ripMIME/MIME_headers.c
// Function: MIMEH_fix_header_mistakes
int MIMEH_fix_header_mistakes( char *data )
{
    int result = 0;
    char *p;

    DMIMEH LOGGER_log("%s:%d:MIMEH_fix_header_mistakes:DEBUG: Checking and fixing headers in '%s'",FL,data);

    if (glb.header_fix == 0) return result;

    p = data;
    while (p) {
        int nonblank_detected = 0;
        char *q;

        p = strchr(p, ';');
        if (p == NULL) break;

        q = p+1;

        DMIMEH LOGGER_log("%s:%d:MIMEH_fix_header_mistakes:DEBUG: Located ';' at offset %d '%20s",FL, p -data, p);

        if ((*q == '\n')||(*q == '\r')) {
            nonblank_detected = 0;
        } else {
            /** If the ; isn't immediately followed by a \n or \r, then search till
             ** the end of the line to see if all the chars are blank **/

            while ((*q != '\0')||(*q != '\r')||(*q != '\n')) {
                switch (*q) {
                    case '\t':
                    case '\n':
                    case '\r':
                    case ' ':
                        nonblank_detected = 0;
                        break;
                    default:
                        nonblank_detected = 1;
                } /*switch*/

                if (nonblank_detected == 1) break;

                q++;
            } /** while looking for the end of the line **/
        } /** ELSE - if *q wasn't a line break char **/

        if (nonblank_detected == 1) {
            DMIMEH LOGGER_log("%s:%d:MIMEH_fix_header_mistakes:DEBUG: Line was normal/safe, continue...",FL);
            p++;
            continue;
        } /** if nonblank_detected == 1 **/
        /** if we had nothing but blanks till the end of the
         ** line, then we need to pull up the next line **/
        if (*q != '\0') {
            if(!MIMEH_check_ct(q)){
                DMIMEH LOGGER_log("%s:%d:MIMEH_fix_header_mistakes:DEBUG: Line needs fixing",FL);
                *q = ' ';
                q++;
                if ((*q == '\n')||(*q == '\r')) *q = ' ';
                DMIMEH LOGGER_log("%s:%d:MIMEH_fix_header_mistakes:DEBUG: Line fixed",FL);
                p = q;
            }else{
                p++;
            }
        } /** If q wasn't the end of data **/
    } /** while looking for more ';' chars **/

    DMIMEH LOGGER_log("%s:%d:MIMEH_fix_header_mistakes:DEBUG: Done",FL);
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x0, 0x23040(%rip)     # 0x2b38c
jle 0x836b
leaq 0xc236(%rip), %rdi      # 0x1458b
leaq 0xbf82(%rip), %rsi      # 0x142de
movl $0x3e3, %edx            # imm = 0x3E3
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc2a1
cmpl $0x0, 0x23026(%rip)     # 0x2b398
je 0x84a6
pushq $0x3b
popq %rbp
leaq 0xbf5c(%rip), %r15      # 0x142de
movq %rbx, %r13
testq %r13, %r13
je 0x8482
movq %r13, %rdi
movl %ebp, %esi
callq 0x2120
movq %rax, %r12
movl 0x22feb(%rip), %eax     # 0x2b38c
testq %r12, %r12
je 0x8488
movq %r12, %r14
testl %eax, %eax
jle 0x83d0
movq %r12, %rcx
subq %rbx, %rcx
leaq 0xc218(%rip), %rdi      # 0x145d6
movq %r15, %rsi
movl $0x3f1, %edx            # imm = 0x3F1
movq %r14, %r8
xorl %eax, %eax
callq 0xc2a1
leaq 0x1(%r12), %r13
movzbl (%r13), %eax
cmpl $0xa, %eax
je 0x83e4
cmpl $0xd, %eax
jne 0x845a
movq %r13, %rdi
callq 0x82e5
testl %eax, %eax
jne 0x8385
cmpl $0x0, 0x22f95(%rip)     # 0x2b38c
jle 0x840f
leaq 0xc265(%rip), %rdi      # 0x14665
movq %r15, %rsi
movl $0x414, %edx            # imm = 0x414
xorl %eax, %eax
callq 0xc2a1
movb $0x20, 0x1(%r14)
addq $0x2, %r12
movzbl 0x2(%r14), %eax
cmpl $0xd, %eax
je 0x8427
cmpl $0xa, %eax
jne 0x842c
movb $0x20, (%r12)
cmpl $0x0, 0x22f59(%rip)     # 0x2b38c
movq %r12, %r13
jle 0x8385
leaq 0xc25b(%rip), %rdi      # 0x1469e
movq %r15, %rsi
movl $0x418, %edx            # imm = 0x418
xorl %eax, %eax
callq 0xc2a1
movq %r12, %r13
jmp 0x8385
cmpl $0x0, 0x22f2b(%rip)     # 0x2b38c
jle 0x8385
leaq 0xc1ae(%rip), %rdi      # 0x1461c
movq %r15, %rsi
movl $0x40c, %edx            # imm = 0x40C
xorl %eax, %eax
callq 0xc2a1
jmp 0x8385
movl 0x22f04(%rip), %eax     # 0x2b38c
testl %eax, %eax
jle 0x84a6
leaq 0xc23d(%rip), %rdi      # 0x146d0
leaq 0xbe44(%rip), %rsi      # 0x142de
movl $0x420, %edx            # imm = 0x420
xorl %eax, %eax
callq 0xc2a1
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq