// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x18(%rbp), %rdi
callq 0xa2b0
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x2090
movl %eax, -0x24(%rbp)
cmpl $-0x1, -0x38(%rbp)
je 0xba17
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x24(%rbp), %edx
callq 0xbcc0
movl %eax, -0x38(%rbp)
jmp 0xb9f7
cmpl $-0x1, -0x34(%rbp)
je 0xba44
movq -0x68(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x24(%rbp), %edx
subl -0x34(%rbp), %edx
callq 0xa5e0
movq %rax, -0x18(%rbp)
movq -0x68(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0xbe30
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0xba80
movq -0x68(%rbp), %rdi
movq -0x50(%rbp), %rax
movq (%rax), %rsi
callq 0xac10
movq %rax, -0x18(%rbp)
movq -0x68(%rbp), %rdi
callq 0x2030
movq -0x50(%rbp), %rdi
callq 0x2030
jmp 0xba88
movq -0x68(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x8a90
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xbab2
movq -0x18(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0xbcaa
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rax
movq (%rax), %rsi
callq 0xac10
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2030
cmpq $0x0, -0x78(%rbp)
je 0xbc99
movq -0x78(%rbp), %rdi
callq 0x2090
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x30(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2090
movq -0x88(%rbp), %rdi
movl -0x7c(%rbp), %esi
movl -0x28(%rbp), %ecx
subq %rcx, %rax
movl %eax, %edx
callq 0xa5e0
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0x2090
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jbe 0xbc87
movl $0x5, %edi
callq 0x8580
movq %rax, -0x40(%rbp)
movq -0x78(%rbp), %rdi
movl $0x2a, %esi
callq 0xa660
movl %eax, -0x1c(%rbp)
movq -0x78(%rbp), %rdi
movl $0x2a, %esi
movl $0x1, %ecx
movl %ecx, %edx
callq 0xa6d0
movl %eax, -0x20(%rbp)
movq -0x78(%rbp), %rax
movl -0x28(%rbp), %ecx
subl -0x20(%rbp), %ecx
movl %ecx, %ecx
movb $0x0, (%rax,%rcx)
movq -0x78(%rbp), %rdi
movl $0x2a, %esi
callq 0xa660
cmpl $0x0, %eax
je 0xbbcd
movq -0x70(%rbp), %rdi
callq 0x2030
movq -0x78(%rbp), %rdi
callq 0x2030
movq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x8a00
movq -0x18(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0xbcaa
movq -0x78(%rbp), %rdi
leaq 0x8bc1(%rip), %rsi      # 0x14799
callq 0x20f0
cmpl $0x0, %eax
jne 0xbc07
movq -0x78(%rbp), %rdi
leaq 0x8d17(%rip), %rsi      # 0x14904
callq 0xa9b0
movq %rax, -0x60(%rbp)
movq -0x78(%rbp), %rdi
callq 0x2030
movq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0xbc09
jmp 0xbc0b
movl -0xc(%rbp), %edi
movq -0x78(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x70(%rbp), %rcx
leaq -0x2c(%rbp), %r8
callq 0xbff0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xbc3a
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x8730
jmp 0xbc3c
xorl %eax, %eax
cmpq $0x0, -0x48(%rbp)
movb %al, -0x89(%rbp)
je 0xbc5a
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
setb %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0xbc0b
movq -0x40(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xbc85
movq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x8a00
movq $0x0, -0x40(%rbp)
jmp 0xbc87
movq -0x78(%rbp), %rdi
callq 0x2030
movq -0x70(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rdi
callq 0x2030
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)