// File: kebwi[P]Trifid/src/main.cpp
// Function: processArgsFromFile(int, char**)
bool processArgsFromFile(int argc, char **argv)
{
	if (argc < 2)
		return false;
	
	string argListFile("argList.txt");
	
	ifstream ifs;
	ifs.open(argListFile.c_str());
	if (!ifs)
		return false;
	
	cout << "Building argument list from file " << argListFile << endl;
	
	vector<string> args;
	args.push_back(string(argv[0]));
	while (ifs)
	{
		string s;
		while (ifs && !isspace(ifs.peek()))
		{
			char c = ifs.get();
			if (ifs)
				s += c;
		}
		
		//cout << "    Arg read: \"" << s << "\"" << endl;
		
		args.push_back(s);
		
		//Skip spaces/endlines/tabs/etc. to the next argument
		while (ifs && isspace(ifs.peek()))
			ifs.get();
	}
	ifs.close();
	
	//cout << "Num args in file: " << args.size() << endl;
	//for (int i = 0; i < args.size(); i++)
	//	cout << "    Arg: \"" << args[i] << "\"" << endl;
	
	int argc2 = args.size();
	char **argv2 = new char*[argc2];
	for (int i = 0; i < argc2; i++)
	{
		argv2[i] = new char[256];
		strcpy(argv2[i], args[i].c_str());
		//cout << "    Arg " << i << " length: " << strlen(argv2[i]) << endl;
	}
	
	//cout << "Argument list built" << endl;
	//for (int i = 0; i < argc2; i++)
	//	cout << "    Arg: \"" << argv2[i] << "\"" << endl;
	
	processArgs(argc2, argv2);
	
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x330, %rsp            # imm = 0x330
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x7d61
movb $0x0, -0x1(%rbp)
jmp 0x827c
leaq -0x31(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x4630
movq -0x2d8(%rbp), %rdx
leaq 0x41ab7(%rip), %rsi     # 0x49836
leaq -0x30(%rbp), %rdi
callq 0xe110
jmp 0x7d8a
leaq -0x31(%rbp), %rdi
callq 0x43f0
leaq -0x250(%rbp), %rdi
callq 0x4420
jmp 0x7da1
leaq -0x30(%rbp), %rdi
callq 0x4160
movq %rax, %rsi
leaq -0x250(%rbp), %rdi
movl $0x8, %edx
callq 0x4230
jmp 0x7dc0
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x250(%rbp,%rax), %rdi
callq 0x41b0
movb %al, -0x2d9(%rbp)
jmp 0x7de0
movb -0x2d9(%rbp), %al
testb $0x1, %al
jne 0x7dec
jmp 0x7e3b
movb $0x0, -0x1(%rbp)
movl $0x1, -0x254(%rbp)
jmp 0x824e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x43f0
jmp 0x828a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x8271
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x8265
movq 0x5218e(%rip), %rdi     # 0x59fd0
leaq 0x419f9(%rip), %rsi     # 0x49842
callq 0x4390
movq %rax, -0x2e8(%rbp)
jmp 0x7e57
movq -0x2e8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4330
movq %rax, -0x2f0(%rbp)
jmp 0x7e70
movq -0x2f0(%rbp), %rdi
movq 0x5213a(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x7e85
leaq -0x270(%rbp), %rdi
callq 0xe1c0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x300(%rbp)
leaq -0x291(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x4630
movq -0x300(%rbp), %rsi
movq -0x2f8(%rbp), %rdx
leaq -0x290(%rbp), %rdi
callq 0xe110
jmp 0x7ece
leaq -0x270(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0xe700
jmp 0x7ee3
leaq -0x290(%rbp), %rdi
callq 0x46c8
leaq -0x291(%rbp), %rdi
callq 0x43f0
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x250(%rbp,%rax), %rdi
callq 0x44a0
movb %al, -0x301(%rbp)
jmp 0x7f1b
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x7f2a
jmp 0x8118
leaq -0x2b8(%rbp), %rdi
callq 0x4500
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x250(%rbp,%rax), %rdi
callq 0x44a0
movb %al, -0x302(%rbp)
jmp 0x7f56
movb -0x302(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x303(%rbp)
jne 0x7f6b
jmp 0x7f98
leaq -0x250(%rbp), %rdi
callq 0x4130
movl %eax, -0x308(%rbp)
jmp 0x7f7f
movl -0x308(%rbp), %edi
callq 0x4080
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x303(%rbp)
movb -0x303(%rbp), %al
testb $0x1, %al
jne 0x7fa7
jmp 0x8074
leaq -0x250(%rbp), %rdi
callq 0x4460
movl %eax, -0x30c(%rbp)
jmp 0x7fbb
movl -0x30c(%rbp), %eax
movb %al, -0x2b9(%rbp)
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x250(%rbp,%rax), %rdi
callq 0x44a0
movb %al, -0x30d(%rbp)
jmp 0x7fe7
movb -0x30d(%rbp), %al
testb $0x1, %al
jne 0x7ff3
jmp 0x806f
movsbl -0x2b9(%rbp), %esi
leaq -0x2b8(%rbp), %rdi
callq 0x4220
jmp 0x8008
jmp 0x806f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x8030
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x46c8
leaq -0x291(%rbp), %rdi
callq 0x43f0
jmp 0x8240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x8240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x46c8
jmp 0x8240
jmp 0x7f36
leaq -0x270(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0xe690
jmp 0x8089
jmp 0x808b
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x250(%rbp,%rax), %rdi
callq 0x44a0
movb %al, -0x30e(%rbp)
jmp 0x80ab
movb -0x30e(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x30f(%rbp)
jne 0x80c0
jmp 0x80eb
leaq -0x250(%rbp), %rdi
callq 0x4130
movl %eax, -0x314(%rbp)
jmp 0x80d4
movl -0x314(%rbp), %edi
callq 0x4080
cmpl $0x0, %eax
setne %al
movb %al, -0x30f(%rbp)
movb -0x30f(%rbp), %al
testb $0x1, %al
jne 0x80f7
jmp 0x8107
leaq -0x250(%rbp), %rdi
callq 0x4460
jmp 0x8105
jmp 0x808b
leaq -0x2b8(%rbp), %rdi
callq 0x46c8
jmp 0x7efb
leaq -0x250(%rbp), %rdi
callq 0x40b0
jmp 0x8126
leaq -0x270(%rbp), %rdi
callq 0xe730
movl %eax, -0x2c0(%rbp)
movslq -0x2c0(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x4030
movq %rax, -0x320(%rbp)
jmp 0x8163
movq -0x320(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movl $0x0, -0x2cc(%rbp)
movl -0x2cc(%rbp), %eax
cmpl -0x2c0(%rbp), %eax
jge 0x8210
movl $0x100, %edi            # imm = 0x100
callq 0x4030
movq %rax, -0x328(%rbp)
jmp 0x81a0
movq -0x328(%rbp), %rdx
movq -0x2c8(%rbp), %rax
movslq -0x2cc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x2c8(%rbp), %rax
movslq -0x2cc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x330(%rbp)
movslq -0x2cc(%rbp), %rsi
leaq -0x270(%rbp), %rdi
callq 0xe750
movq %rax, %rdi
callq 0x4160
movq -0x330(%rbp), %rdi
movq %rax, %rsi
callq 0x4350
movl -0x2cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2cc(%rbp)
jmp 0x817b
movl -0x2c0(%rbp), %edi
movq -0x2c8(%rbp), %rsi
callq 0x6460
jmp 0x8224
movb $0x1, -0x1(%rbp)
movl $0x1, -0x254(%rbp)
leaq -0x270(%rbp), %rdi
callq 0xe1e0
jmp 0x824e
leaq -0x270(%rbp), %rdi
callq 0xe1e0
jmp 0x8265
leaq -0x250(%rbp), %rdi
callq 0x40d0
leaq -0x30(%rbp), %rdi
callq 0x46c8
jmp 0x827c
leaq -0x250(%rbp), %rdi
callq 0x40d0
leaq -0x30(%rbp), %rdi
callq 0x46c8
jmp 0x828a
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x4620
nopw %cs:(%rax,%rax)