// File: /workspace/github_cpp_makefile_star2_O3/kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::emit_cxx_file()
void xbytes::emit_cxx_file()
{
	//open output file
	std::ofstream ofs;
	ofs.open("PARSER.cxx", std::ofstream::out);

	//open template file
	std::ifstream ifs;
	ifs.open("TEMPLATE.cxx", std::ifstream::in);

	//copy data
	string line;
	while(ifs.good())
	{
		line.clear();
		getline(ifs, line);

		if(line.size() == 0)
		{
			ofs << std::endl;
			continue;
		}
		
		if(line[0] == '%' && line[1] == '%')
		{
			string keyword;
			for(int i = 2; i < line.size(); ++i)
			{
				if(line[i] == '%') break;
				keyword.push_back(line[i]);
			}

			if(keyword == "DECLARE_SYMBOL_TABLE")
			{
				output_symbol_table(ofs);
			}
			else if(keyword == "DECLARE_RULE_TABLE")
			{
				output_rule_table(ofs);
			}
			else if(keyword == "DECLARE_ACTION_TABLE")
			{
				output_action_table(ofs);
			}
			else if(keyword == "DECLARE_REDUCE_CODE")
			{
				output_reduce_code(ofs);
			}
			else if(keyword == "DECLARE_SYNTAX_ERROR_CODE")
			{
				if(syntax_error_code.size() > 0)
					ofs << syntax_error_code << std::endl;
			}

			continue;
		}

		ofs << line << std::endl;	
	}

	ifs.close();
	ofs.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rdi, -0x30(%rbp)
leaq -0x478(%rbp), %rbx
movq %rbx, %rdi
callq 0x33a0
leaq 0x786f(%rip), %rsi      # 0xd921
movq %rbx, %rdi
movl $0x10, %edx
callq 0x3040
leaq -0x278(%rbp), %rdi
callq 0x32a0
leaq 0x785a(%rip), %rsi      # 0xd92c
leaq -0x278(%rbp), %r15
movq %r15, %rdi
movl $0x8, %edx
callq 0x3140
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq -0x278(%rbp), %rax
movq -0x18(%rax), %rcx
cmpl $0x0, -0x258(%rbp,%rcx)
je 0x6197
leaq -0x278(%rbp), %rdi
callq 0x3070
leaq -0x478(%rbp), %rdi
callq 0x32e0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6143
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3260
leaq -0x278(%rbp), %rdi
callq 0x3080
movq 0xae7a(%rip), %rax      # 0x10fd0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x470(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x478(%rbp,%rcx)
callq 0x31e0
leaq -0x380(%rbp), %rdi
callq 0x30c0
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $-0x18, %rax
leaq -0x50(%rbp), %r12
leaq -0x70(%rbp), %r13
movq $0x0, -0x48(%rbp)
movq -0x50(%rbp), %rcx
movb $0x0, (%rcx)
movq (%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x33f0
movq -0x48(%rbp), %rdx
testq %rdx, %rdx
je 0x631e
movq -0x50(%rbp), %rsi
cmpb $0x25, (%rsi)
jne 0x62fd
cmpb $0x25, 0x1(%rsi)
jne 0x62fd
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movb $0x0, -0x60(%rbp)
cmpq $0x3, %rdx
jb 0x6234
movl $0x2, %r14d
movq -0x50(%rbp), %rax
movb (%rax,%r14), %al
cmpb $0x25, %al
je 0x6234
movsbl %al, %esi
movq %r13, %rdi
callq 0x31f0
incq %r14
cmpq %r14, -0x48(%rbp)
ja 0x6214
movq %r13, %rdi
leaq 0x76fb(%rip), %rsi      # 0xd939
callq 0x30a0
testl %eax, %eax
je 0x636e
movq %r13, %rdi
leaq 0x76f9(%rip), %rsi      # 0xd94e
callq 0x30a0
testl %eax, %eax
je 0x637c
movq %r13, %rdi
leaq 0x76f5(%rip), %rsi      # 0xd961
callq 0x30a0
testl %eax, %eax
je 0x638a
movq %r13, %rdi
leaq 0x76f3(%rip), %rsi      # 0xd976
callq 0x30a0
testl %eax, %eax
je 0x6398
movq %r13, %rdi
leaq 0x76f0(%rip), %rsi      # 0xd98a
callq 0x30a0
testl %eax, %eax
jne 0x63a4
movq -0x30(%rbp), %rax
movq 0x98(%rax), %rdx
testq %rdx, %rdx
je 0x63a4
movq -0x30(%rbp), %rax
movq 0x90(%rax), %rsi
movq %rbx, %rdi
callq 0x32b0
movq %rax, %r14
movq (%rax), %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
jmp 0x63a4
movq %rbx, %rdi
callq 0x32b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
jmp 0x6339
movq -0x478(%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movq %rbx, %r14
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq -0x278(%rbp), %rax
movq -0x18(%rax), %rcx
addq $-0x18, %rax
cmpl $0x0, -0x258(%rbp,%rcx)
je 0x61a3
jmp 0x6112
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x9534
jmp 0x63a4
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x9632
jmp 0x63a4
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x98a8
jmp 0x63a4
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x9b30
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x634c
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3260
jmp 0x634c
movq %rax, %rbx
jmp 0x6409
jmp 0x63c6
movq %rax, %rbx
jmp 0x6415
jmp 0x63cf
jmp 0x63ed
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x63f0
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3260
jmp 0x63f0
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6409
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3260
leaq -0x278(%rbp), %rdi
callq 0x3080
leaq -0x478(%rbp), %rdi
callq 0x3300
movq %rbx, %rdi
callq 0x33d0
nop