// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
movq 0x10(%rdi), %r12
cmpq $0x0, 0x8(%r12)
je 0x9cf3
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0x6d0c
cmpb $0x0, 0x18(%rax)
jne 0x9ce3
movq %rax, %rbx
movq (%rax), %r14
movq %r14, %rdi
leaq 0x4e73(%rip), %rsi      # 0xea02
callq 0x2120
testl %eax, %eax
je 0x9ce3
movl %ebp, 0xc(%rsp)
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x6ac5
testq %rax, %rax
je 0x9c7d
movq %rax, %r14
movq 0x8(%rbx), %rdi
movq 0x8(%rax), %rsi
callq 0x2120
testl %eax, %eax
jne 0x9c22
movq 0x20(%rbx), %rdi
movq 0x8(%rdi), %rax
movq 0x20(%r14), %rcx
cmpq 0x8(%rcx), %rax
jne 0x9c22
testq %rax, %rax
je 0x9c19
xorl %r15d, %r15d
movq %r15, %rsi
callq 0x6d0c
leaq 0x10(%rax), %rbp
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x6d0c
leaq 0x10(%rax), %rsi
movq %rbp, %rdi
callq 0x686e
testb %al, %al
je 0x9c22
incq %r15
movq 0x20(%rbx), %rdi
cmpq 0x8(%rdi), %r15
jb 0x9be4
movl 0xc(%rsp), %ebp
jmp 0x9ce3
movl 0x28(%r14), %esi
movq 0x10(%rsp), %rdi
callq 0x2a78
movq %rax, %r14
movq (%rax), %rdi
callq 0x7f5c
movl %eax, %ebp
movl 0x10(%r14), %r15d
movl %r15d, %esi
subl $0x1, %esi
adcl %eax, %esi
movq 0x18(%rsp), %rdi
callq 0x6d0c
movq %rax, %rdi
callq 0x8239
movq %rax, %rbx
cmpl $0x1, %r15d
movq 0x8(%r14), %rdi
adcl 0x10(%r14), %ebp
movl %ebp, %esi
movq %rax, %rdx
leaq 0x4d91(%rip), %rcx      # 0xea07
callq 0x58dd
jmp 0x9cd5
movl 0x28(%rbx), %esi
movq 0x10(%rsp), %rdi
callq 0x2a78
movq %rax, %r14
movq (%rax), %rdi
callq 0x7f5c
movl %eax, %ebp
movl 0x10(%r14), %r15d
movl %r15d, %esi
subl $0x1, %esi
adcl %eax, %esi
movq 0x18(%rsp), %rdi
callq 0x6d0c
movq %rax, %rdi
callq 0x8239
movq %rax, %rbx
cmpl $0x1, %r15d
movq 0x8(%r14), %rdi
adcl 0x10(%r14), %ebp
movl %ebp, %esi
movq %rax, %rdx
leaq 0x4d49(%rip), %rcx      # 0xea19
callq 0x585c
movq %rbx, %rdi
callq 0x2030
movl 0xc(%rsp), %ebp
incl %ebp
incq %r13
cmpq 0x8(%r12), %r13
jb 0x9b6a
jmp 0x9cf5
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop