// File: /workspace/github_c_makefile_star2_O2/inflex[P]ripMIME/MIME_headers.c
// Function: MIMEH_strip_comments
int MIMEH_strip_comments( char *input )
{
    char *p,*p_org;
    int in_quote=0;

    if (input == NULL) return 0;

    p = p_org = input;

    do {
        char *q = NULL;

        // Locate (if any) the first occurance of the (
        while ((p_org != NULL)&&((*p_org != '(')||(in_quote==1)))
        {
            switch (*p_org) {
                case '"':
                    in_quote ^= 1;
                    break;
                case '\n':
                case '\r':
                    in_quote = 0;
                    break;
                case '\0':
                    p_org = NULL;
                    break;
            }

            if (p_org) p_org++;
        }

        p = p_org;

        if ((p != NULL)&&(in_quote == 0))
        {
            int stop_searching = 0;

            DMIMEH LOGGER_log("%s:%d:MIMEH_strip_comments:DEBUG: Located open ( at %s",FL,p);
            // If we did locate an opening parenthesis, look for the closing one
            //      NOTE - we cannot have a breaking \n or \r inbetween
            //      q = strpbrk(p, ")\n\r");
            q = p;
            while ( (q != NULL) && (stop_searching == 0) )
            {
                switch (*q) {
                    case '\0':
                        stop_searching = 1;
                        q = NULL;
                        break;

                    case '\n':
                    case '\r':
                        stop_searching = 1;
                        in_quote = 0;
                        break;

                    case '"':
                        in_quote ^= 1;
                        break;

                    case ')':
                        DMIMEH LOGGER_log("%s:%d:MIMEH_strip_comments:DEBUG: Located closing ) at %s",FL,q);
                        if (in_quote == 0) stop_searching = 1;
                        break;
                }
                if ((q != NULL)&&(stop_searching == 0)) q++;
            }

            // If we've got both opening and closing, then we need to remove
            //      the contents of the comment, including the parenthesis
            if (q != NULL)
            {
                if (*q != ')')
                {
                    // if we found a \n or \r between the two (), then jump out
                    // and move p to the next position.
                    p_org++;
                    continue;
                } else {
                    // Move q to the first char after the closing parenthesis
                    q++;

                    DMIMEH LOGGER_log("%s:%d:MIMEH_strip_comments:DEBUG: located closing ) at %s ",FL, q);
                    // While there's more chars in string, copy them to where
                    //      the opening parenthesis is
                    while (*q != '\0')
                    {
                        *p = *q;
                        p++;
                        q++;
                    } // While q != '\0'
                    DMIMEH LOGGER_log("%s:%d:MIMEH_strip_comments:DEBUG: char copy done",FL);

                    // Terminate the string
                    *p = '\0';
                } // if q !=/= ')'

            } else break; // if q == NULL
        } // if p == NULL
    } while ((p != NULL)&&(p_org != NULL)); // do-while more comments to remove

    DMIMEH LOGGER_log("%s:%d:MIMEH_strip_comments:DEBUG: Final string = '%s'",FL,input);
    return 0;
}

// Assembly:
testq %rdi, %rdi
je 0x8276
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
leaq 0xc411(%rip), %r12      # 0x1446a
leaq 0xc27e(%rip), %rsi      # 0x142de
pushq $0x1
popq %r8
leaq 0xc470(%rip), %r9       # 0x144db
leaq 0xc4a4(%rip), %r10      # 0x14516
movq %rdi, %rbx
xorl %ebp, %ebp
movq %rbx, %rcx
testq %rcx, %rcx
je 0x8242
movq %rcx, %rbx
cmpl $0x1, %ebp
sete %cl
movzbl (%rbx), %eax
cmpl $0x28, %eax
setne %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x80c0
movl $0x0, %ecx
testl %eax, %eax
je 0x807a
cmpl $0xa, %eax
je 0x80b9
cmpl $0xd, %eax
je 0x80b9
cmpl $0x22, %eax
jne 0x80bb
xorl $0x1, %ebp
jmp 0x80bb
xorl %ebp, %ebp
incq %rbx
jmp 0x8077
testl %ebp, %ebp
jne 0x8077
cmpl $0x0, 0x232c1(%rip)     # 0x2b38c
jle 0x80f7
movq %r12, %rdi
movq %rsi, %r15
movl $0x35b, %edx            # imm = 0x35B
movq %rbx, %rcx
xorl %eax, %eax
movl %r8d, %ebp
movq %r9, %r12
movq %r10, %r13
callq 0xc2a1
movq %r13, %r10
movq %r12, %r9
movl %ebp, %r8d
movq %r15, %rsi
xorl %ebp, %ebp
movq %rbx, %r13
xorl %r12d, %r12d
testq %r13, %r13
je 0x81a2
testl %r12d, %r12d
jne 0x81a2
movzbl (%r13), %eax
xorl %r12d, %r12d
movb $0x1, %r15b
cmpl $0x29, %eax
je 0x813e
cmpl $0xa, %eax
je 0x8186
cmpl $0xd, %eax
je 0x8186
cmpl $0x22, %eax
je 0x8139
testl %eax, %eax
jne 0x818e
xorl %r13d, %r13d
jmp 0x8188
xorl $0x1, %ebp
jmp 0x818e
cmpl $0x0, 0x23247(%rip)     # 0x2b38c
jle 0x817d
leaq 0xc353(%rip), %rdi      # 0x144a1
leaq 0xc189(%rip), %rsi      # 0x142de
movl $0x373, %edx            # imm = 0x373
movq %r13, %rcx
xorl %eax, %eax
callq 0xc2a1
leaq 0xc3ab(%rip), %r10      # 0x14516
leaq 0xc369(%rip), %r9       # 0x144db
pushq $0x1
popq %r8
leaq 0xc161(%rip), %rsi      # 0x142de
testl %ebp, %ebp
je 0x8186
movl %r8d, %ebp
jmp 0x818e
xorl %ebp, %ebp
xorl %r15d, %r15d
movl %r8d, %r12d
testq %r13, %r13
setne %al
andb %r15b, %al
movzbl %al, %eax
addq %rax, %r13
jmp 0x80ff
testq %r13, %r13
leaq 0xc2be(%rip), %r12      # 0x1446a
je 0x8242
cmpb $0x29, (%r13)
jne 0x80bb
incq %r13
cmpl $0x0, 0x231c5(%rip)     # 0x2b38c
jle 0x81f3
movq %r9, %rdi
movq %rsi, %r15
movl $0x388, %edx            # imm = 0x388
movq %r13, %rcx
xorl %eax, %eax
callq 0xc2a1
leaq 0xc331(%rip), %r10      # 0x14516
leaq 0xc2ef(%rip), %r9       # 0x144db
pushq $0x1
popq %r8
movq %r15, %rsi
xorl %r15d, %r15d
movb (%r13,%r15), %al
testb %al, %al
je 0x8208
movb %al, (%rbx,%r15)
incq %r15
jmp 0x81f6
cmpl $0x0, 0x2317d(%rip)     # 0x2b38c
jle 0x8238
movq %r10, %rdi
movq %rsi, %r13
movl $0x391, %edx            # imm = 0x391
xorl %eax, %eax
callq 0xc2a1
leaq 0xc2ec(%rip), %r10      # 0x14516
leaq 0xc2aa(%rip), %r9       # 0x144db
pushq $0x1
popq %r8
movq %r13, %rsi
movb $0x0, (%rbx,%r15)
jmp 0x8077
cmpl $0x0, 0x23143(%rip)     # 0x2b38c
jle 0x8268
leaq 0xc2f5(%rip), %rdi      # 0x14547
leaq 0xc085(%rip), %rsi      # 0x142de
movl $0x39b, %edx            # imm = 0x39B
movq %r14, %rcx
xorl %eax, %eax
callq 0xc2a1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq