// File: /workspace/github_c_makefile_star2_O1/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, 0x2c(%rsp)
movl $0x0, 0x8(%rsp)
movq %rsi, %rdi
callq 0x7be4
movq %rax, 0x18(%rsp)
movq %rax, %rdi
callq 0x20b0
movq %rax, 0x20(%rsp)
movslq %eax, %r15
xorl %ecx, %ecx
movl %ecx, %ebp
movslq %ecx, %r13
decq %r13
movb 0x1(%r14,%r13), %r12b
incq %r13
movsbl %r12b, %edi
callq 0x7ed1
cmpq %r15, %r13
jge 0x88e6
testb %al, %al
jne 0x88cc
leaq (%r14,%r13), %rbx
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x5eb6(%rip), %rsi      # 0xe7af
callq 0x2070
testl %eax, %eax
je 0x891f
movl $0x7, %edx
movq %rbx, %rdi
leaq 0x5eb2(%rip), %rsi      # 0xe7c3
callq 0x2070
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x896e
xorl %eax, %eax
cmpb $0x63, %r12b
setne %al
leal (%rax,%rax,2), %eax
addl %r13d, %eax
addl $0x4, %eax
movslq %eax, %rcx
movq %rcx, %rbx
movsbl (%r14,%rcx), %edi
callq 0x7ed1
leaq 0x1(%rbx), %rcx
cmpq %r15, %rbx
jge 0x894e
testb %al, %al
jne 0x8934
decq %rcx
movq %rcx, %rdx
movb (%r14,%rcx), %al
incq %rcx
cmpq %r15, %rdx
jge 0x8964
cmpb $0x3a, %al
jne 0x8951
cmpb $0x3a, %al
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %eax, %ecx
cmpl $-0x1, %ecx
jne 0x88c4
movq 0x20(%rsp), %rdx
subl %ebp, %edx
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7db1
movq %rax, %r14
movq %rbx, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x20b0
movq %rax, %rbx
movl $0x2, %r12d
leal -0x2(%r12), %r15d
movsbl (%r14,%r15), %edi
callq 0x7ed1
incl %r12d
testb %al, %al
je 0x89c4
cmpq %r15, %rbx
ja 0x89a9
addq %r14, %r15
leaq 0x465c(%rip), %rsi      # 0xd02a
movl $0x3, %edx
movq %r15, %rdi
callq 0x2070
testl %eax, %eax
jne 0x8a54
jmp 0x89e6
cmpq %r15, %rbx
jbe 0x89fd
movl %r12d, %r15d
movb (%r14,%r15), %bpl
movsbl %bpl, %edi
callq 0x7ed1
incl %r12d
testb %al, %al
jne 0x89e1
cmpb $0x28, %bpl
jne 0x8a54
movl %r12d, %r15d
movsbl (%r14,%r15), %edi
callq 0x7ed1
incl %r12d
testb %al, %al
je 0x8a1c
cmpq %r15, %rbx
ja 0x8a03
xorl %eax, %eax
callq 0x8287
testq %rax, %rax
je 0x8a54
movq %rax, %rbx
leal -0x1(%r12), %eax
movq %r14, %rdi
addq %r15, %rdi
movl %eax, (%rbx)
movl $0x3b, %esi
callq 0x7f51
addl %r12d, %eax
movl %eax, 0x4(%rbx)
cmpl %eax, (%rbx)
jbe 0x8a56
movq %rbx, %rdi
callq 0x2030
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x8a7c
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x8149
movq %rax, %r15
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x2030
movq %r15, %r14
movq %r14, %rdi
callq 0x6d50
testq %rax, %rax
je 0x8b50
movq %rax, %rbx
movq (%rax), %rsi
movq %r14, %rdi
callq 0x8149
movq %rax, %r15
movl (%rbx), %ebp
movq %rbx, %rdi
callq 0x2030
testq %r15, %r15
je 0x8b50
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 0x7db1
movq %rax, %r13
movq %rax, %rdi
callq 0x20b0
movq %rax, %rbp
testl %ebp, %ebp
je 0x8b57
movl $0x5, %edi
callq 0x6ac8
movq %rax, %r12
movq %r15, %rdi
movl $0x2a, %esi
callq 0x7e07
movl %eax, 0x20(%rsp)
movq %r15, %rdi
movl $0x2a, %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x7e3f
subl %eax, %ebx
movb $0x0, (%r15,%rbx)
movq %r15, %rdi
movl $0x2a, %esi
callq 0x7e07
testl %eax, %eax
je 0x8b5e
movq %r13, %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2030
movq %r12, %rdi
movl $0x1, %esi
callq 0x6d0a
xorl %ebx, %ebx
jmp 0x8cd9
xorl %ebx, %ebx
jmp 0x8cc9
movq %r12, 0x18(%rsp)
leaq 0x5c25(%rip), %rsi      # 0xe78f
movq %r15, %rdi
callq 0x2120
testl %eax, %eax
je 0x8b7d
movq %r15, 0x10(%rsp)
jmp 0x8b9c
leaq 0x5d9e(%rip), %rsi      # 0xe922
movq %r15, %rdi
callq 0x7fbd
movq %rax, %rbx
movq %r15, %rdi
callq 0x2030
movq %rbx, 0x10(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x0, 0xc(%rsp)
movl 0x8(%rsp), %ebx
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
leaq 0xc(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x8508
testq %rax, %rax
je 0x8c53
movq %rax, %r12
addq %r13, %rbx
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x8149
movq %rax, %r15
movq %r12, %rdi
callq 0x2030
movq %r15, %rdi
movl $0x2a, %esi
callq 0x7e07
movl %eax, %ebx
movq %r15, %rdi
movl $0x2a, %esi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x7e3f
movl %eax, %r12d
movq %r15, %rdi
callq 0x20b0
subl %ebx, %eax
movq %r15, %rdi
movl %r12d, %esi
movl %eax, %edx
callq 0x7db1
movq %rax, %r12
movq %r15, %rdi
callq 0x2030
testq %r12, %r12
je 0x8c53
movq %r12, %rdi
callq 0x6a8d
testb %al, %al
movl 0x20(%rsp), %r15d
je 0x8c78
movq %r12, %rdi
callq 0x2030
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x8c67
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x6b96
testq %rbx, %rbx
je 0x8ca9
cmpl %ebp, 0x8(%rsp)
jb 0x8b9c
jmp 0x8ca9
movq 0x10(%rsp), %rdi
callq 0x7d58
addl %r15d, %ebx
addl 0xc(%rsp), %ebx
movsbl %bl, %edx
movq %r12, %rdi
movq %rax, %rsi
movl 0x2c(%rsp), %ecx
callq 0x6090
movq %rax, %rbx
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rbx)
jmp 0x8c55
movq 0x18(%rsp), %rbx
cmpq $0x0, 0x8(%rbx)
jne 0x8cc4
movq %rbx, %rdi
movl $0x1, %esi
callq 0x6d0a
xorl %ebx, %ebx
movq 0x10(%rsp), %r15
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
nop