// File: /workspace/github_cpp_makefile_star2_O3/kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::output_reduce_code(std::basic_ofstream<char, std::char_traits<char>>&)
void xbytes::output_reduce_code(std::ofstream& ss)
{
	for(int i = 0; i < rules.size(); ++i)
	{
		rule* r = rules[i];
		if(r->code.size() == 0) continue;
		ss << "	case " << i << ":/* "  << r->str_rule << " */" << std::endl;

		string& code = r->code;

		//生成左边符号代码
		string& la = r->left_alias;
		if(la.size() > 0)
		{
			std::size_t spos = 0;
			while(spos < code.size())
			{
				std::size_t pos = code.find(la, spos);
				
				if(pos == std::string::npos) break;
				if(spos == pos) break;
				if(pos > 0 && isalpha(code[pos-1]))
				{
					spos = pos + la.size() - 1;
					continue;
				}
				if(pos < code.size() - 1 && isalpha(code[pos + la.size()]))
				{
					spos = pos + la.size() - 1;
					continue;
				}

				code.replace(pos, la.size(), "tt");
			}
		}

		//生成右边符号代码
		for(int m = 0; m < r->right_alias.size(); ++m)
		{
			string& ra = r->right_alias[m];
			if(ra.size() == 0) continue;

			std::stringstream ss;
			ss << "tv[" << m << "]";

			std::size_t spos = 0;
			while(spos < code.size())
			{
				std::size_t pos = code.find(ra, spos);

				if(pos == std::string::npos) break;
				if(spos == pos) break;
				if(pos > 0 && isalpha(code[pos-1]))
				{
					spos = pos + ra.size() - 1;
					continue;
				}
				if(pos < code.size() - 1 && isalpha(code[pos + ra.size()]))
				{
					spos = pos + ra.size() - 1;
					continue;
				}

				code.replace(pos, ra.size(), ss.str());
			}
		}

		ss << r->code << std::endl;
		ss << "	break;\n" << std::endl;
	}	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, -0x40(%rbp)
movq 0x20(%rdi), %rax
movq %rdi, -0x68(%rbp)
movq 0x28(%rdi), %rcx
cmpq %rax, %rcx
je 0x9f27
leaq -0x1f0(%rbp), %r12
xorl %r14d, %r14d
movq (%rax,%r14,8), %r15
cmpq $0x0, 0x68(%r15)
je 0x9f11
leaq 0x60(%r15), %rax
movq %rax, -0x38(%rbp)
movl $0x6, %edx
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
leaq 0x3cd2(%rip), %rsi      # 0xd863
callq 0x32b0
movq %rbx, %rdi
movq %r14, -0x70(%rbp)
movl %r14d, %esi
callq 0x33b0
movq %rax, %rbx
movl $0x4, %edx
movq %rax, %rdi
leaq 0x3cb3(%rip), %rsi      # 0xd86a
callq 0x32b0
movq 0x80(%r15), %rsi
movq 0x88(%r15), %rdx
movq %rbx, %rdi
callq 0x32b0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x3c8b(%rip), %rsi      # 0xd86f
callq 0x32b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq %r15, -0x30(%rbp)
cmpq $0x0, 0x18(%r15)
je 0x9ceb
movq -0x30(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x9ceb
xorl %ebx, %ebx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %rdi
movq %rbx, %rdx
callq 0x33c0
cmpq $-0x1, %rax
je 0x9ceb
movq %rax, %r15
cmpq %rax, %rbx
je 0x9ceb
testq %r15, %r15
je 0x9c8a
movq -0x38(%rbp), %rax
movq (%rax), %rax
movsbl -0x1(%rax,%r15), %edi
callq 0x3350
testl %eax, %eax
je 0x9c8a
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rax
leaq (%r15,%rax), %rbx
decq %rbx
jmp 0x9ce1
movq -0x30(%rbp), %rax
movq 0x18(%rax), %r14
movq 0x68(%rax), %rax
decq %rax
cmpq %rax, %r15
jae 0x9cc1
movq %r15, %r13
addq %r14, %r13
movq -0x38(%rbp), %rax
movq (%rax), %rax
movsbl (%rax,%r13), %edi
callq 0x3350
testl %eax, %eax
je 0x9cc1
decq %r13
movq %r13, %rbx
jmp 0x9cdd
movl $0x2, %r8d
movq -0x38(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
leaq 0x3b9b(%rip), %rcx      # 0xd873
callq 0x3290
movq -0x30(%rbp), %rcx
cmpq 0x68(%rcx), %rbx
jb 0x9c30
movq -0x30(%rbp), %r15
movq 0x48(%r15), %rbx
movq 0x50(%r15), %rax
cmpq %rbx, %rax
je 0x9e88
xorl %r13d, %r13d
movq %r13, %r14
shlq $0x5, %r14
cmpq $0x0, 0x8(%rbx,%r14)
je 0x9e72
leaq -0x200(%rbp), %rdi
callq 0x3190
movl $0x3, %edx
movq %r12, %rdi
leaq 0x3b45(%rip), %rsi      # 0xd876
callq 0x32b0
movq %r12, %rdi
movl %r13d, %esi
callq 0x33b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3888(%rip), %rsi      # 0xd5d8
callq 0x32b0
movq %r13, -0x78(%rbp)
cmpq $0x0, 0x68(%r15)
je 0x9e40
addq %r14, %rbx
xorl %r12d, %r12d
movq (%rbx), %rsi
movq 0x8(%rbx), %rcx
movq -0x38(%rbp), %rdi
movq %r12, %rdx
callq 0x33c0
cmpq $-0x1, %rax
je 0x9e40
movq %rax, %r13
cmpq %rax, %r12
je 0x9e40
testq %r13, %r13
je 0x9dbb
movq -0x38(%rbp), %rax
movq (%rax), %rax
movsbl -0x1(%rax,%r13), %edi
callq 0x3350
testl %eax, %eax
je 0x9dbb
movq 0x8(%rbx), %rax
leaq (%rax,%r13), %r12
decq %r12
jmp 0x9e36
movq 0x68(%r15), %rax
decq %rax
movq 0x8(%rbx), %r14
cmpq %rax, %r13
jae 0x9df2
movq %r13, %r15
addq %r14, %r15
movq -0x38(%rbp), %rax
movq (%rax), %rax
movsbl (%rax,%r15), %edi
callq 0x3350
testl %eax, %eax
je 0x9df2
decq %r15
movq %r15, %r12
movq -0x30(%rbp), %r15
jmp 0x9e36
leaq -0x60(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x3340
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %r8
movq -0x38(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x3290
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
movq -0x30(%rbp), %r15
je 0x9e36
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3260
cmpq 0x68(%r15), %r12
jb 0x9d6a
leaq -0x200(%rbp), %rdi
movq 0x716a(%rip), %rsi      # 0x10fb8
callq 0x31b0
leaq -0x180(%rbp), %rdi
callq 0x30c0
movq 0x48(%r15), %rbx
movq 0x50(%r15), %rax
leaq -0x1f0(%rbp), %r12
movq -0x78(%rbp), %r13
incq %r13
movq %rax, %rcx
subq %rbx, %rcx
sarq $0x5, %rcx
cmpq %r13, %rcx
ja 0x9d03
movq 0x60(%r15), %rsi
movq 0x68(%r15), %rdx
movq -0x40(%rbp), %r14
movq %r14, %rdi
callq 0x32b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movl $0x8, %edx
movq %r14, %rdi
leaq 0x39a5(%rip), %rsi      # 0xd87a
callq 0x32b0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq -0x68(%rbp), %rcx
movq 0x20(%rcx), %rax
movq 0x28(%rcx), %rcx
movq -0x70(%rbp), %r14
incq %r14
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r14, %rdx
ja 0x9b67
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9f59
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x9f5c
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3260
jmp 0x9f5c
movq %rax, %rbx
movq 0x7055(%rip), %rsi      # 0x10fb8
leaq -0x200(%rbp), %rdi
callq 0x31b0
leaq -0x180(%rbp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x33d0
nop