// File: /workspace/github_c_makefile_star2_O2/Yamsman[P]scc/src/lex.c
// Function: lex_eschar
char lex_eschar(lexer *lx) {
	//Simple escape characters
	s_pos loc = lx->tgt->loc;
	switch (lex_cur(lx)) {
		case '\'': lex_advc(lx); return '\'';
		case '\"': lex_advc(lx); return '\"';
		case '\?': lex_advc(lx); return '\?';
		case '\\': lex_advc(lx); return '\\';
		case 'a':  lex_advc(lx); return '\a';
		case 'b':  lex_advc(lx); return '\b';
		case 'f':  lex_advc(lx); return '\f';
		case 'n':  lex_advc(lx); return '\n';
		case 'r':  lex_advc(lx); return '\r';
		case 't':  lex_advc(lx); return '\t';
		case 'v':  lex_advc(lx); return '\v';
	}

	//Number escape character
	char cur = lex_cur(lx);
	unsigned int val = 0;
	if (cur == 'x') {
		//Hexadecimal
		cur = lex_advc(lx);
		if (!isxdigit(cur)) {
			c_warn(&loc, "\\x escape character without hexadecimal digits\n");
			return 0;
		}

		//Read number and check range
		while (isxdigit(cur)) {
			int dval = (!isdigit(cur)) ? 10 + (tolower(cur) - 'a') : (cur - '0');
			val = (val * 16) + dval;
			cur = lex_advc(lx);
		}
		if (val > 0xFF)
			c_warn(&loc, "hexadecimal escape char out of range\n");
	} else if (isdigit(cur) && cur != '8' && cur != '9') {
		//Octal
		//Read number
		while (isdigit(cur) && cur != '8' && cur != '9') {
			val = (val * 8) + (cur - '0');
			cur = lex_advc(lx);
		}

		//Check range
		if (val > 0377)
			c_warn(&loc, "octal escape char out of range\n");
	}

	return val;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x38(%rax), %rcx
movq %rcx, 0x10(%rsp)
movups 0x28(%rax), %xmm0
movaps %xmm0, (%rsp)
callq 0x6493
movzbl %al, %eax
leal -0x6e(%rax), %ecx
cmpl $0x8, %ecx
jbe 0x6aa5
cmpl $0x22, %eax
je 0x6b5b
cmpl $0x66, %eax
je 0x6b8b
cmpl $0x3f, %eax
je 0x6b3b
cmpl $0x5c, %eax
je 0x6b4b
cmpl $0x61, %eax
je 0x6b6b
cmpl $0x62, %eax
je 0x6b7b
cmpl $0x27, %eax
jne 0x6ac5
movq %rbx, %rdi
callq 0x64ad
movb $0x27, %r14b
jmp 0x6c87
leaq 0x5df8(%rip), %rax      # 0xc8a4
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rbx, %rdi
callq 0x64ad
movb $0xa, %r14b
jmp 0x6c87
movq %rbx, %rdi
callq 0x6493
cmpb $0x78, %al
jne 0x6b9b
movq %rbx, %rdi
callq 0x64ad
movl %eax, %ebp
callq 0x3230
movq %rax, %r15
movq (%rax), %rax
movsbq %bpl, %rcx
movzwl (%rax,%rcx,2), %eax
btl $0xc, %eax
jb 0x6c0f
leaq 0x623b(%rip), %rsi      # 0xcd3e
xorl %r14d, %r14d
jmp 0x6c7d
movq %rbx, %rdi
callq 0x64ad
movb $0x9, %r14b
jmp 0x6c87
movq %rbx, %rdi
callq 0x64ad
movb $0xd, %r14b
jmp 0x6c87
movq %rbx, %rdi
callq 0x64ad
movb $0xb, %r14b
jmp 0x6c87
movq %rbx, %rdi
callq 0x64ad
movb $0x3f, %r14b
jmp 0x6c87
movq %rbx, %rdi
callq 0x64ad
movb $0x5c, %r14b
jmp 0x6c87
movq %rbx, %rdi
callq 0x64ad
movb $0x22, %r14b
jmp 0x6c87
movq %rbx, %rdi
callq 0x64ad
movb $0x7, %r14b
jmp 0x6c87
movq %rbx, %rdi
callq 0x64ad
movb $0x8, %r14b
jmp 0x6c87
movq %rbx, %rdi
callq 0x64ad
movb $0xc, %r14b
jmp 0x6c87
movl %eax, %r12d
callq 0x3230
movq %rax, %r15
leal -0x3a(%r12), %eax
xorl %r14d, %r14d
cmpb $-0x3, %al
ja 0x6c87
movq (%r15), %rax
movsbq %r12b, %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, %ecx
andl $0x800, %ecx            # imm = 0x800
je 0x6c87
xorl %r14d, %r14d
leal -0x3a(%r12), %ecx
cmpb $-0x3, %cl
ja 0x6c6d
andl $0x800, %eax            # imm = 0x800
je 0x6c6d
movsbl %r12b, %eax
leal (%rax,%r14,8), %r14d
addl $-0x30, %r14d
movq %rbx, %rdi
callq 0x64ad
movl %eax, %r12d
movq (%r15), %rax
movsbq %r12b, %rcx
movzwl (%rax,%rcx,2), %eax
jmp 0x6bd2
xorl %r14d, %r14d
movzwl %ax, %eax
btl $0xc, %eax
jae 0x6c5b
btl $0xb, %eax
jb 0x6c36
movsbq %bpl, %r12
callq 0x3220
movq (%rax), %rax
movl (%rax,%r12,4), %eax
addl $-0x57, %eax
jmp 0x6c3d
movsbl %bpl, %eax
addl $-0x30, %eax
shll $0x4, %r14d
addl %eax, %r14d
movq %rbx, %rdi
callq 0x64ad
movl %eax, %ebp
movq (%r15), %rax
movsbq %bpl, %rcx
movzwl (%rax,%rcx,2), %eax
jmp 0x6c12
cmpl $0xff, %r14d
jbe 0x6c87
leaq 0x6103(%rip), %rsi      # 0xcd6e
jmp 0x6c7d
cmpl $0x100, %r14d           # imm = 0x100
jb 0x6c87
leaq 0x6117(%rip), %rsi      # 0xcd94
movq %rsp, %rdi
xorl %eax, %eax
callq 0x36cc
movl %r14d, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq