// File: /workspace/github_c_makefile_star2_O3/System-Glitch[P]ESGILinter-C/src/stringutils.c
// Function: str_remove_comments
char *str_remove_comments(char *str) {
	char *result            = NULL;
	char *tmp               = NULL;
	int comment_start       = -1;
	int comment_end         = -1;
	unsigned char in_quotes = 0;
	unsigned char type      = 0;
	size_t length = strlen(str);

	for(unsigned i = 0 ; i < length ; i++) {
		if(!in_quotes && str[i] == '\"') {
			in_quotes = 1;
		} else if(in_quotes) {
			if(str[i] == '\"' && str[i-1] != '\\')
				in_quotes = 0;
		} else {
			if(comment_start == -1) {
				if(str[i] == '/' && str[i+1] == '*') {
					type = COMMENT_TYPE_MULTILINE;
					comment_start = i;
					i++;
				} else if(str[i] == '/' && str[i+1] == '/') {
					type = COMMENT_TYPE_ENDLINE;
					comment_start = i;
					i++;
				}
			} else {
				if(type == COMMENT_TYPE_MULTILINE && str[i] == '*' && str[i+1] == '/') {
					comment_end = i + 2;
					break;
				} else if(type == COMMENT_TYPE_ENDLINE && is_line_break(str[i])) {
					comment_end = i;
					break;
				}
			}
		}
	}

	if(type == COMMENT_TYPE_ENDLINE && comment_end == -1)
		comment_end = length;

	if(comment_start != -1 && comment_end != -1) {
		result = malloc((length + 1) * sizeof(char));
		strncpy(result, str, comment_start);
		strncpy(result + comment_start, str + comment_end, length - comment_end);
		result[comment_start + (length - comment_end)] = '\0';
		tmp = str_remove_comments(result);
		free(result);
		result = tmp;
	} else {
		result = strduplicate(str);
	}

	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x20b0
testq %rax, %rax
je 0x7d90
movq %rax, %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movzbl (%rbx,%rax), %esi
testb %dl, %dl
je 0x7c99
movb $0x1, %dl
cmpl $0x22, %esi
jne 0x7cf6
leal -0x1(%rax), %edx
cmpb $0x5c, (%rbx,%rdx)
sete %dl
jmp 0x7cf6
movb $0x1, %dl
cmpl $0x22, %esi
je 0x7cf6
cmpl $-0x1, %ebp
je 0x7cc7
cmpb $0x2, %cl
je 0x7ce8
movzbl %cl, %edx
cmpl $0x1, %edx
jne 0x7cf4
movb $0x1, %cl
cmpl $0x2a, %esi
jne 0x7cf4
leal 0x1(%rax), %edx
cmpb $0x2f, (%rbx,%rdx)
jne 0x7cf4
jmp 0x7da6
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2f, %esi
jne 0x7cf4
leal 0x1(%rax), %esi
movzbl (%rbx,%rsi), %edx
cmpl $0x2a, %edx
je 0x7cff
cmpl $0x2f, %edx
jne 0x7cf4
movb $0x2, %cl
xorl %edx, %edx
jmp 0x7d03
movb $0x2, %cl
cmpl $0xa, %esi
je 0x7d0e
cmpl $0xd, %esi
je 0x7d0e
xorl %edx, %edx
incl %eax
cmpq %rax, %r14
ja 0x7c7e
jmp 0x7d09
xorl %edx, %edx
movb $0x1, %cl
movl %eax, %ebp
movl %esi, %eax
jmp 0x7cf6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpb $0x2, %cl
sete %cl
cmpl $-0x1, %eax
movl %r14d, %r13d
cmovnel %eax, %r13d
testb %cl, %cl
cmovel %eax, %r13d
cmpl $-0x1, %ebp
je 0x7d90
cmpl $-0x1, %r13d
je 0x7d90
leaq 0x1(%r14), %rdi
callq 0x2140
movq %rax, %r15
movslq %ebp, %r12
movq %rax, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2060
addq %r15, %r12
movslq %r13d, %rax
addq %rax, %rbx
subq %rax, %r14
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2060
movb $0x0, (%r14,%r12)
movq %r15, %rdi
callq 0x7c54
movq %rax, %rbx
movq %r15, %rdi
callq 0x2030
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7dc1
addl $0x2, %eax
xorl %ecx, %ecx
jmp 0x7d14