// File: /workspace/github_c_makefile_star2_O1/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 0x6ac8
movq %rax, %r14
movq 0x18(%rbx), %rax
movl 0x8(%rax), %edi
callq 0x6ac8
movq %rax, %r15
movq 0x18(%rbx), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x9407
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbx, 0x30(%rsp)
movq %r14, 0x28(%rsp)
movq %r15, 0x20(%rsp)
movq %r12, %rsi
callq 0x6c76
cmpb $0x0, 0x24(%rax)
jne 0x93f4
movq %rax, %r13
movl 0x20(%rax), %esi
movq %r15, %rdi
callq 0x9464
testb %al, %al
jne 0x93f4
movl 0x20(%r13), %esi
movq %r14, %rdi
callq 0x9464
testb %al, %al
je 0x93d9
movl 0x20(%r13), %esi
movq 0x10(%rsp), %rdi
callq 0x2a74
movq %rax, %rbx
movq (%rax), %rdi
callq 0x7ef3
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 0x6c76
movq %rax, %rdi
callq 0x81dc
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 0x5623(%rip), %rcx      # 0xe9cb
callq 0x57a8
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 0x6b96
incl %ebp
jmp 0x93f4
movl $0x4, %edi
callq 0x2140
movl 0x20(%r13), %ecx
movl %ecx, (%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x6b96
incq %r12
movq 0x18(%rbx), %rdi
cmpq 0x8(%rdi), %r12
jb 0x9308
jmp 0x9409
xorl %ebp, %ebp
movq %r14, %rdi
movl $0x1, %esi
callq 0x6d0a
movq %r15, %rdi
movl $0x1, %esi
callq 0x6d0a
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rbx
testq %rbx, %rbx
je 0x9453
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r15
movq (%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x92ac
addl %eax, %ebp
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
jne 0x943a
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq