// File: /workspace/github_c_makefile_star2_O0/qpfiffer[P]lair/src/parse.c
// Function: parse_from_token
static struct _lair_ast *_parse_from_token(struct _lair_token **tokens) {
	/* "pop" the token off of the top of the stack. */
	struct _lair_token *current_token = _pop_token(tokens);

	/* Atomize the function, stick it at the head of the list. */
	struct _lair_ast _stack_ast = {
		.atom = _lair_atomize_token(current_token),
		.indent_level = current_token->indent_level
	};

	if (current_token->token_type == LR_FUNCTION_CALL ||
			current_token->token_type == LR_FUNCTION_DEF ||
			current_token->token_type == LR_CALL) {
		struct _lair_ast *list = calloc(1, sizeof(struct _lair_ast));
		memcpy(list, &_stack_ast, sizeof(struct _lair_ast));

		/* We break out of the loop when we find an EOF or a DEDENT. */
		struct _lair_ast *cur_ast_item = list;
		struct _lair_ast *prev = NULL;
		while (current_token->token_type != LR_DEDENT &&
			   current_token->token_type != LR_EOF) {
			struct _lair_ast *to_append = _parse_from_token(tokens);
			cur_ast_item->next = to_append;
			cur_ast_item->prev = prev;

			/* Get the next token in line. */
			prev = cur_ast_item;
			cur_ast_item = cur_ast_item->next;
			current_token = (*tokens);
			if (current_token == NULL) {
				/* This happens sometimes if we have a statement like the following:
				 * ! print ! return 10<EOF>
				 */
				return list;
			}
		}

		if (current_token->token_type == LR_EOF) {
			struct _lair_ast *to_append = _parse_from_token(tokens);
			cur_ast_item->next = to_append;
			cur_ast_item->prev = prev;

			prev = cur_ast_item;
			cur_ast_item = cur_ast_item->next;
			current_token = (*tokens);
		}
		return list;
	} else {
		struct _lair_ast *to_return = calloc(1, sizeof(struct _lair_ast));
		memcpy(to_return, &_stack_ast, sizeof(struct _lair_ast));
		_lair_free_token(current_token);
		return to_return;
	}

	_lair_free_tokens(current_token);

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5110
movq %rax, -0x18(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4ba0
movl %eax, -0x28(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x2, 0x8(%rax)
je 0x4fa8
movq -0x18(%rbp), %rax
cmpl $0x1, 0x8(%rax)
je 0x4fa8
movq -0x18(%rbp), %rax
cmpl $0xb, 0x8(%rax)
jne 0x50bf
movl $0x1, %edi
movl $0x38, %esi
callq 0x1110
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movl $0x38, %edx
callq 0x1140
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpl $0x8, 0x8(%rcx)
movb %al, -0x81(%rbp)
je 0x5000
movq -0x18(%rbp), %rax
cmpl $0x9, 0x8(%rax)
setne %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x500c
jmp 0x5068
movq -0x10(%rbp), %rdi
callq 0x4f30
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x5063
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x50f5
jmp 0x4fdd
movq -0x18(%rbp), %rax
cmpl $0x9, 0x8(%rax)
jne 0x50b5
movq -0x10(%rbp), %rdi
callq 0x4f30
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x50f5
movl $0x1, %edi
movl $0x38, %esi
callq 0x1110
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movl $0x38, %edx
callq 0x1140
movq -0x18(%rbp), %rdi
callq 0x4e10
movq -0x80(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)