// File: /workspace/github_c_makefile_star2_O2/System-Glitch[P]ESGILinter-C/src/rules/no_multi_declaration.c
// Function: check_no_multi_declaration
unsigned int check_no_multi_declaration(scope_t *root_scope, arraylist_t *file, arraylist_t *real_file) {
	node_t  *current  = NULL;
	line_t  *line     = NULL;
	field_t *variable = NULL;
	int     *tmp      = NULL;
	char    *display  = NULL;
	unsigned int breaks  = 0;
	arraylist_t *lines   = arraylist_init(root_scope->variables->size);
	arraylist_t *ignores = arraylist_init(root_scope->variables->size);
	unsigned int count   = 0; //Counts warnings and errors

	for(size_t i = 0 ; i < root_scope->variables->size ; i++) {
		variable = (field_t*)arraylist_get(root_scope->variables, i);
		if(!(variable->is_param) && !list_contains(ignores, variable->line)) {
			if(!list_contains(lines, variable->line)) {
				tmp = malloc(sizeof(int));
				*tmp = variable->line;
				arraylist_add(lines, tmp);
			} else {
				line = get_line(file, variable->line);
				breaks = strcount_heading_line_breaks(line->line) + (line->start_real_line == 0 ? 1 : 0);
				display = trim(arraylist_get(real_file, line->start_real_line + breaks - 1));
				print_warning(line->source, line->start_real_line + breaks, display, "Variable multiple declaration");
				free(display);
				tmp = malloc(sizeof(int));
				*tmp = variable->line;
				arraylist_add(ignores, tmp);
				count++;
			}
		}
	}

	arraylist_free(lines, 1);
	arraylist_free(ignores, 1);

	current = root_scope->children->head;
	while (current != NULL) {
		count += check_no_multi_declaration((scope_t*)current->val, file, real_file);
		current = current->next;
	}

	return count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x18(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movl 0x8(%rax), %edi
callq 0x67e4
movq %rax, %r12
movq 0x18(%rbx), %rax
movl 0x8(%rax), %edi
callq 0x67e4
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %r14, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
movq %r12, 0x20(%rsp)
movq 0x18(%rbx), %rdi
cmpq 0x8(%rdi), %r13
jae 0x8f6f
movq %r13, %rsi
callq 0x6978
cmpb $0x0, 0x24(%rax)
jne 0x8f67
movq %rax, %rbp
movl 0x20(%rax), %esi
movq 0x8(%rsp), %rdi
callq 0x8fbc
testb %al, %al
jne 0x8f67
movl 0x20(%rbp), %esi
movq %r12, %rdi
callq 0x8fbc
testb %al, %al
je 0x8f4f
movl 0x20(%rbp), %esi
movq %r14, %rdi
callq 0x2a1e
movq %rax, %rbx
movq (%rax), %rdi
callq 0x7af0
movl %eax, %r14d
movl 0x10(%rbx), %eax
movl %eax, 0x14(%rsp)
movl %eax, %esi
subl $0x1, %esi
adcl %r14d, %esi
movq 0x18(%rsp), %rdi
callq 0x6978
movq %rax, %rdi
callq 0x7daf
movq %rax, %r12
cmpl $0x1, 0x14(%rsp)
movq 0x8(%rbx), %rdi
adcl 0x10(%rbx), %r14d
movq 0x28(%rsp), %rbx
movl %r14d, %esi
movq 0x30(%rsp), %r14
movq %rax, %rdx
leaq 0x5a9d(%rip), %rcx      # 0xe9bb
callq 0x560c
movq %r12, %rdi
callq 0x2030
pushq $0x4
popq %rdi
callq 0x2130
movl 0x20(%rbp), %ecx
movl %ecx, (%rax)
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x68b5
incl %r15d
movq 0x20(%rsp), %r12
jmp 0x8f67
pushq $0x4
popq %rdi
callq 0x2130
movl 0x20(%rbp), %ecx
movl %ecx, (%rax)
movq %r12, %rdi
movq %rax, %rsi
callq 0x68b5
incq %r13
jmp 0x8e72
pushq $0x1
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
callq 0x69f4
movq 0x8(%rsp), %rdi
movl %ebp, %esi
callq 0x69f4
movq 0x8(%rbx), %rbx
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
je 0x8faa
movq (%rbx), %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
callq 0x8e24
addl %eax, %r15d
jmp 0x8f8c
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq