// File: /workspace/github_cpp_makefile_star2_O1/TsukiGva2[P]Blade-lang/blade.cpp
// Function: lc_eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::string lc_eval(std::string expr){
/* 
1. detect the innermost function [x]
2. call that function            [x]
3. return to 1                   [x]
*/

	std::cout << "got: " << expr << endl;
	FnPtr tempfun = err;
	std::string temp;
	std::string ufun;
	bool userfun = false;
    
	//       f a a
	// [ + [ - 9 9] 9 ]
	//   f   arg1  arg2	

	// so, it works like this
	//-         1 1 1     1 1 1
	//  [ [ [ [ ] ] ] [ [ ] ] ]
	//+ 1 1 1 1       1 1   
	//  you do + 1 for the opening parens
	//  and - 1 for the closing ones

	int acc = 0;
	std::map<int,int> depth_index;
	std::vector<int> depths;
	std::vector<std::string> args;

	bool instr = false;
	
	for (int i = 0; i < expr.size(); i++){
		if (expr[i] == '"') instr = !instr;

		if (expr[i] == '[' && !instr) {
			acc += 1;
			depths.push_back(acc);
		}

		else if (expr[i] == ']' && !instr) {
			acc -= 1;
			depths.push_back(acc);
		}

		if (depth_index.find(acc) == depth_index.end())
			depth_index[acc] = i;
	}

	if (instr) return "SYNTAX-ERROR: no matching double quote. err-unfinished-str";

	if (acc != 0){
		return "SYNTAX-ERROR: wrong number of brackets. err-unbalanced-brackets";
	}

	int maxd_index = depth_index[max_element(depths)];
	int replace_end = 0;

	for (int i = maxd_index+1; i < expr.size(); i++){
		if (expr[i] == ']' && !instr) {
			replace_end = i+1;
		}

		if (expr[i] == '"' && !instr){
			instr = true;
			continue;
		}

		if (!((expr[i] == ' ' && !instr && expr[i-1] != '"') || (expr[i] == '"' && instr) || (expr[i] == ']' && !instr))){ // XXX
			temp += expr[i];
		} else {
			if (!instr){
				std::remove(temp.begin(), temp.end(), ' ');
			}

			if (funcs_map.find(temp) != funcs_map.end() && !instr) tempfun = funcs_map[temp];
			else if (usfuns_map.find(temp) != usfuns_map.end() && !instr){
				ufun = temp;
				userfun = true;
			} else {
				if (vars.find(temp) != vars.end() && !instr) {
					args.push_back(vars[temp]);
				} else if (!temp.empty()){
					args.push_back(temp);
				}
			}

			instr = false;
			if (expr[i] == ']' && !instr) break;
			temp = "";
		}
	}
	std::string result;
	if (!userfun) result = tempfun(args);
	else {
		globl_args = args;
		result = lc_eval(usfuns_map[ufun]);
	}

	if (max_element(depths) < 2) return result;
	
	// else
	
	return lc_eval(replace_str(expr,maxd_index,replace_end,result));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rsi, %r14
movq %rdi, -0x38(%rbp)
leaq 0x108215(%rip), %r15    # 0x120980
leaq 0xc19bf(%rip), %rsi     # 0xda131
movl $0x5, %edx
movq %r15, %rdi
callq 0x97cf0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r15, %rdi
callq 0x97cf0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x78e40
movsbl %al, %esi
movq %r15, %rdi
callq 0x977f0
movq %rax, %rdi
callq 0x96dc0
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
xorl %ebx, %ebx
movq %rbx, -0x8(%rax)
movb %bl, (%rax)
leaq -0xf8(%rbp), %rax
movq %rax, -0x10(%rax)
movq %rbx, -0x8(%rax)
movb %bl, (%rax)
movl %ebx, -0x2c(%rbp)
leaq -0x200(%rbp), %r13
movl %ebx, (%r13)
movq %rbx, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %rbx, 0x20(%r13)
movq %rbx, -0x70(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movq %rbx, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
cmpq %rbx, 0x8(%r14)
je 0x188e5
xorl %r15d, %r15d
leaq -0x2c(%rbp), %r12
xorl %ebx, %ebx
movl %ebx, %ecx
movq (%r14), %rax
movzbl (%rax,%r15), %eax
cmpl $0x22, %eax
sete %bl
xorb %cl, %bl
cmpl $0x5b, %eax
je 0x1884b
cmpl $0x5d, %eax
jne 0x18880
testb $0x1, %bl
jne 0x18880
movl -0x2c(%rbp), %eax
decl %eax
jmp 0x1885b
testb $0x1, %bl
je 0x18856
cmpb $0x5d, %al
je 0x1883f
jmp 0x18880
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
movq -0x78(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0x18874
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x78(%rbp)
jmp 0x18880
leaq -0x80(%rbp), %rdi
movq %r12, %rdx
callq 0x27128
movq -0x1f8(%rbp), %rcx
movq %r13, %rax
testq %rcx, %rcx
je 0x188ac
movl -0x2c(%rbp), %edx
movq %r13, %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x18895
movq %r13, %rcx
cmpq %r13, %rax
je 0x188c1
movl -0x2c(%rbp), %ecx
cmpl 0x20(%rax), %ecx
cmovlq %r13, %rax
movq %rax, %rcx
cmpq %r13, %rcx
jne 0x188d8
leaq -0x208(%rbp), %rdi
movq %r12, %rsi
callq 0x1b352
movl %r15d, (%rax)
incq %r15
cmpq %r15, 0x8(%r14)
ja 0x18823
testb $0x1, %bl
je 0x18910
movq -0x38(%rbp), %r15
leaq 0x10(%r15), %rax
movq %rax, (%r15)
leaq 0xc183b(%rip), %rsi     # 0xda137
leaq 0xc186e(%rip), %rdx     # 0xda171
movq %r15, %rdi
callq 0x1bccc
jmp 0x18e4d
cmpl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %r15
je 0x1893c
leaq 0x10(%r15), %rax
movq %rax, (%r15)
leaq 0xc184a(%rip), %rsi     # 0xda172
leaq 0xc1882(%rip), %rdx     # 0xda1b1
movq %r15, %rdi
callq 0x1bccc
jmp 0x18e4d
leaq -0xe8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x1b422
movq -0xe8(%rbp), %rcx
movq -0xe0(%rbp), %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
je 0x1896e
movl (%rcx), %esi
cmpl %eax, %esi
cmovgl %esi, %eax
addq $0x4, %rcx
jmp 0x1895c
leaq -0xa0(%rbp), %rsi
movl %eax, (%rsi)
leaq -0x208(%rbp), %rdi
callq 0x1b3ba
movl (%rax), %r12d
movslq %r12d, %r15
movq -0xe8(%rbp), %rdi
testq %rdi, %rdi
je 0x189a4
movq -0xd8(%rbp), %rsi
subq %rdi, %rsi
callq 0x2b980
incq %r15
cmpq %r15, 0x8(%r14)
movl %r12d, -0xa4(%rbp)
jbe 0x18b69
movl $0x0, -0x3c(%rbp)
leaq -0x37c(%rip), %rax      # 0x1864a
movq %rax, -0xb0(%rbp)
movl %r12d, %r13d
xorl %r12d, %r12d
movl %r12d, %edx
movq (%r14), %rcx
movb (%rcx,%r15), %al
leal 0x2(%r13), %r12d
testb $0x1, %bl
cmovnel %edx, %r12d
cmpb $0x5d, %al
cmovnel %edx, %r12d
cmpb $0x22, %al
jne 0x189fe
testb $0x1, %bl
jne 0x189fe
movb $0x1, %bl
jmp 0x18b4d
cmpb $0x20, %al
jne 0x18a10
testb $0x1, %bl
jne 0x18a10
movslq %r13d, %rdx
cmpb $0x22, (%rcx,%rdx)
jne 0x18a40
cmpb $0x22, %al
setne %dl
cmpb $0x5d, %al
setne %cl
movl %ebx, %esi
notb %sil
orb %dl, %sil
testb $0x1, %sil
je 0x18a40
orb %bl, %cl
testb $0x1, %cl
je 0x18a40
movsbl %al, %esi
leaq -0x60(%rbp), %rdi
callq 0xa8c10
jmp 0x18b4d
testb $0x1, %bl
jne 0x18a63
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq %rdi, %rsi
movb $0x20, -0xa0(%rbp)
leaq -0xa0(%rbp), %rdx
callq 0x27523
leaq 0x106ea6(%rip), %rdi    # 0x11f910
leaq -0x60(%rbp), %rsi
callq 0x27600
leaq 0x106e9e(%rip), %rcx    # 0x11f918
cmpq %rcx, %rax
je 0x18aa3
testb $0x1, %bl
jne 0x18aa3
leaq 0x106e85(%rip), %rdi    # 0x11f910
leaq -0x60(%rbp), %rsi
callq 0x1b4a2
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
jmp 0x18b28
leaq 0x106e96(%rip), %rdi    # 0x11f940
leaq -0x60(%rbp), %rsi
callq 0x279c8
leaq 0x106e8e(%rip), %rcx    # 0x11f948
cmpq %rcx, %rax
je 0x18adb
testb $0x1, %bl
jne 0x18adb
movb $0x1, %al
movl %eax, -0x3c(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xa81b0
jmp 0x18b28
leaq 0x106ea6(%rip), %rdi    # 0x11f988
leaq -0x60(%rbp), %rsi
callq 0x279c8
leaq 0x106e9e(%rip), %rcx    # 0x11f990
cmpq %rcx, %rax
je 0x18b0e
testb $0x1, %bl
jne 0x18b0e
leaq 0x106e85(%rip), %rdi    # 0x11f988
leaq -0x60(%rbp), %rsi
callq 0x1b56e
jmp 0x18b19
cmpq $0x0, -0x58(%rbp)
leaq -0x60(%rbp), %rax
je 0x18b28
leaq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0x1b522
movq (%r14), %rax
cmpb $0x5d, (%rax,%r15)
je 0x18b5d
xorl %ebx, %ebx
movq -0x58(%rbp), %rdx
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
leaq 0xc1827(%rip), %rcx     # 0xda36c
xorl %r8d, %r8d
callq 0xa91d0
incq %r15
incl %r13d
cmpq %r15, 0x8(%r14)
ja 0x189d3
movq -0xb0(%rbp), %rbx
movl -0x3c(%rbp), %eax
jmp 0x18b75
leaq -0x526(%rip), %rbx      # 0x1864a
xorl %r12d, %r12d
xorl %eax, %eax
leaq -0x90(%rbp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
testb $0x1, %al
je 0x18c40
leaq 0x106dd4(%rip), %rdi    # 0x11f970
leaq -0xd0(%rbp), %rsi
callq 0x1b682
leaq 0x106d91(%rip), %rdi    # 0x11f940
leaq -0x108(%rbp), %rsi
callq 0x1b56e
leaq -0x178(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x188(%rbp), %rdi
callq 0x1bc32
leaq -0x128(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x18749
leaq -0xa0(%rbp), %rdi
leaq -0x128(%rbp), %r15
movq %r15, %rsi
callq 0xa85d0
movq (%r15), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x18c23
movq -0x118(%rbp), %rsi
incq %rsi
callq 0x2b980
movq -0x188(%rbp), %rdi
cmpq %rbx, %rdi
je 0x18ca3
movq -0x178(%rbp), %rsi
incq %rsi
callq 0x2b980
jmp 0x18ca3
leaq -0x1d8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1b5ee
leaq -0x128(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq *%rbx
leaq -0xa0(%rbp), %rdi
leaq -0x128(%rbp), %r15
movq %r15, %rsi
callq 0xa85d0
movq (%r15), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x18c97
movq -0x118(%rbp), %rsi
incq %rsi
callq 0x2b980
leaq -0x1d8(%rbp), %rdi
callq 0x1b252
leaq -0x1c0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x1b422
movq -0x1c0(%rbp), %rdi
movq -0x1b8(%rbp), %rax
cmpq %rax, %rdi
je 0x18ce7
xorl %ecx, %ecx
movq %rdi, %rdx
movq -0x38(%rbp), %r15
movl (%rdx), %esi
cmpl %ecx, %esi
cmovgl %esi, %ecx
addq $0x4, %rdx
cmpq %rax, %rdx
jne 0x18ccf
cmpl $0x2, %ecx
setl %bl
jmp 0x18ced
movb $0x1, %bl
movq -0x38(%rbp), %r15
testq %rdi, %rdi
je 0x18d01
movq -0x1b0(%rbp), %rsi
subq %rdi, %rsi
callq 0x2b980
testb %bl, %bl
je 0x18d2f
leaq 0x10(%r15), %rax
movq %rax, (%r15)
movq -0xa0(%rbp), %rcx
cmpq %r13, %rcx
je 0x18e06
movq %rcx, (%r15)
movq -0x90(%rbp), %rax
movq %rax, 0x10(%r15)
jmp 0x18e0e
leaq -0x158(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x168(%rbp), %rdi
callq 0x1bc32
leaq -0x138(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
addq %rsi, %rdx
leaq -0x148(%rbp), %rdi
callq 0x1bc32
leaq -0x1a8(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x148(%rbp), %r8
movl -0xa4(%rbp), %edx
movl %r12d, %ecx
callq 0x18677
leaq -0x1a8(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x18749
leaq -0x198(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x18dca
movq -0x198(%rbp), %rsi
incq %rsi
callq 0x2b980
movq -0x148(%rbp), %rdi
cmpq %r14, %rdi
je 0x18de5
movq -0x138(%rbp), %rsi
incq %rsi
callq 0x2b980
movq -0x168(%rbp), %rdi
cmpq %r15, %rdi
movq -0x38(%rbp), %r15
je 0x18e32
movq -0x158(%rbp), %rsi
incq %rsi
callq 0x2b980
jmp 0x18e32
movups (%r13), %xmm0
movups %xmm0, (%rax)
movq -0x98(%rbp), %rax
movq %rax, 0x8(%r15)
movq %r13, -0xa0(%rbp)
movq $0x0, -0x98(%rbp)
movb $0x0, -0x90(%rbp)
movq -0xa0(%rbp), %rdi
cmpq %r13, %rdi
je 0x18e4d
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2b980
leaq -0xd0(%rbp), %rdi
callq 0x1b252
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x18e6e
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x2b980
leaq -0x208(%rbp), %rdi
callq 0x1ba32
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x18e9c
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x2b980
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x18eb5
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2b980
movq %r15, %rax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
leaq -0x198(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x18ef1
movq -0x198(%rbp), %rsi
incq %rsi
callq 0x2b980
jmp 0x18ef1
movq %rax, %r12
movq -0x148(%rbp), %rdi
cmpq %r14, %rdi
je 0x18f11
movq -0x138(%rbp), %rsi
incq %rsi
callq 0x2b980
jmp 0x18f11
movq %rax, %r12
movq -0x168(%rbp), %rdi
cmpq %r15, %rdi
je 0x18f83
movq -0x158(%rbp), %rsi
jmp 0x18f3c
movq %rax, %r12
movq -0x188(%rbp), %rdi
cmpq %rbx, %rdi
je 0x18f83
movq -0x178(%rbp), %rsi
incq %rsi
callq 0x2b980
jmp 0x18f83
movq %rax, %r12
leaq -0x1d8(%rbp), %rdi
callq 0x1b252
jmp 0x18f83
jmp 0x18f80
jmp 0x18fa6
jmp 0x18f80
movq %rax, %r12
movq -0xe8(%rbp), %rdi
testq %rdi, %rdi
je 0x18fa9
movq -0xd8(%rbp), %rsi
subq %rdi, %rsi
jmp 0x18f99
jmp 0x18fa6
jmp 0x18fa6
jmp 0x18fa6
jmp 0x18fa6
movq %rax, %r12
movq -0xa0(%rbp), %rdi
cmpq %r13, %rdi
je 0x18fa9
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2b980
jmp 0x18fa9
jmp 0x18fa6
jmp 0x18fa6
jmp 0x18fa6
movq %rax, %r12
leaq -0xd0(%rbp), %rdi
callq 0x1b252
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x18fca
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x2b980
leaq -0x208(%rbp), %rdi
callq 0x1ba32
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x18ff8
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x2b980
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x19011
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2b980
movq %r12, %rdi
callq 0xd6fc0