// File: /workspace/github_c_makefile_star2_O2/System-Glitch[P]ESGILinter-C/src/rules/no_prototype.c
// Function: check_no_prototype
unsigned int check_no_prototype(scope_t *root_scope, arraylist_t *file, arraylist_t *real_file) {

	arraylist_t *functions = root_scope->functions;
	function_t  *function  = NULL;
	function_t  *prototype = NULL;
	line_t      *line      = NULL;
	char        *display   = NULL;
	unsigned int breaks    = 0;
	unsigned int count     = 0; //Counts warnings and errors

	for(size_t i = 0 ; i < functions->size ; i++) {
		breaks = 0;
		function = arraylist_get(functions, i);
		if(!function->is_prototype && strcmp(function->name, "main")) {

			prototype = find_function_prototype(root_scope, function->name);
			if(prototype != NULL) {
				if(strcmp(function->return_type.name, prototype->return_type.name) || !check_params(function, prototype)) {
					line = get_line(file, prototype->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_error(line->source, line->start_real_line + breaks, display, "Conflicting types");
					free(display);
					count++;
				}
			} else {
				line = get_line(file, function->line);
				breaks = strcount_heading_line_breaks(line->line) + (line->start_real_line == 0 ? 1 : 0); //TODO count until not whitespace instead of all breaks
				display = trim(arraylist_get(real_file, line->start_real_line + breaks - 1));
				print_warning(line->source, line->start_real_line + breaks, display, "Missing prototype");
				free(display);
				count++;
			}
		}
	}

	return count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, 0x20(%rsp)
movq 0x10(%rdi), %r13
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq 0x8(%r13), %rbp
jae 0x969d
movq %r13, %rdi
movq %rbp, %rsi
callq 0x6978
cmpb $0x0, 0x18(%rax)
jne 0x968e
movq %rax, %rbx
movq (%rax), %r14
movq %r14, %rdi
leaq 0x54c5(%rip), %rsi      # 0xea02
callq 0x2110
testl %eax, %eax
je 0x968e
movq %r15, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x6754
testq %rax, %rax
je 0x9624
movq %rax, %r14
movq 0x8(%rbx), %rdi
movq 0x8(%rax), %rsi
callq 0x2110
testl %eax, %eax
jne 0x95c7
movq 0x20(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x20(%r14), %rcx
cmpq 0x8(%rcx), %rax
jne 0x95c7
xorl %r15d, %r15d
movq 0x20(%rbx), %rdi
cmpq 0x8(%rdi), %r15
jae 0x9696
movq %r15, %rsi
callq 0x6978
leaq 0x10(%rax), %r12
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x6978
leaq 0x10(%rax), %rsi
movq %r12, %rdi
callq 0x652a
incq %r15
testb %al, %al
jne 0x958e
movl 0x28(%r14), %esi
movq 0x8(%rsp), %rdi
callq 0x2a1e
movq %rax, %r14
movq (%rax), %rdi
callq 0x7af0
movl %eax, %r15d
movl 0x10(%r14), %r12d
movl %r12d, %esi
subl $0x1, %esi
adcl %eax, %esi
movq 0x10(%rsp), %rdi
callq 0x6978
movq %rax, %rdi
callq 0x7daf
movq %rax, %rbx
cmpl $0x1, %r12d
movq 0x8(%r14), %rdi
adcl 0x10(%r14), %r15d
movl %r15d, %esi
movq %rax, %rdx
leaq 0x53ea(%rip), %rcx      # 0xea07
callq 0x568d
jmp 0x967e
movl 0x28(%rbx), %esi
movq 0x8(%rsp), %rdi
callq 0x2a1e
movq %rax, %r14
movq (%rax), %rdi
callq 0x7af0
movl %eax, %r15d
movl 0x10(%r14), %r12d
movl %r12d, %esi
subl $0x1, %esi
adcl %eax, %esi
movq 0x10(%rsp), %rdi
callq 0x6978
movq %rax, %rdi
callq 0x7daf
movq %rax, %rbx
cmpl $0x1, %r12d
movq 0x8(%r14), %rdi
adcl 0x10(%r14), %r15d
movl %r15d, %esi
movq %rax, %rdx
leaq 0x53a0(%rip), %rcx      # 0xea19
callq 0x560c
movq %rbx, %rdi
callq 0x2030
movq 0x18(%rsp), %r15
incl %r15d
incq %rbp
jmp 0x950e
movq 0x18(%rsp), %r15
jmp 0x968e
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop