// File: /workspace/github_c_makefile_star2_O2/System-Glitch[P]ESGILinter-C/src/parsing_variables.c
// Function: get_variables_from_declaration
arraylist_t *get_variables_from_declaration(int line_index, char *line) {
	unsigned int star_count_type;
	unsigned int type_sub_index;
	unsigned int length;
	unsigned int type_length;
	unsigned int names_index      = 0;
	unsigned int type_start_index = 0;
	int          start_index      = 0;
	int          tmp_index        = 0;
	arraylist_t *list   = NULL;
	field_t *variable   = NULL;
	match_t *for_loop   = NULL;
	match_t *match_type = NULL;
	char *tmp_type      = NULL;
	char *tmp_line      = NULL;
	char *tmp_names;
	char *type;

	tmp_line = str_remove_comments(line);
	length = strlen(tmp_line);
	while(tmp_index != -1) {
		start_index = tmp_index;
		tmp_index = skip_switch_case(line, start_index, length);
	}

	if(start_index != -1) {
		line = strsubstr(tmp_line, start_index, length - start_index);
		free(tmp_line);
		tmp_line = line;
	}

	for_loop = match_for_loop(tmp_line);
	if(for_loop != NULL) {
		line = substr_match(tmp_line, *for_loop);
		free(tmp_line);
		free(for_loop);
	} else {
		line = tmp_line;
	}

	match_type = parse_type(line);
	if(match_type == NULL) {
		free(line);
		return NULL;
	}

	type = substr_match(line, *match_type);
	type_start_index = match_type->index_start;
	free(match_type);

	if(type != NULL) {

		type_length = strlen(type);
		tmp_names   = strsubstr(line, type_start_index + type_length, strlen(line) - type_length);
		length      = strlen(tmp_names);

		if(length > 0) {
			list            = arraylist_init(5);
			star_count_type = strcount(type, '*');
			type_sub_index  = strcountuntil(type, '*', 1, 1);

			//Remove stars
			type[type_length - type_sub_index] = '\0';

			if(strcount(type, '*')) { //Contains stars inside the type name -> invalid type
				free(tmp_names);
				free(type);
				arraylist_free(list, 1);
				free(line);
				return NULL;
			} else if(!strcmp(type, "unsigned")) {
				tmp_type = strconcat(type, " int");
				free(type);
				type = tmp_type;
			}

			do {
				variable = get_variable_from_declaration(line_index, type, star_count_type, tmp_names, &names_index);
				if(variable != NULL)
					arraylist_add(list, variable);
			} while(variable != NULL && names_index < length);

			if(list->size == 0) {
				arraylist_free(list, 1);
				list = NULL;
			}
		}

		free(type);
		free(tmp_names);
	}

	free(line);

	return list;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movl %edi, 0x24(%rsp)
andl $0x0, (%rsp)
movq %rsi, %rdi
callq 0x77dc
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x20b0
movq %rax, 0x30(%rsp)
movslq %eax, %rbp
leaq -0x1(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %esi, %esi
xorl %ecx, %ecx
cmpl $-0x1, %ecx
je 0x84cb
movl %ecx, 0x18(%rsp)
movslq %ecx, %r13
movq 0x10(%rsp), %rax
leaq (%rax,%r13), %r15
movq %r13, %r12
movb 0x1(%r15), %bl
incq %r15
movsbl %bl, %edi
callq 0x7ace
incq %r13
cmpq %rbp, %r12
jge 0x8440
testb %al, %al
jne 0x8422
movq %r15, %rdi
leaq 0x6362(%rip), %rsi      # 0xe7ac
pushq $0x4
popq %rdx
callq 0x2070
testl %eax, %eax
movl 0x18(%rsp), %r12d
je 0x8477
movq %r15, %rdi
leaq 0x635b(%rip), %rsi      # 0xe7c0
pushq $0x7
popq %rdx
callq 0x2070
movl %r12d, %esi
pushq $-0x1
popq %rcx
testl %eax, %eax
jne 0x8409
xorl %eax, %eax
cmpb $0x63, %bl
setne %al
leal (%rax,%rax,2), %eax
addl %r13d, %eax
addl $0x3, %eax
movslq %eax, %rcx
movq %rcx, %rbx
movsbl (%r14,%rcx), %edi
callq 0x7ace
leaq 0x1(%rbx), %rcx
cmpq %rbp, %rbx
jge 0x84a5
testb %al, %al
jne 0x848b
decq %rcx
movq %rcx, %rdx
movb (%r14,%rcx), %al
incq %rcx
cmpq %rbp, %rdx
jge 0x84bb
cmpb $0x3a, %al
jne 0x84a8
cmpb $0x3a, %al
pushq $-0x1
popq %rax
cmovnel %eax, %ecx
movl %r12d, %esi
jmp 0x8409
movq 0x30(%rsp), %rdx
subl %esi, %edx
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x79a6
movq %rax, %r14
movq %rbx, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x20b0
movq %rax, %rbx
pushq $0x2
popq %r15
leal -0x2(%r15), %r12d
movsbl (%r14,%r12), %edi
callq 0x7ace
incl %r15d
testb %al, %al
je 0x8513
cmpq %r12, %rbx
ja 0x84f9
cmpb $0x66, (%r14,%r12)
jne 0x85bf
cmpb $0x6f, 0x1(%r14,%r12)
jne 0x85bf
cmpb $0x72, 0x2(%r14,%r12)
jne 0x85bf
movl %r15d, %r12d
movb (%r14,%r12), %bpl
movsbl %bpl, %edi
callq 0x7ace
incl %r15d
testb %al, %al
je 0x8552
cmpq %r12, %rbx
ja 0x8536
cmpb $0x28, %bpl
jne 0x85bf
movl %r15d, %r12d
movsbl (%r14,%r12), %edi
callq 0x7ace
incl %r15d
testb %al, %al
je 0x8571
cmpq %r12, %rbx
ja 0x8558
xorl %eax, %eax
callq 0x7e26
testq %rax, %rax
je 0x85bf
movq %rax, %rbx
leal -0x1(%r15), %eax
movq %r14, %rdi
addq %r12, %rdi
movl %eax, (%rbx)
pushq $0x3b
popq %rsi
callq 0x7b48
addl %r15d, %eax
movl %eax, 0x4(%rbx)
cmpl %eax, (%rbx)
ja 0x85b7
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x7d20
movq %rax, %r15
movq %r14, %rdi
callq 0x2030
movq %r15, %r14
movq %rbx, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x6a30
testq %rax, %rax
je 0x868a
movq %rax, %rbx
movq (%rax), %rsi
movq %r14, %rdi
callq 0x7d20
movq %rax, %r15
movl (%rbx), %ebp
movq %rbx, %rdi
callq 0x2030
testq %r15, %r15
je 0x8699
movq %r15, %rdi
callq 0x20b0
movq %rax, %rbx
addl %ebx, %ebp
movq %r14, %rdi
callq 0x20b0
subl %ebx, %eax
movq %r14, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x79a6
movq %rax, %r13
movq %rax, %rdi
callq 0x20b0
movq %rax, 0x18(%rsp)
testl %eax, %eax
je 0x87e1
pushq $0x5
popq %rdi
callq 0x67e4
movq %rax, %r12
pushq $0x2a
popq %rbp
movq %r15, %rdi
movl %ebp, %esi
callq 0x79fc
movl %eax, 0x10(%rsp)
pushq $0x1
popq %rcx
movq %r15, %rdi
movl %ebp, %esi
movl %ecx, %edx
callq 0x7a2e
subl %eax, %ebx
movb $0x0, (%r15,%rbx)
movq %r15, %rdi
movl %ebp, %esi
callq 0x79fc
testl %eax, %eax
je 0x86a0
movq %r13, %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2030
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0x69f4
movq %r14, %rdi
callq 0x2030
xorl %ebx, %ebx
jmp 0x87fb
xorl %ebx, %ebx
jmp 0x87f3
leaq 0x60e5(%rip), %rsi      # 0xe78c
movq %r15, %rdi
callq 0x2110
testl %eax, %eax
movq %r12, 0x8(%rsp)
jne 0x86d5
leaq 0x6253(%rip), %rsi      # 0xe912
movq %r15, %rdi
callq 0x7bab
movq %rax, %rbx
movq %r15, %rdi
callq 0x2030
movq %rbx, %r15
xorl %ebp, %ebp
andq $0x0, 0x28(%rsp)
andl $0x0, 0x4(%rsp)
movq %r13, %rdi
movq %rsp, %rsi
leaq 0x4(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x8014
testq %rax, %rax
movq %r13, %r12
je 0x87c7
movq %rax, %rbx
movl %ebp, %edi
addq %r12, %rdi
movq (%rax), %rsi
callq 0x7d20
movq %rax, %rbp
movq %rbx, %rdi
callq 0x2030
movq %rbp, %rdi
pushq $0x2a
popq %r13
movl %r13d, %esi
callq 0x79fc
movl %eax, %ebx
movq %rbp, %rdi
movl %r13d, %esi
xorl %edx, %edx
pushq $0x1
popq %rcx
callq 0x7a2e
movl %eax, %r13d
movq %rbp, %rdi
callq 0x20b0
subl %ebx, %eax
movq %rbp, %rdi
movl %r13d, %esi
movl %eax, %edx
callq 0x79a6
movq %rax, %r13
movq %rbp, %rdi
callq 0x2030
testq %r13, %r13
je 0x87c7
movq %r13, %rdi
callq 0x67a6
testb %al, %al
jne 0x87bf
movq %r15, %rdi
callq 0x794d
addl 0x10(%rsp), %ebx
addl 0x4(%rsp), %ebx
movsbl %bl, %edx
movq %r13, %rdi
movq %rax, %rsi
movl 0x24(%rsp), %ecx
callq 0x5ee4
movq 0x28(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x68b5
movl (%rsp), %ebp
cmpl 0x18(%rsp), %ebp
movq %r12, %r13
jb 0x86d7
jmp 0x87ca
movq %r13, %rdi
callq 0x2030
movq %r12, %r13
movq 0x8(%rsp), %rbx
cmpq $0x0, 0x8(%rbx)
jne 0x87e3
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x69f4
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x2030
movq %r13, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)