// File: /workspace/github_c_makefile_star2_O2/System-Glitch[P]ESGILinter-C/src/parsing_type.c
// Function: parse_type
match_t *parse_type(char *line) {
	unsigned int index = 0;
	int type_start = -1;
	int type_end = -1;

	size_t length = strlen(line);
	unsigned char c;
	match_t *match = NULL;

	if(length < 3) return NULL; //3 is the minimum size for a declaration

	SKIP_WHITESPACES

	if(strstr(line + index, "extern") == line + index) //Skip extern keyword
		index += 6;

	SKIP_WHITESPACES

	if(strstr(line + index, "static") == line + index) //Skip static keyword
		index += 6;

	SKIP_WHITESPACES

	if(strstr(line + index, "volatile") == line + index) //Skip volatile keyword
		index += 8;

	SKIP_WHITESPACES

	if(strstr(line + index, "const") == line + index) //Skip const keyword
		index += 5;

	SKIP_WHITESPACES

	if(strstr(line + index, "signed") == line + index) //Skip signed keyword
		index += 6;

	SKIP_WHITESPACES

	type_start = index;

	if(!parse_type_word(line, length, &index)) //No type word found, it's not a variable declaration
		return NULL;

	if(line[index] == ';') //If found semi-colon, it's not a variable declaration
		return NULL;

	//Find star	
	while(index < length) {
		SKIP_WHITESPACES

		//If found something else than star, end
		if(c != '*') {
			index--;
			break;
		} else if(c == ';') //If found semi-colon, it's not a variable declaration
			return NULL;
		else
			index++;
	}

	type_end = index;

	if(type_end != -1) {
		match = match_init();
		if(match != NULL) {
			match->index_start = type_start;
			match->index_end = type_end;
		}
	}

	return match;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r13
callq 0x20b0
cmpq $0x3, %rax
jb 0x6ccc
movq %rax, (%rsp)
pushq $-0x1
popq %r15
incl %r15d
movsbl (%r13,%r15), %edi
callq 0x7ace
cmpq %r15, (%rsp)
jbe 0x6a70
testb %al, %al
jne 0x6a58
leaq (%r15,%r13), %rdi
leaq 0x7d5a(%rip), %rsi      # 0xe7d5
pushq $0x6
popq %rdx
callq 0x2070
leal 0x6(%r15), %ebx
testl %eax, %eax
cmovnel %r15d, %ebx
decl %ebx
movq (%rsp), %r14
incl %ebx
movsbl (%r13,%rbx), %edi
callq 0x7ace
cmpq %rbx, %r14
jbe 0x6aa9
testb %al, %al
jne 0x6a93
leaq (%rbx,%r13), %rdi
leaq 0x7d50(%rip), %rsi      # 0xe804
pushq $0x6
popq %rdx
callq 0x2070
leal 0x6(%rbx), %r15d
testl %eax, %eax
cmovnel %ebx, %r15d
decl %r15d
incl %r15d
movsbl (%r13,%r15), %edi
callq 0x7ace
cmpq %r15, (%rsp)
jbe 0x6ae1
testb %al, %al
jne 0x6ac9
leaq (%r15,%r13), %rdi
leaq 0x7d3b(%rip), %rsi      # 0xe827
pushq $0x8
popq %rdx
callq 0x2070
leal 0x8(%r15), %ebx
testl %eax, %eax
cmovnel %r15d, %ebx
decl %ebx
movq (%rsp), %r14
incl %ebx
movsbl (%r13,%rbx), %edi
callq 0x7ace
cmpq %rbx, %r14
jbe 0x6b1a
testb %al, %al
jne 0x6b04
leaq (%rbx,%r13), %rdi
leaq 0x7c8c(%rip), %rsi      # 0xe7b1
pushq $0x5
popq %rdx
callq 0x2070
leal 0x5(%rbx), %r15d
testl %eax, %eax
cmovnel %ebx, %r15d
decl %r15d
incl %r15d
movsbl (%r13,%r15), %edi
callq 0x7ace
cmpq %r15, (%rsp)
jbe 0x6b52
testb %al, %al
jne 0x6b3a
leaq (%r15,%r13), %rdi
leaq 0x7c31(%rip), %rsi      # 0xe78e
pushq $0x6
popq %rdx
callq 0x2070
leal 0x6(%r15), %ebp
testl %eax, %eax
cmovnel %r15d, %ebp
movq (%rsp), %r15
movl %ebp, %ebx
movsbl (%r13,%rbx), %edi
callq 0x7ace
incl %ebp
cmpq %rbx, %r15
jbe 0x6b8b
testb %al, %al
jne 0x6b73
decl %ebp
movb $0x1, %al
movl %ebp, 0x10(%rsp)
movl %ebp, %r12d
movq %r13, 0x8(%rsp)
movl %eax, 0x14(%rsp)
leal -0x1(%r12), %ecx
movl %r12d, %ebp
movl %ecx, %r12d
movl %ebp, %ebx
movsbl (%r13,%rbx), %edi
callq 0x7ace
incl %ebp
cmpq %rbx, %r15
jbe 0x6bc7
leal 0x1(%r12), %ecx
testb %al, %al
jne 0x6ba7
decl %ebp
pushq $-0x1
popq %r15
incl %r12d
movq 0x8(%rsp), %rax
movsbl (%rax,%r12), %r13d
cmpl $0x2a, %r13d
sete %r14b
movl %r13d, %edi
callq 0x7dfb
testb %al, %al
setne %al
incl %r15d
cmpq %r12, (%rsp)
jbe 0x6bfd
orb %al, %r14b
jne 0x6bcd
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x79a6
movq %rax, %r15
movq %rax, %rdi
callq 0x20b0
movq %rax, %r14
movq %r15, %rdi
pushq $0x2a
popq %rsi
pushq $0x1
popq %rcx
movl %ecx, %edx
callq 0x7a2e
movl %eax, %eax
subq %rax, %r14
movb $0x0, (%r15,%r14)
movq %r15, %rdi
callq 0x6590
movl %eax, %r14d
movq %r15, %rdi
callq 0x2030
testb %r14b, %r14b
je 0x6c66
xorl %eax, %eax
movl %r12d, %ebp
cmpb $0x3b, %r13b
movq 0x8(%rsp), %r13
movq (%rsp), %r15
jne 0x6b9b
jmp 0x6c79
movq %rbx, %r12
testb $0x1, 0x14(%rsp)
movq 0x8(%rsp), %r13
movq (%rsp), %r15
jne 0x6ccc
cmpb $0x3b, (%r13,%r12)
je 0x6ccc
movl %ebp, %eax
cmpq %rax, %r15
jbe 0x6cab
movl %ebp, %r14d
movb (%r13,%r14), %bl
movsbl %bl, %edi
callq 0x7ace
incl %ebp
cmpq %r14, %r15
jbe 0x6ca3
testb %al, %al
jne 0x6c88
cmpb $0x2a, %bl
je 0x6c81
addl $-0x2, %ebp
cmpl $-0x1, %ebp
je 0x6ccc
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x7e26
testq %rax, %rax
je 0x6cce
movl 0x10(%rsp), %ecx
movl %ecx, (%rax)
movl %ebp, 0x4(%rax)
movq %rax, %rbx
jmp 0x6cce
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq