// File: /workspace/github_c_makefile_star2_O0/Yamsman[P]scc/src/lex.c
// Function: lex_nchar
char lex_nchar(lexer *lx, int *len, s_pos *nloc, int pflag) {
	char *pos, *prev_pos;
	char cch, prev_cch;
	s_pos loc, prev_loc;
	
	/*
	 * Get the next character
	 */
	static int is_reset = 0;
	int is_start = (lx->tgt->loc.col == 0);
reset:	pos = lx->tgt->pos;
	cch = lx->tgt->cch;
	loc = lx->tgt->loc;
tpaste:	if (!is_reset) lex_prcc(lx, &pos, &cch, &loc);
	if (is_start) lx->tgt->loc = loc;

	//Release the current context if the end has been reached
	if (cch == '\0' && lx->m_exp) {
		//The last context will stay open until the lexer is closed
		if (lx->tgt->prev == NULL)
			return '\0';

		lexer_tgt_close(lx);
		is_reset = 1;
		goto reset;
	}

	/*
	 * Replace comments with whitespace
	 */
	prev_pos = pos; prev_cch = cch; prev_loc = loc;
	if (cch == '/') {
		lex_prcc(lx, &pos, &cch, &loc);
		if (cch == '/') {
			//C++ style comments
			for (;;) {
				if (cch == '\n' || cch == '\0') break;
				lex_prcc(lx, &pos, &cch, &loc);
			}
			if (cch == '\0') {
				//error
			}
		} else if (cch == '*') {
			//C style comments
			lex_prcc(lx, &pos, &cch, &loc);
			char prevc = cch;
			for (;;) {
				if (prevc == '\0') break;
				lex_prcc(lx, &pos, &cch, &loc);
				if (prevc == '*' && cch == '/') break;
				prevc = cch;
			}
			if (cch == '\0') {
				c_error(&loc, "Unterminated comment\n");
			} else {
				cch = ' ';
			}
		} else {
			//Rewind
			pos = prev_pos; cch = prev_cch; loc = prev_loc;
		}
	}

	/*
	 * Macro expansion
	 * Only attempt if currently at beginning of an identifier and expansion is enabled
	*/
	char prev = (is_reset || is_start) ? '\0' : *lx->tgt->pos;
	prev_pos = pos; prev_cch = cch; prev_loc = loc;
	if (lx->m_exp && (!isalpha(prev) && prev != '_') && (isalpha(cch) || cch == '_')) {
		//Read identifier
		int len = 0;
		int bsize = 256;
		char cur = cch;
		char *buf = malloc(bsize);
		s_pos m_loc = loc;
		while (isalnum(cur) || cur == '_') {
			//Resize if needed
			if (len+2 == bsize) {
				bsize *= 2;
				buf = realloc(buf, bsize);
			}

			//Copy character to buffer
			buf[len++] = cur;
			cur = lex_prcc(lx, &pos, &cch, &loc);
		}
		buf[len] = '\0';

		//Attempt to expand the macro
		if (!lex_expand_macro(lx, buf, &m_loc, &pos, &cch, &loc)) {
			is_reset = 1;
			goto reset;
		} else {
			free(buf);
		}

		//If the macro was not expanded, restore to before the identifier was read
		pos = prev_pos; cch = prev_cch; loc = prev_loc;
	}

	/*
	 * Handle token pasting
	 */
	//Only attempt once per chunk of whitespace
	prev_pos = pos; prev_cch = cch; prev_loc = loc;
	if (isspace(cch) && !isspace(prev))
		while (isspace(cch) && cch != '\n') lex_prcc(lx, &pos, &cch, &loc);

	//Perform token pasting if a double pound sign exists
	int has_dns = 0;
	if (lx->tgt->type == TGT_MACRO && cch == '#') {
		//Check for a '##'
		lex_prcc(lx, &pos, &cch, &loc);
		if (cch == '#') {
			has_dns = 1;
			do lex_prcc(lx, &pos, &cch, &loc);
			while (isspace(cch) && cch != '\n');
		}
	}
	if (has_dns) {
		is_reset = 1;
		goto tpaste;
	} else {
		pos = prev_pos; cch = prev_cch; loc = prev_loc;
	}

	//Update external values if applicable and return the next character
	if (len != NULL) *len = pos - lx->tgt->pos;
	if (nloc != NULL) {
		if (lx->tgt->type != TGT_MACRO)
			*nloc = loc;
		else
			*nloc = lx->tgt->loc;
	}
	if (!pflag)
		is_reset = 0;

	return cch;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x2c(%rax)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x74(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb 0x20(%rax), %al
movb %al, -0x39(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x30(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x38(%rax), %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, 0x100c6(%rip)     # 0x174c8
jne 0x7419
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x39(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x71a0
cmpl $0x0, -0x74(%rbp)
je 0x743e
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movq %rcx, 0x28(%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x38(%rax)
movsbl -0x39(%rbp), %eax
cmpl $0x0, %eax
jne 0x7480
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x7480
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x50(%rax)
jne 0x7468
movb $0x0, -0x1(%rbp)
jmp 0x7a1a
movq -0x10(%rbp), %rdi
callq 0x70b0
movl $0x1, 0x1004d(%rip)     # 0x174c8
jmp 0x73c0
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movb -0x39(%rbp), %al
movb %al, -0x3a(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movsbl -0x39(%rbp), %eax
cmpl $0x2f, %eax
jne 0x75bb
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x39(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x71a0
movsbl -0x39(%rbp), %eax
cmpl $0x2f, %eax
jne 0x750e
jmp 0x74d3
movsbl -0x39(%rbp), %eax
cmpl $0xa, %eax
je 0x74e5
movsbl -0x39(%rbp), %eax
cmpl $0x0, %eax
jne 0x74e7
jmp 0x74fe
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x39(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x71a0
jmp 0x74d3
movsbl -0x39(%rbp), %eax
cmpl $0x0, %eax
jne 0x7509
jmp 0x7509
jmp 0x75b9
movsbl -0x39(%rbp), %eax
cmpl $0x2a, %eax
jne 0x7591
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x39(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x71a0
movb -0x39(%rbp), %al
movb %al, -0x75(%rbp)
movsbl -0x75(%rbp), %eax
cmpl $0x0, %eax
jne 0x753d
jmp 0x756e
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x39(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x71a0
movsbl -0x75(%rbp), %eax
cmpl $0x2a, %eax
jne 0x7566
movsbl -0x39(%rbp), %eax
cmpl $0x2f, %eax
jne 0x7566
jmp 0x756e
movb -0x39(%rbp), %al
movb %al, -0x75(%rbp)
jmp 0x7532
movsbl -0x39(%rbp), %eax
cmpl $0x0, %eax
jne 0x758b
leaq -0x58(%rbp), %rdi
leaq 0xa975(%rip), %rsi      # 0x11ef7
movb $0x0, %al
callq 0x3880
jmp 0x758f
movb $0x20, -0x39(%rbp)
jmp 0x75b7
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movb -0x3a(%rbp), %al
movb %al, -0x39(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x75b9
jmp 0x75bb
cmpl $0x0, 0xff06(%rip)      # 0x174c8
jne 0x75ca
cmpl $0x0, -0x74(%rbp)
je 0x75d4
xorl %eax, %eax
movl %eax, -0xb0(%rbp)
jmp 0x75e8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movsbl (%rax), %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
movb %al, -0x76(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movb -0x39(%rbp), %al
movb %al, -0x3a(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x77ea
callq 0x3240
movq (%rax), %rax
movsbl -0x76(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x77ea
movsbl -0x76(%rbp), %eax
cmpl $0x5f, %eax
je 0x77ea
callq 0x3240
movq (%rax), %rax
movsbl -0x39(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x767d
movsbl -0x39(%rbp), %eax
cmpl $0x5f, %eax
jne 0x77ea
movl $0x0, -0x7c(%rbp)
movl $0x100, -0x80(%rbp)     # imm = 0x100
movb -0x39(%rbp), %al
movb %al, -0x81(%rbp)
movslq -0x80(%rbp), %rdi
callq 0x3190
movq %rax, -0x90(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x98(%rbp)
callq 0x3240
movq (%rax), %rax
movsbl -0x81(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x8, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0xb1(%rbp)
jne 0x76fe
movsbl -0x81(%rbp), %eax
cmpl $0x5f, %eax
sete %al
movb %al, -0xb1(%rbp)
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x770a
jmp 0x7772
movl -0x7c(%rbp), %eax
addl $0x2, %eax
cmpl -0x80(%rbp), %eax
jne 0x7734
movl -0x80(%rbp), %eax
shll %eax
movl %eax, -0x80(%rbp)
movq -0x90(%rbp), %rdi
movslq -0x80(%rbp), %rsi
callq 0x31c0
movq %rax, -0x90(%rbp)
movb -0x81(%rbp), %dl
movq -0x90(%rbp), %rax
movl -0x7c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x7c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x39(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x71a0
movb %al, -0x81(%rbp)
jmp 0x76c5
movq -0x90(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
movq -0x90(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x39(%rbp), %r8
leaq -0x58(%rbp), %r9
callq 0x7a30
cmpl $0x0, %eax
jne 0x77b8
movl $0x1, 0xfd15(%rip)      # 0x174c8
jmp 0x73c0
movq -0x90(%rbp), %rdi
callq 0x3030
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movb -0x3a(%rbp), %al
movb %al, -0x39(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movb -0x39(%rbp), %al
movb %al, -0x3a(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
callq 0x3240
movq (%rax), %rax
movsbl -0x39(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x78a7
callq 0x3240
movq (%rax), %rax
movsbl -0x76(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x78a7
jmp 0x784c
callq 0x3240
movq (%rax), %rax
movsbl -0x39(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xb2(%rbp)
je 0x7882
movsbl -0x39(%rbp), %eax
cmpl $0xa, %eax
setne %al
movb %al, -0xb2(%rbp)
movb -0xb2(%rbp), %al
testb $0x1, %al
jne 0x788e
jmp 0x78a5
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x39(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x71a0
jmp 0x784c
jmp 0x78a7
movl $0x0, -0xac(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, 0x8(%rax)
jne 0x7950
movsbl -0x39(%rbp), %eax
cmpl $0x23, %eax
jne 0x7950
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x39(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x71a0
movsbl -0x39(%rbp), %eax
cmpl $0x23, %eax
jne 0x794e
movl $0x1, -0xac(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x39(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x71a0
callq 0x3240
movq (%rax), %rax
movsbl -0x39(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xb3(%rbp)
je 0x7942
movsbl -0x39(%rbp), %eax
cmpl $0xa, %eax
setne %al
movb %al, -0xb3(%rbp)
movb -0xb3(%rbp), %al
testb $0x1, %al
jne 0x78f7
jmp 0x794e
jmp 0x7950
cmpl $0x0, -0xac(%rbp)
je 0x7968
movl $0x1, 0xfb65(%rip)      # 0x174c8
jmp 0x73fb
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movb -0x3a(%rbp), %al
movb %al, -0x39(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x79af
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0x7a04
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, 0x8(%rax)
je 0x79e0
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x7a02
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq 0x28(%rcx), %rdx
movq %rdx, (%rax)
movq 0x30(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x38(%rcx), %rcx
movq %rcx, 0x10(%rax)
jmp 0x7a04
cmpl $0x0, -0x24(%rbp)
jne 0x7a14
movl $0x0, 0xfab4(%rip)      # 0x174c8
movb -0x39(%rbp), %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)