// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %rsi, %r12
movl %edi, 0x28(%rsp)
movl $0x0, 0x10(%rsp)
movq %rsi, %rdi
callq 0x7c54
movq %rax, 0x40(%rsp)
movq %rax, %rdi
callq 0x20b0
movq %rax, 0x38(%rsp)
cltq
movq %rax, 0x8(%rsp)
leaq -0x1(%r12), %rax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
movq %r12, 0x18(%rsp)
movl %ebp, 0x2c(%rsp)
movslq %ebp, %rbx
movq 0x20(%rsp), %rax
leaq (%rax,%rbx), %r15
leal -0x2(%rbx), %ebp
leal -0x1(%rbx), %r13d
movq %rbx, %r12
movb 0x1(%r15), %r14b
incq %r15
movsbl %r14b, %edi
callq 0x7f3a
incq %rbx
incl %ebp
incl %r13d
cmpq 0x8(%rsp), %r12
jge 0x89c0
testb %al, %al
jne 0x899a
movl $0x4, %edx
movq %r15, %rdi
leaq 0x5ddd(%rip), %rsi      # 0xe7ac
callq 0x2070
testl %eax, %eax
movq 0x18(%rsp), %r12
je 0x89f5
movl $0x7, %edx
movq %r15, %rdi
leaq 0x5dd4(%rip), %rsi      # 0xe7c0
callq 0x2070
testl %eax, %eax
jne 0x8a65
xorl %eax, %eax
cmpb $0x63, %r14b
setne %al
leaq (%rax,%rax,2), %r15
addq $0x4, %r15
leal (%r15,%rbx), %eax
decl %eax
movslq %eax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rcx, %rbx
movl %edx, %r14d
movsbl (%r12,%rcx), %edi
callq 0x7f3a
leaq 0x1(%rbx), %rcx
cmpq 0x8(%rsp), %rbx
jge 0x8a37
leal -0x1(%r14), %edx
testb %al, %al
jne 0x8a14
decq %rcx
movb (%r12,%rcx), %al
decl %r14d
cmpq 0x8(%rsp), %rcx
jge 0x8a4f
incq %rcx
cmpb $0x3a, %al
jne 0x8a3a
cmpb $0x3a, %al
jne 0x8a65
addl %r15d, %r13d
addl %r15d, %ebp
subl %r14d, %ebp
cmpl %r14d, %r13d
jne 0x8983
movq 0x38(%rsp), %rdx
movl 0x2c(%rsp), %esi
subl %esi, %edx
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x7e1a
movq %rax, %r14
movq %rbx, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x20b0
movq %rax, %rbx
movl $0x2, %r15d
leal -0x2(%r15), %r12d
movsbl (%r14,%r12), %edi
callq 0x7f3a
incl %r15d
testb %al, %al
je 0x8ab3
cmpq %r12, %rbx
ja 0x8a99
cmpb $0x66, (%r14,%r12)
jne 0x8b61
cmpb $0x6f, 0x1(%r14,%r12)
jne 0x8b61
cmpb $0x72, 0x2(%r14,%r12)
jne 0x8b61
movl %r15d, %r12d
movb (%r14,%r12), %bpl
movsbl %bpl, %edi
callq 0x7f3a
incl %r15d
testb %al, %al
je 0x8af2
cmpq %r12, %rbx
ja 0x8ad6
cmpb $0x28, %bpl
jne 0x8b61
movl %r15d, %r12d
movsbl (%r14,%r12), %edi
callq 0x7f3a
incl %r15d
testb %al, %al
je 0x8b11
cmpq %r12, %rbx
ja 0x8af8
xorl %eax, %eax
callq 0x82d2
testq %rax, %rax
je 0x8b61
movq %rax, %rbx
leal -0x1(%r15), %eax
movq %r14, %rdi
addq %r12, %rdi
movl %eax, (%rbx)
movl $0x3b, %esi
callq 0x7fba
addl %r15d, %eax
movl %eax, 0x4(%rbx)
cmpl %eax, (%rbx)
ja 0x8b59
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x81b3
movq %rax, %r15
movq %r14, %rdi
callq 0x2030
movq %r15, %r14
movq %rbx, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x6de4
testq %rax, %rax
je 0x8c39
movq %rax, %rbx
movq (%rax), %rsi
movq %r14, %rdi
callq 0x81b3
movq %rax, %r15
movl (%rbx), %ebp
movq %rbx, %rdi
callq 0x2030
testq %r15, %r15
je 0x8c48
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 0x7e1a
movq %rax, %r13
movq %rax, %rdi
callq 0x20b0
movq %rax, 0x8(%rsp)
testl %eax, %eax
je 0x8da1
movl $0x5, %edi
callq 0x6b58
movq %rax, %r12
movq %r15, %rdi
movl $0x2a, %esi
callq 0x7e70
movl %eax, %ebp
movq %r15, %rdi
movl $0x2a, %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x7ea8
subl %eax, %ebx
movb $0x0, (%r15,%rbx)
movq %r15, %rdi
movl $0x2a, %esi
callq 0x7e70
testl %eax, %eax
je 0x8c4f
movq %r13, %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2030
movq %r12, %rdi
movl $0x1, %esi
callq 0x6d97
movq %r14, %rdi
callq 0x2030
xorl %ebx, %ebx
jmp 0x8dbb
xorl %ebx, %ebx
jmp 0x8db3
leaq 0x5b36(%rip), %rsi      # 0xe78c
movq %r15, %rdi
callq 0x2120
testl %eax, %eax
movq %r12, 0x18(%rsp)
movl %ebp, 0x20(%rsp)
jne 0x8c88
leaq 0x5ca0(%rip), %rsi      # 0xe912
movq %r15, %rdi
callq 0x8026
movq %rax, %rbx
movq %r15, %rdi
callq 0x2030
movq %rbx, %r15
xorl %ebp, %ebp
movq $0x0, 0x30(%rsp)
movl $0x0, 0x14(%rsp)
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x14(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x853c
testq %rax, %rax
movq %r13, %r12
je 0x8d85
movq %rax, %rbx
movl %ebp, %edi
addq %r12, %rdi
movq (%rax), %rsi
callq 0x81b3
movq %rax, %rbp
movq %rbx, %rdi
callq 0x2030
movq %rbp, %rdi
movl $0x2a, %esi
callq 0x7e70
movl %eax, %ebx
movq %rbp, %rdi
movl $0x2a, %esi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x7ea8
movl %eax, %r13d
movq %rbp, %rdi
callq 0x20b0
subl %ebx, %eax
movq %rbp, %rdi
movl %r13d, %esi
movl %eax, %edx
callq 0x7e1a
movq %rax, %r13
movq %rbp, %rdi
callq 0x2030
testq %r13, %r13
je 0x8d85
movq %r13, %rdi
callq 0x6b1c
testb %al, %al
jne 0x8d7d
movq %r15, %rdi
callq 0x7dc1
addl 0x20(%rsp), %ebx
addl 0x14(%rsp), %ebx
movsbl %bl, %edx
movq %r13, %rdi
movq %rax, %rsi
movl 0x28(%rsp), %ecx
callq 0x615c
movq 0x30(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x6c26
movl 0x10(%rsp), %ebp
cmpl 0x8(%rsp), %ebp
movq %r12, %r13
jb 0x8c8a
jmp 0x8d88
movq %r13, %rdi
callq 0x2030
movq %r12, %r13
movq 0x18(%rsp), %rbx
cmpq $0x0, 0x8(%rbx)
jne 0x8da3
movq %rbx, %rdi
movl $0x1, %esi
callq 0x6d97
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x2030
movq %r13, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)