// File: fuzzythecat[P]SBK-Interpreter/sbk.cpp
// Function: TruncateFile(char const*, bool*)
char* TruncateFile(char const *text, bool *fin_flag)
{
	int idx = 0, size = strlen(text);
	char *file = (char*)malloc(sizeof(char) * size);
	bool comment_flag = false;
	char comment_char = '@';
	
	for(int i = 0; i < size; ++i)
	{
		if(comment_flag)
		{
			for(;i < size; ++i)
				if(text[i] == comment_char) 
				{ 
					comment_flag = false;
					break; 
				}	
		}
		else if(text[i] == comment_char)
			comment_flag = true;	
		else if(strncmp(text+i, "쌀", 3) == 0)
		{
			strncpy(file+idx, "0", 1);
			i += 2; idx++;
		}
		else if(strncmp(text+i, "콩", 3) == 0)
		{
			strncpy(file+idx, "|", 1);
			i += 2; idx++;
		}
		else if(strncmp(text+i, "보리", 6) == 0)
		{
			strncpy(file+idx, "1", 1);
			i += 5; idx ++;
		}
		else if(strncmp(text+i, "취사", 6) == 0)
		{
			*fin_flag = true;
			break;
		}
	}	

	file[idx] = '\0';

	return file;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2090
movl %eax, -0x18(%rbp)
movslq -0x18(%rbp), %rdi
shlq $0x0, %rdi
callq 0x21b0
movq %rax, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movb $0x40, -0x22(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x28a2
testb $0x1, -0x21(%rbp)
je 0x274b
jmp 0x2717
movl -0x28(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x2746
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x22(%rbp), %ecx
cmpl %ecx, %eax
jne 0x2739
movb $0x0, -0x21(%rbp)
jmp 0x2746
jmp 0x273b
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2717
jmp 0x2892
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x22(%rbp), %ecx
cmpl %ecx, %eax
jne 0x2768
movb $0x1, -0x21(%rbp)
jmp 0x2890
movq -0x8(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
leaq 0x28e9(%rip), %rsi      # 0x5063
movl $0x3, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0x27bc
movq -0x20(%rbp), %rdi
movslq -0x14(%rbp), %rax
addq %rax, %rdi
leaq 0x28cc(%rip), %rsi      # 0x5067
movl $0x1, %edx
callq 0x20b0
movl -0x28(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x28(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x288e
movq -0x8(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
leaq 0x289b(%rip), %rsi      # 0x5069
movl $0x3, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0x280d
movq -0x20(%rbp), %rdi
movslq -0x14(%rbp), %rax
addq %rax, %rdi
leaq 0x287e(%rip), %rsi      # 0x506d
movl $0x1, %edx
callq 0x20b0
movl -0x28(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x28(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x288c
movq -0x8(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
leaq 0x2850(%rip), %rsi      # 0x506f
movl $0x6, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0x285e
movq -0x20(%rbp), %rdi
movslq -0x14(%rbp), %rax
addq %rax, %rdi
leaq 0x2836(%rip), %rsi      # 0x5076
movl $0x1, %edx
callq 0x20b0
movl -0x28(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x28(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x288a
movq -0x8(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
leaq 0x2808(%rip), %rsi      # 0x5078
movl $0x6, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0x2888
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x28a2
jmp 0x288a
jmp 0x288c
jmp 0x288e
jmp 0x2890
jmp 0x2892
jmp 0x2894
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2703
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x20(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)