// File: /workspace/github_c_makefile_star2_O1/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 0x9bb9
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0x6c76
cmpb $0x0, 0x18(%rax)
jne 0x9ba9
movq %rax, %rbx
movq (%rax), %r14
movq %r14, %rdi
leaq 0x4fff(%rip), %rsi      # 0xea12
callq 0x2120
testl %eax, %eax
je 0x9ba9
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x6a36
testq %rax, %rax
movl %ebp, 0xc(%rsp)
je 0x9b43
movq %rax, %r14
movq 0x8(%rbx), %rdi
movq 0x8(%rax), %rsi
callq 0x2120
testl %eax, %eax
jne 0x9ae8
movq 0x20(%rbx), %rdi
movq 0x8(%rdi), %rax
movq 0x20(%r14), %rcx
cmpq 0x8(%rcx), %rax
jne 0x9ae8
testq %rax, %rax
sete 0xb(%rsp)
je 0x9ad8
xorl %esi, %esi
callq 0x6c76
leaq 0x10(%rax), %r15
movq 0x20(%r14), %rdi
xorl %esi, %esi
callq 0x6c76
leaq 0x10(%rax), %rsi
movq %r15, %rdi
callq 0x67b4
testb %al, %al
je 0x9ad8
movl $0x1, %r15d
movq 0x20(%rbx), %rdi
cmpq 0x8(%rdi), %r15
setae 0xb(%rsp)
jae 0x9ad8
movq %r15, %rsi
callq 0x6c76
leaq 0x10(%rax), %rbp
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x6c76
leaq 0x10(%rax), %rsi
movq %rbp, %rdi
callq 0x67b4
incq %r15
testb %al, %al
jne 0x9a9e
cmpb $0x0, 0xb(%rsp)
je 0x9ae8
movl 0xc(%rsp), %ebp
jmp 0x9ba9
movl 0x28(%r14), %esi
movq 0x10(%rsp), %rdi
callq 0x2a74
movq %rax, %r14
movq (%rax), %rdi
callq 0x7ef3
movl %eax, %ebp
movl 0x10(%r14), %r15d
movl %r15d, %esi
subl $0x1, %esi
adcl %eax, %esi
movq 0x18(%rsp), %rdi
callq 0x6c76
movq %rax, %rdi
callq 0x81dc
movq %rax, %rbx
cmpl $0x1, %r15d
movq 0x8(%r14), %rdi
adcl 0x10(%r14), %ebp
movl %ebp, %esi
movq %rax, %rdx
leaq 0x4edb(%rip), %rcx      # 0xea17
callq 0x5829
jmp 0x9b9b
movl 0x28(%rbx), %esi
movq 0x10(%rsp), %rdi
callq 0x2a74
movq %rax, %r14
movq (%rax), %rdi
callq 0x7ef3
movl %eax, %ebp
movl 0x10(%r14), %r15d
movl %r15d, %esi
subl $0x1, %esi
adcl %eax, %esi
movq 0x18(%rsp), %rdi
callq 0x6c76
movq %rax, %rdi
callq 0x81dc
movq %rax, %rbx
cmpl $0x1, %r15d
movq 0x8(%r14), %rdi
adcl 0x10(%r14), %ebp
movl %ebp, %esi
movq %rax, %rdx
leaq 0x4e93(%rip), %rcx      # 0xea29
callq 0x57a8
movq %rbx, %rdi
callq 0x2030
movl 0xc(%rsp), %ebp
incl %ebp
incq %r13
cmpq 0x8(%r12), %r13
jb 0x99ee
jmp 0x9bbb
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq