// File: /workspace/github_c_makefile_star2_O0/ebiggers[P]mysh/mysh_lex.c
// Function: lex_next_token
int lex_next_token(const char *p, size_t *bytes_remaining_p,
		   struct token **tok_ret)
{
	struct token *tok;
	enum token_type type;
	char *tok_data;
	bool found_whitespace = false;
	size_t bytes_remaining = *bytes_remaining_p;
	int ret;

	if (*bytes_remaining_p == 0) /* No bytes remaining */
		return LEX_NOT_ENOUGH_INPUT;

	/* Ignore whitespace between tokens */
	while (shell_char_type(*p) & SHELL_LEX_WHITESPACE) {
		found_whitespace = true;
		p++;
		if (--bytes_remaining == 0)
			return LEX_NOT_ENOUGH_INPUT;
	}

	/* Choose the token type based on the next character, then parse the
	 * token. */
	tok_data = NULL;
	switch (*p) {
	case '&':
		type = TOK_AMPERSAND;
		--bytes_remaining;
		break;
	case '|':
		type = TOK_PIPE;
		--bytes_remaining;
		break;
	case '<':
		type = TOK_LESS_THAN;
		--bytes_remaining;
		break;
	case '>':
		type = TOK_GREATER_THAN;
		--bytes_remaining;
		break;
	case '#':
		{ /* everything after '#' up until the next newline is a comment */
			const char *newline;

			newline = memchr(p + 1, '\n', bytes_remaining - 1);
			if (!newline)
				return LEX_NOT_ENOUGH_INPUT;
			bytes_remaining -= newline - p;
		}
		/* fall through */
	case '\r':
	case '\n':
	case ';':
		type = TOK_END_OF_SHELL_STATEMENT;
		--bytes_remaining;
		break;
	case '\'':
		type = TOK_SINGLE_QUOTED_STRING;
		--bytes_remaining;
		ret = lex_string(p + 1, scan_single_quoted_string,
				 &bytes_remaining, &tok_data);
		if (ret < 0)
			return ret;
		break;
	case '"':
		type = TOK_DOUBLE_QUOTED_STRING;
		--bytes_remaining;
		ret = lex_string(p + 1, scan_double_quoted_string,
				 &bytes_remaining, &tok_data);
		if (ret < 0)
			return ret;
		break;
	default:
		/* anything that didn't match one of the special characters is
		 * treated as the beginning of an unquoted string */
		type = TOK_UNQUOTED_STRING;
		ret = lex_string(p, scan_unquoted_string,
				 &bytes_remaining, &tok_data);
		if (ret < 0)
			return ret;
		break;
	}
	/* Allocate and initialize the token */
	tok = xmalloc(sizeof(struct token));
	tok->preceded_by_whitespace = found_whitespace;
	tok->type = type;
	/* tok_data defaults to NULL if not explicitly set for a string token */
	tok->tok_data = tok_data;
	/* Return the token and set the bytes remaining in the input according
	 * to how much was consumed */
	*bytes_remaining_p = bytes_remaining;
	*tok_ret = tok;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movb $0x0, -0x39(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x34b9
movl $0xfffff830, -0x4(%rbp) # imm = 0xFFFFF830
jmp 0x3755
jmp 0x34bb
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0x3760
andl $0x10, %eax
cmpl $0x0, %eax
je 0x34ff
movb $0x1, -0x39(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0x34fd
movl $0xfffff830, -0x4(%rbp) # imm = 0xFFFFF830
jmp 0x3755
jmp 0x34bb
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x5c(%rbp)
subl $0xa, %eax
je 0x3634
jmp 0x351c
movl -0x5c(%rbp), %eax
subl $0xd, %eax
je 0x3634
jmp 0x352a
movl -0x5c(%rbp), %eax
subl $0x22, %eax
je 0x3691
jmp 0x3538
movl -0x5c(%rbp), %eax
subl $0x23, %eax
je 0x35ed
jmp 0x3546
movl -0x5c(%rbp), %eax
subl $0x26, %eax
je 0x358d
jmp 0x3550
movl -0x5c(%rbp), %eax
subl $0x27, %eax
je 0x364c
jmp 0x355e
movl -0x5c(%rbp), %eax
subl $0x3b, %eax
je 0x3634
jmp 0x356c
movl -0x5c(%rbp), %eax
subl $0x3c, %eax
je 0x35bd
jmp 0x3576
movl -0x5c(%rbp), %eax
subl $0x3e, %eax
je 0x35d5
jmp 0x3580
movl -0x5c(%rbp), %eax
subl $0x7c, %eax
je 0x35a5
jmp 0x36d6
movl $0x200, -0x2c(%rbp)     # imm = 0x200
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x3708
movl $0x100, -0x2c(%rbp)     # imm = 0x100
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x3708
movl $0x80, -0x2c(%rbp)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x3708
movl $0x40, -0x2c(%rbp)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x3708
movq -0x10(%rbp), %rdi
addq $0x1, %rdi
movq -0x48(%rbp), %rdx
subq $0x1, %rdx
movl $0xa, %esi
callq 0x2200
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x361e
movl $0xfffff830, -0x4(%rbp) # imm = 0xFFFFF830
jmp 0x3755
movq -0x58(%rbp), %rcx
movq -0x10(%rbp), %rax
subq %rax, %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x400, -0x2c(%rbp)     # imm = 0x400
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x3708
movl $0x4, -0x2c(%rbp)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
addq $0x1, %rdi
leaq 0x1b2(%rip), %rsi       # 0x3820
leaq -0x48(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x3780
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x368f
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3755
jmp 0x3708
movl $0x2, -0x2c(%rbp)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
addq $0x1, %rdi
leaq 0x22d(%rip), %rsi       # 0x38e0
leaq -0x48(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x3780
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x36d4
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3755
jmp 0x3708
movl $0x1, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x358(%rip), %rsi       # 0x3a40
leaq -0x48(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x3780
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x3706
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3755
jmp 0x3708
movl $0x20, %edi
callq 0x8e00
movq %rax, -0x28(%rbp)
movb -0x39(%rbp), %cl
movq -0x28(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop