// File: iamlouk[P]asbi/src/main.cc
// Function: main
int main(int argc, const char *argv[]) {
	if (argc <= 1) {
		usage(argv[0]);
		exit(EXIT_FAILURE);
	}

	Context ctx;
	ctx.global_env->decl(ctx.names.__imports, Value::map(new MapContainer(&ctx)));

	for (int i = 1; i < argc; i++) {
		auto arg = argv[i];
		if (strcmp(arg, "--repl") == 0) {
			load_procenv(&ctx, argc, argv, i + 1);
			repl(ctx);
			break;
		} else if (strcmp(arg, "--eval") == 0 && i + 1 < argc) {
			std::string str = argv[++i];
			std::cout << ctx.run(str).to_string(true) << '\n';
		} else if (strcmp(arg, "--help") == 0) {
			usage(argv[0]);
#ifndef NDEBUG
		} else if (strcmp(arg, "--test") == 0) {
			tests::run();
#endif
		} else if (arg[0] != '-') {
			auto filepath = std::string(arg);
			filepath = utils::normalize(filepath);

			load_procenv(&ctx, argc, argv, i + 1);
			ctx.global_env->decl(ctx.names.__file, Value::string(filepath.c_str(), &ctx));
			ctx.global_env->decl(ctx.names.__main, Value::string(filepath.c_str(), &ctx));

			std::string content;
			utils::readfile(filepath, content);
			ctx.run(content);
			ctx.evtloop.start();
			break;
		} else {
			usage(argv[0]);
			exit(EXIT_FAILURE);
		}
	}

	return EXIT_SUCCESS;
}

// Assembly:
subq $0x758, %rsp            # imm = 0x758
movl $0x0, 0x754(%rsp)
movl %edi, 0x750(%rsp)
movq %rsi, 0x748(%rsp)
cmpl $0x1, 0x750(%rsp)
jg 0x6f45
movq 0x748(%rsp), %rax
movq (%rax), %rdi
callq 0x7610
movl $0x1, %edi
callq 0x6560
leaq 0x1e0(%rsp), %rdi
callq 0x26480
leaq 0x6d8(%rsp), %rdi
callq 0x7bd0
movq %rax, 0xb0(%rsp)
movq 0x728(%rsp), %rax
movq %rax, 0xb8(%rsp)
movl $0x68, %edi
callq 0x6460
movq %rax, 0xc0(%rsp)
jmp 0x6f8b
movq 0xc0(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x212d0
jmp 0x6fa2
movq 0xc0(%rsp), %rdi
callq 0x7be0
movq %rdx, 0xa0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x6fc0
movq 0xb8(%rsp), %rsi
movq 0xb0(%rsp), %rdi
movq 0xa0(%rsp), %rax
movl 0xac(%rsp), %ecx
movl %ecx, 0x1d0(%rsp)
movq %rax, 0x1d8(%rsp)
movl 0x1d0(%rsp), %edx
movq 0x1d8(%rsp), %rcx
callq 0x26220
jmp 0x7004
movl $0x1, 0x1c0(%rsp)
movl 0x1c0(%rsp), %eax
cmpl 0x750(%rsp), %eax
jge 0x75ce
movq 0x748(%rsp), %rax
movslq 0x1c0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rdi
leaq 0x30fb6(%rip), %rsi     # 0x38004
callq 0x6660
cmpl $0x0, %eax
jne 0x70d7
movl 0x750(%rsp), %esi
movq 0x748(%rsp), %rdx
movl 0x1c0(%rsp), %ecx
incl %ecx
leaq 0x1e0(%rsp), %rdi
callq 0x2cf70
jmp 0x707f
leaq 0x1e0(%rsp), %rdi
callq 0x76c0
jmp 0x708e
jmp 0x75ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x75f5
movq 0xc0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
movl $0x68, %esi
callq 0x6470
jmp 0x75f5
movq 0x1b8(%rsp), %rdi
leaq 0x30f25(%rip), %rsi     # 0x3800b
callq 0x6660
cmpl $0x0, %eax
jne 0x728e
movl 0x1c0(%rsp), %eax
addl $0x1, %eax
cmpl 0x750(%rsp), %eax
jge 0x728e
movq 0x748(%rsp), %rax
movslq 0x1c0(%rsp), %rcx
movl %ecx, %edx
incl %edx
movl %edx, 0x1c0(%rsp)
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0x90(%rsp)
leaq 0x197(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x67b0
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
leaq 0x198(%rsp), %rdi
callq 0x7c20
jmp 0x7167
leaq 0x197(%rsp), %rdi
callq 0x64c0
leaq 0x1e0(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x26be0
movq %rdx, 0x80(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0x719a
movq 0x80(%rsp), %rax
movl 0x8c(%rsp), %ecx
movl %ecx, 0x160(%rsp)
movq %rax, 0x168(%rsp)
leaq 0x170(%rsp), %rdi
leaq 0x160(%rsp), %rsi
movl $0x1, %edx
callq 0x220c0
jmp 0x71d4
movq 0x44dd5(%rip), %rdi     # 0x4bfb0
leaq 0x170(%rsp), %rsi
callq 0x63d0
movq %rax, 0x78(%rsp)
jmp 0x71ef
movq 0x78(%rsp), %rdi
movl $0xa, %esi
callq 0x6540
jmp 0x7200
leaq 0x170(%rsp), %rdi
callq 0x6290
leaq 0x198(%rsp), %rdi
callq 0x6290
jmp 0x75b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x197(%rsp), %rdi
callq 0x64c0
jmp 0x75f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x727c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x6290
leaq 0x198(%rsp), %rdi
callq 0x6290
jmp 0x75f5
movq 0x1b8(%rsp), %rdi
leaq 0x30d75(%rip), %rsi     # 0x38012
callq 0x6660
cmpl $0x0, %eax
jne 0x72be
movq 0x748(%rsp), %rax
movq (%rax), %rdi
callq 0x7610
jmp 0x72b9
jmp 0x75b2
movq 0x1b8(%rsp), %rdi
leaq 0x30d4c(%rip), %rsi     # 0x38019
callq 0x6660
cmpl $0x0, %eax
jne 0x72e3
callq 0x360f0
jmp 0x72de
jmp 0x75b0
movq 0x1b8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x7594
movq 0x1b8(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x13f(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x67b0
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
leaq 0x140(%rsp), %rdi
callq 0x7c20
jmp 0x732f
leaq 0x13f(%rsp), %rdi
callq 0x64c0
leaq 0x118(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x179f0
jmp 0x7353
leaq 0x140(%rsp), %rdi
leaq 0x118(%rsp), %rsi
movq %rsi, 0x60(%rsp)
callq 0x6580
movq 0x60(%rsp), %rdi
callq 0x6290
movl 0x750(%rsp), %esi
movq 0x748(%rsp), %rdx
movl 0x1c0(%rsp), %ecx
incl %ecx
leaq 0x1e0(%rsp), %rdi
callq 0x2cf70
jmp 0x739e
leaq 0x6d8(%rsp), %rdi
callq 0x7bd0
movq %rax, 0x40(%rsp)
movq 0x718(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x6180
movq %rax, %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x218a0
movq %rdx, 0x50(%rsp)
movl %eax, 0x5c(%rsp)
jmp 0x73e5
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
movq 0x50(%rsp), %rax
movl 0x5c(%rsp), %ecx
movl %ecx, 0x108(%rsp)
movq %rax, 0x110(%rsp)
movl 0x108(%rsp), %edx
movq 0x110(%rsp), %rcx
callq 0x26220
jmp 0x741d
leaq 0x6d8(%rsp), %rdi
callq 0x7bd0
movq %rax, 0x20(%rsp)
movq 0x720(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x6180
movq %rax, %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x218a0
movq %rdx, 0x30(%rsp)
movl %eax, 0x3c(%rsp)
jmp 0x7464
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl %ecx, 0xf8(%rsp)
movq %rax, 0x100(%rsp)
movl 0xf8(%rsp), %edx
movq 0x100(%rsp), %rcx
callq 0x26220
jmp 0x749c
leaq 0xd8(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x6650
movq 0x18(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0x17af0
jmp 0x74c2
leaq 0x1e0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x26be0
movq %rdx, 0x8(%rsp)
movl %eax, 0x14(%rsp)
jmp 0x74e2
movq 0x8(%rsp), %rax
movl 0x14(%rsp), %ecx
movl %ecx, 0xc8(%rsp)
movq %rax, 0xd0(%rsp)
leaq 0x4f8(%rsp), %rdi
callq 0x2fd70
jmp 0x7509
leaq 0xd8(%rsp), %rdi
callq 0x6290
leaq 0x140(%rsp), %rdi
callq 0x6290
jmp 0x75ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x13f(%rsp), %rdi
callq 0x64c0
jmp 0x75f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x7585
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x6290
leaq 0x140(%rsp), %rdi
callq 0x6290
jmp 0x75f5
movq 0x748(%rsp), %rax
movq (%rax), %rdi
callq 0x7610
jmp 0x75a6
movl $0x1, %edi
callq 0x6560
jmp 0x75b2
jmp 0x75b4
jmp 0x75b6
jmp 0x75b8
movl 0x1c0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c0(%rsp)
jmp 0x700f
movl $0x0, 0x754(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x268b0
movl 0x754(%rsp), %eax
addq $0x758, %rsp            # imm = 0x758
retq
leaq 0x1e0(%rsp), %rdi
callq 0x268b0
movq 0x1c8(%rsp), %rdi
callq 0x67a0
nop