// File: /workspace/github_c_makefile_star2_O3/System-Glitch[P]ESGILinter-C/src/parsing_functions.c
// Function: parse_function_parameters
static arraylist_t *parse_function_parameters(char *line, unsigned char is_prototype, int line_index) {
	arraylist_t *list            = arraylist_init(5);
	unsigned int start_index     = 0;
	unsigned int index           = 0;
	unsigned int sub_index       = 0;
	unsigned int length          = strlen(line);
	unsigned int type_length     = 0;
	unsigned int star_count_type = 0;
	unsigned int star_count_name = 0;
	unsigned int array_count     = 0;
	unsigned int type_sub_index;
	unsigned char c;
	char *tmp           = NULL;
	char *tmp_name      = NULL;
	char *type          = NULL;
	char *name          = NULL;
	match_t *match_type = NULL;
	match_t *match_name = NULL;
	field_t *field      = NULL;

	do {
		SKIP_WHITESPACES

		start_index = index;

		//Until comma
		while((c = line[index]) != ',' && index < length) {
			index++;
		}

		tmp = strsubstr(line, start_index, index - start_index);
		if(strlen(tmp) == 0) {
			free(tmp);
			break;
		}

		//Parse type
		match_type = parse_type(tmp);
		if(match_type == NULL) {
			free(tmp);
			field_list_free(list);
			return NULL;
		}

		type = substr_match(tmp, *match_type);
		free(match_type);
		type_length     = strlen(type);
		star_count_type = strcount(type, '*');
		type_sub_index  = strcountuntil(type, '*', 1, 1);

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

		//If no name and not prototype, invalid syntax
		match_name = parse_variable_name(tmp + type_length, &sub_index, &array_count, NULL);
		if(match_name != NULL) {
			tmp_name = substr_match(tmp + type_length, *match_name);
			free(match_name);

			if(strlen(tmp_name) == 0 && !is_prototype) { //Parameter names compulsory when not prototype
				free(tmp);
				field_list_free(list);
				return NULL;
			}

			star_count_name = strcount(tmp_name, '*');
			sub_index       = strcountuntil(tmp_name, '*', 0, 1);

			//Remove stars
			name = strsubstr(tmp_name, sub_index, strlen(tmp_name) - star_count_name);
			free(tmp_name);
		} else if(!is_prototype) { //Parameter names compulsory when not prototype
			free(tmp);
			field_list_free(list);
			return NULL;
		}

		field = field_init(name, type, star_count_type + star_count_name + array_count, line_index);
		field->is_param = 1;
		arraylist_add(list, field);

		free(tmp);

		index++;
		
	} while(index < length);

	return list;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, 0x24(%rsp)
movl %esi, 0x4(%rsp)
movq %rdi, %r15
movl $0x5, %edi
callq 0x6b58
movq %rax, %rbp
xorl %r13d, %r13d
leaq 0xc(%rsp), %rax
movl %r13d, (%rax)
movq %r15, %rdi
callq 0x20b0
leaq 0x8(%rsp), %rcx
movl %r13d, (%rcx)
movq %rax, 0x38(%rsp)
movl %eax, %r14d
xorl %r12d, %r12d
movq $0x0, 0x30(%rsp)
movq %rbp, 0x10(%rsp)
movl %r13d, %ebx
decq %rbx
movsbl 0x1(%r15,%rbx), %edi
incq %rbx
callq 0x7f3a
testb %al, %al
je 0xb05e
cmpq %r14, %rbx
jb 0xb047
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rax
leaq 0x1(%rax), %r13
incl %edx
cmpb $0x2c, (%r15,%rax)
je 0xb07b
cmpq %r14, %rax
movq %r13, %rax
jb 0xb066
movq %r15, %rdi
movl %ebx, %esi
callq 0x7e1a
cmpb $0x0, (%rax)
je 0xb1fa
movl %r12d, 0x28(%rsp)
movq %rax, %rdi
movq %rax, %rbx
callq 0x6de4
testq %rax, %rax
je 0xb204
movq %rax, %r12
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x81b3
movq %rax, %rbp
movq %r12, %rdi
callq 0x2030
movq %rbp, %rdi
callq 0x20b0
movq %rax, %r12
movq %rbp, %rdi
movl $0x2a, %esi
callq 0x7e70
movl %eax, 0x2c(%rsp)
movq %rbp, %rdi
movl $0x2a, %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x7ea8
movl %r12d, %ecx
subl %eax, %r12d
movq %rbp, 0x40(%rsp)
movb $0x0, (%rbp,%r12)
movq %rbx, 0x18(%rsp)
addq %rcx, %rbx
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x853c
testq %rax, %rax
je 0xb199
movq %rax, %r12
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x81b3
movq %rax, %rbp
movq %r12, %rdi
callq 0x2030
movb (%rbp), %al
orb 0x4(%rsp), %al
je 0xb211
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, %r12d
movl %eax, 0xc(%rsp)
movq %rbp, %rdi
callq 0x20b0
subl %ebx, %eax
movq %rbp, %rdi
movl %r12d, %esi
movl %eax, %edx
callq 0x7e1a
movq %rax, %r12
movq %rbp, %rdi
callq 0x2030
jmp 0xb1a9
cmpb $0x0, 0x4(%rsp)
movl 0x28(%rsp), %ebx
movq 0x30(%rsp), %r12
je 0xb211
movl 0x2c(%rsp), %eax
addl %ebx, %eax
addl 0x8(%rsp), %eax
movsbl %al, %edx
movq %r12, 0x30(%rsp)
movq %r12, %rdi
movq 0x40(%rsp), %rsi
movl 0x24(%rsp), %ecx
callq 0x615c
movb $0x1, 0x24(%rax)
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %rax, %rsi
callq 0x6c26
movq 0x18(%rsp), %rdi
callq 0x2030
cmpl 0x38(%rsp), %r13d
movl %ebx, %r12d
jb 0xb041
jmp 0xb227
movq %rax, %rdi
callq 0x2030
jmp 0xb227
movq %rbx, %rdi
callq 0x2030
movq %rbp, %rdi
jmp 0xb220
movq 0x18(%rsp), %rdi
callq 0x2030
movq 0x10(%rsp), %rdi
callq 0x6953
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq