// File: /workspace/github_c_makefile_star2_O0/System-Glitch[P]ESGILinter-C/src/scopetree.c
// Function: parse_scope
scope_t *parse_scope(arraylist_t *file, unsigned int start_line, unsigned int from_char, scope_t *parent_scope) {
	scope_t *scope              = scope_init(parent_scope);
	scope_t *child              = NULL;
	unsigned int level          = 0;
	unsigned int no_scope_level = 0;
	char found                  = 0;
	unsigned int length;
	char *line;

	for(size_t i = start_line ; i < file->size ; i++) { //Already considers end of line as bracket
		line   = str_remove_comments(arraylist_get(file, i));
		length = strlen(line);
		for(size_t j = i == start_line ? from_char : 0 ; j < length ; j++) {

			if(!check_quotes(line, line + j, length)) {

				if(line[j] == '{') {

					if(previous_char_is_equal(line, j)) {
						no_scope_level++;
					} else {
						level++;

						if(!found) {
							scope->from_line = i;
							scope->from_char = j;
						}

						found = 1;

						if(level == 2) {
							child = parse_scope(file, i, j, scope);
							if(child != NULL)
								linkedlist_add(scope->children, child);
						}
					}
				} else if(line[j] == '}') {
					if(no_scope_level != 0) {
						no_scope_level--;
					} else {
						level--;

						if(found && level == 0) {
							scope->to_line = i;
							scope->to_char = j + 1;
							break;
						}
					}
				}
			}
		}

		free(line);
		if(scope->to_line != -1) break;
	}

	if(scope->to_line == -1) {
		scope_free(scope);
		scope = NULL;
	} else {
		parse_scope_content(file, scope);
	}

	return scope;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x7680
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movb $0x0, -0x31(%rbp)
movl -0xc(%rbp), %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x7c09
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x8890
movq %rax, %rdi
callq 0xa2b0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2090
movl %eax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movl -0xc(%rbp), %ecx
cmpq %rcx, %rax
jne 0x7a8f
movl -0x10(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x7a96
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0x7a96
movl -0x54(%rbp), %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl -0x38(%rbp), %ecx
cmpq %rcx, %rax
jae 0x7be1
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq -0x50(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0xae60
cmpb $0x0, %al
jne 0x7bce
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7b, %eax
jne 0x7b6c
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %esi
callq 0x7f30
cmpb $0x0, %al
je 0x7afe
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x7b6a
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpb $0x0, -0x31(%rbp)
jne 0x7b27
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x50(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x24(%rax)
movb $0x1, -0x31(%rbp)
cmpl $0x2, -0x2c(%rbp)
jne 0x7b68
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %esi
movq -0x50(%rbp), %rax
movl %eax, %edx
movq -0x20(%rbp), %rcx
callq 0x7a00
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x7b66
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0xc1a0
jmp 0x7b68
jmp 0x7b6a
jmp 0x7bcc
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7d, %eax
jne 0x7bca
cmpl $0x0, -0x30(%rbp)
je 0x7b8e
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x7bc8
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
movsbl -0x31(%rbp), %eax
cmpl $0x0, %eax
je 0x7bc6
cmpl $0x0, -0x2c(%rbp)
jne 0x7bc6
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x2c(%rax)
jmp 0x7be1
jmp 0x7bc8
jmp 0x7bca
jmp 0x7bcc
jmp 0x7bce
jmp 0x7bd0
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x7a9f
movq -0x40(%rbp), %rdi
callq 0x2030
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x28(%rax)
je 0x7bf6
jmp 0x7c09
jmp 0x7bf8
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x7a44
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x28(%rax)
jne 0x7c26
movq -0x20(%rbp), %rdi
callq 0x7fa0
movq $0x0, -0x20(%rbp)
jmp 0x7c33
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x7c40
movq -0x20(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)