// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movl %eax, %edi
callq 0x8580
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movl %eax, %edi
callq 0x8580
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jae 0xcd62
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x68(%rbp), %rsi
callq 0x8890
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpb $0x0, 0x24(%rax)
jne 0xcd4f
movq -0x58(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x20(%rax), %esi
callq 0xcdd0
cmpb $0x0, %al
jne 0xcd4f
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x20(%rax), %esi
callq 0xcdd0
cmpb $0x0, %al
jne 0xcc92
movl $0x4, %edi
callq 0x2110
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x8730
jmp 0xcd4d
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x20(%rax), %esi
callq 0x2cb0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
callq 0xa840
movq -0x28(%rbp), %rcx
movl 0x10(%rcx), %esi
xorl %ecx, %ecx
movl $0x1, %edx
cmpl $0x0, %esi
cmovel %edx, %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
addl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x8890
movq %rax, %rdi
callq 0xad00
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %esi
addl -0x44(%rbp), %esi
movq -0x40(%rbp), %rdx
leaq 0x7c9f(%rip), %rcx      # 0x149ad
callq 0x6850
movq -0x40(%rbp), %rdi
callq 0x2030
movl $0x4, %edi
callq 0x2110
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x58(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x8730
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xcd4f
jmp 0xcd51
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0xcc00
movq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x8a00
movq -0x58(%rbp), %rdi
movl $0x1, %esi
callq 0x8a00
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xcdbd
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xcb80
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0xcd8e
movl -0x5c(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)