// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movl 0x8(%rax), %edi
callq 0x6b58
movq %rax, %r14
movq 0x18(%rbx), %rax
movl 0x8(%rax), %edi
callq 0x6b58
movq %rax, %r15
movq 0x18(%rbx), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x9593
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbx, 0x30(%rsp)
movq %r14, 0x28(%rsp)
movq %r15, 0x20(%rsp)
movq %r12, %rsi
callq 0x6d0c
cmpb $0x0, 0x24(%rax)
jne 0x9580
movq %rax, %r13
movl 0x20(%rax), %esi
movq %r15, %rdi
callq 0x95f0
testb %al, %al
jne 0x9580
movl 0x20(%r13), %esi
movq %r14, %rdi
callq 0x95f0
testb %al, %al
je 0x9565
movl 0x20(%r13), %esi
movq 0x10(%rsp), %rdi
callq 0x2a78
movq %rax, %rbx
movq (%rax), %rdi
callq 0x7f5c
movl %eax, %r14d
movl 0x10(%rbx), %eax
movl %eax, 0xc(%rsp)
movl %eax, %esi
subl $0x1, %esi
adcl %r14d, %esi
movq 0x18(%rsp), %rdi
callq 0x6d0c
movq %rax, %rdi
callq 0x8239
movq %rax, %r15
cmpl $0x1, 0xc(%rsp)
movq 0x8(%rbx), %rdi
adcl 0x10(%rbx), %r14d
movq 0x30(%rsp), %rbx
movl %r14d, %esi
movq 0x28(%rsp), %r14
movq %rax, %rdx
leaq 0x5487(%rip), %rcx      # 0xe9bb
callq 0x585c
movq %r15, %rdi
movq 0x20(%rsp), %r15
callq 0x2030
movl $0x4, %edi
callq 0x2140
movl 0x20(%r13), %ecx
movl %ecx, (%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0x6c26
incl %ebp
jmp 0x9580
movl $0x4, %edi
callq 0x2140
movl 0x20(%r13), %ecx
movl %ecx, (%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x6c26
incq %r12
movq 0x18(%rbx), %rdi
cmpq 0x8(%rdi), %r12
jb 0x9494
jmp 0x9595
xorl %ebp, %ebp
movq %r14, %rdi
movl $0x1, %esi
callq 0x6d97
movq %r15, %rdi
movl $0x1, %esi
callq 0x6d97
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rbx
testq %rbx, %rbx
je 0x95df
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r15
movq (%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x9438
addl %eax, %ebp
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
jne 0x95c6
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq