// File: /workspace/github_cpp_makefile_star2_O1/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 0x20(%rdi), %rax
movq %rdi, -0x68(%rbp)
cmpq %rax, 0x28(%rdi)
je 0x9f4d
movq %rsi, %r15
xorl %ebx, %ebx
movq %rsi, -0x60(%rbp)
movq (%rax,%rbx,8), %r14
cmpq $0x0, 0x68(%r14)
je 0x9f2e
leaq 0x60(%r14), %rax
movq %rax, -0x38(%rbp)
movl $0x6, %edx
movq %r15, %rdi
leaq 0x3c98(%rip), %rsi      # 0xd863
callq 0x32b0
movq %r15, %rdi
movq %rbx, -0x70(%rbp)
movl %ebx, %esi
callq 0x33b0
movq %rax, %rbx
movl $0x4, %edx
movq %rax, %rdi
leaq 0x3c7a(%rip), %rsi      # 0xd86a
callq 0x32b0
movq 0x80(%r14), %rsi
movq 0x88(%r14), %rdx
movq %rbx, %rdi
callq 0x32b0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x3c52(%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
cmpq $0x0, 0x18(%r14)
movq %r14, %rcx
movq %r14, -0x30(%rbp)
je 0x9d16
xorl %r14d, %r14d
cmpq 0x68(%rcx), %r14
jae 0x9d16
movq 0x10(%rcx), %rsi
movq 0x18(%rcx), %rcx
movq -0x38(%rbp), %rdi
movq %r14, %rdx
callq 0x33c0
movq %rax, %r12
cmpq $-0x1, %rax
sete %al
cmpq %r12, %r14
sete %bl
orb %al, %bl
jne 0x9d0a
testq %r12, %r12
je 0x9cbc
movq -0x38(%rbp), %rax
movq (%rax), %rax
movsbl -0x1(%rax,%r12), %edi
callq 0x3350
testl %eax, %eax
je 0x9cbc
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
leaq (%r12,%rax), %r14
decq %r14
jmp 0x9d0a
movq -0x30(%rbp), %r13
movq 0x68(%r13), %rax
decq %rax
cmpq %rax, %r12
jae 0x9ced
movq 0x18(%r13), %r15
addq %r12, %r15
movq 0x60(%r13), %rax
movsbl (%rax,%r15), %edi
callq 0x3350
testl %eax, %eax
je 0x9ced
decq %r15
movq %r15, %r14
jmp 0x9d0a
movq 0x18(%r13), %rdx
movl $0x2, %r8d
movq -0x38(%rbp), %rdi
movq %r12, %rsi
leaq 0x3b6e(%rip), %rcx      # 0xd873
callq 0x3290
testb %bl, %bl
movq -0x30(%rbp), %rcx
je 0x9c5e
movq 0x48(%rcx), %r13
cmpq %r13, 0x50(%rcx)
je 0x9eb1
xorl %r14d, %r14d
movq %r14, %rbx
shlq $0x5, %rbx
cmpq $0x0, 0x8(%r13,%rbx)
je 0x9e92
leaq -0x200(%rbp), %rdi
callq 0x3190
movl $0x3, %edx
leaq -0x1f0(%rbp), %rdi
leaq 0x3b1d(%rip), %rsi      # 0xd876
callq 0x32b0
leaq -0x1f0(%rbp), %rdi
movl %r14d, %esi
callq 0x33b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x385c(%rip), %rsi      # 0xd5d8
callq 0x32b0
movq %r14, -0x78(%rbp)
addq %rbx, %r13
xorl %r14d, %r14d
movq -0x30(%rbp), %rbx
cmpq 0x68(%rbx), %r14
jae 0x9e6f
movq (%r13), %rsi
movq 0x8(%r13), %rcx
movq -0x38(%rbp), %rdi
movq %r14, %rdx
callq 0x33c0
movq %rax, %r12
cmpq $-0x1, %rax
sete %al
cmpq %r12, %r14
sete %r15b
orb %al, %r15b
jne 0x9e66
testq %r12, %r12
je 0x9def
movq -0x38(%rbp), %rax
movq (%rax), %rax
movsbl -0x1(%rax,%r12), %edi
callq 0x3350
testl %eax, %eax
je 0x9def
movq 0x8(%r13), %rax
leaq (%r12,%rax), %r14
decq %r14
jmp 0x9e66
movq 0x68(%rbx), %rax
decq %rax
cmpq %rax, %r12
jae 0x9e1e
movq 0x8(%r13), %rbx
addq %r12, %rbx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movsbl (%rax,%rbx), %edi
callq 0x3350
testl %eax, %eax
je 0x9e1e
decq %rbx
movq %rbx, %r14
jmp 0x9e62
movq 0x8(%r13), %rbx
leaq -0x58(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x3340
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x38(%rbp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3290
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x9e62
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x3260
movq -0x30(%rbp), %rbx
testb %r15b, %r15b
je 0x9d8f
leaq -0x200(%rbp), %rdi
movq 0x713b(%rip), %rsi      # 0x10fb8
callq 0x31b0
leaq -0x180(%rbp), %rdi
callq 0x30c0
movq -0x78(%rbp), %r14
incq %r14
movq -0x30(%rbp), %rcx
movq 0x48(%rcx), %r13
movq 0x50(%rcx), %rax
subq %r13, %rax
sarq $0x5, %rax
cmpq %r14, %rax
ja 0x9d27
movq 0x60(%rcx), %rsi
movq 0x68(%rcx), %rdx
movq -0x60(%rbp), %r15
movq %r15, %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 %r15, %rdi
leaq 0x397c(%rip), %rsi      # 0xd87a
callq 0x32b0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq -0x70(%rbp), %rbx
incq %rbx
movq -0x68(%rbp), %rcx
movq 0x20(%rcx), %rax
movq 0x28(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0x9ba5
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9f7f
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x9f82
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x3260
jmp 0x9f82
movq %rax, %rbx
movq 0x702f(%rip), %rsi      # 0x10fb8
leaq -0x200(%rbp), %rdi
callq 0x31b0
leaq -0x180(%rbp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x33d0
nop