// File: /workspace/github_c_makefile_star2_O3/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, 0x23e29(%rip)     # 0x2c38c
jle 0x8582
leaq 0xd01f(%rip), %rdi      # 0x1558b
leaq 0xcd6b(%rip), %rsi      # 0x152de
movl $0x3e3, %edx            # imm = 0x3E3
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc84f
cmpl $0x0, 0x23e0f(%rip)     # 0x2c398
je 0x86c3
testq %rbx, %rbx
je 0x86a0
movq %rbx, %rdi
movl $0x3b, %esi
callq 0x2120
testq %rax, %rax
je 0x86a0
movq %rax, %r12
leaq 0xd01e(%rip), %r14      # 0x155d6
leaq 0xcd1f(%rip), %r15      # 0x152de
leaq 0xd056(%rip), %rbp      # 0x1561c
cmpl $0x0, 0x23dbf(%rip)     # 0x2c38c
jle 0x85ea
movq %r12, %rcx
subq %rbx, %rcx
movq %r14, %rdi
movq %r15, %rsi
movl $0x3f1, %edx            # imm = 0x3F1
movq %r12, %r8
xorl %eax, %eax
callq 0xc84f
leaq 0x1(%r12), %r13
movzbl (%r13), %eax
cmpl $0xa, %eax
je 0x85fe
cmpl $0xd, %eax
jne 0x866c
movq %r13, %rdi
callq 0x84fa
testl %eax, %eax
jne 0x8687
cmpl $0x0, 0x23d7b(%rip)     # 0x2c38c
jle 0x8629
leaq 0xd04b(%rip), %rdi      # 0x15665
movq %r15, %rsi
movl $0x414, %edx            # imm = 0x414
xorl %eax, %eax
callq 0xc84f
movb $0x20, 0x1(%r12)
movzbl 0x2(%r12), %eax
addq $0x2, %r12
cmpl $0xd, %eax
je 0x8643
cmpl $0xa, %eax
jne 0x8648
movb $0x20, (%r12)
cmpl $0x0, 0x23d3d(%rip)     # 0x2c38c
jle 0x8667
leaq 0xd046(%rip), %rdi      # 0x1569e
movq %r15, %rsi
movl $0x418, %edx            # imm = 0x418
xorl %eax, %eax
callq 0xc84f
movq %r12, %r13
jmp 0x8687
cmpl $0x0, 0x23d19(%rip)     # 0x2c38c
jle 0x8687
movq %rbp, %rdi
movq %r15, %rsi
movl $0x40c, %edx            # imm = 0x40C
xorl %eax, %eax
callq 0xc84f
movq %r13, %rdi
movl $0x3b, %esi
callq 0x2120
movq %rax, %r12
testq %rax, %rax
jne 0x85c6
cmpl $0x0, 0x23ce5(%rip)     # 0x2c38c
jle 0x86c3
leaq 0xd020(%rip), %rdi      # 0x156d0
leaq 0xcc27(%rip), %rsi      # 0x152de
movl $0x420, %edx            # imm = 0x420
xorl %eax, %eax
callq 0xc84f
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq