// File: ch4rli3kop[P]ch4rli3-fuzzer/main.cc
// Function: init_corpus()
void init_corpus(){
	
	DIR *dir;
	struct dirent *entry;
	string in_dir = "./in/";

	if (!(dir = opendir(in_dir.c_str()))){
		perror("open dir error!\n");
	}

	while ((entry = readdir(dir))){
		if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name,"..")) continue;
		string filename(entry->d_name);
		ifstream in(in_dir + filename, ios::ate);

		if (in.fail()){
			perror("open file error!\n");
			exit(-1);
		}

		uint32_t length = in.tellg();
		in.seekg(0, ios::beg);

		uint8_t* buf = new uint8_t[length+1+4];
		memcpy(buf, &length, 4);
		in.read((char*)buf + 4, length);

		// cout << "./in/" << entry->d_name << endl;
		// cout << "File length : " << length << endl;
		// cout << buf << endl;
		corpus.push_back(buf);
		//input.push(buf);
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
leaq -0x31(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x23e0
movq -0x2c0(%rbp), %rdx
leaq 0x428b(%rip), %rsi      # 0x70a4
leaq -0x30(%rbp), %rdi
callq 0x38c0
jmp 0x2e24
leaq -0x31(%rbp), %rdi
callq 0x2250
leaq -0x30(%rbp), %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x2350
movq %rax, -0x2c8(%rbp)
jmp 0x2e47
movq -0x2c8(%rbp), %rax
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
jne 0x2e93
leaq 0x424b(%rip), %rdi      # 0x70aa
callq 0x21b0
jmp 0x2e66
jmp 0x2e93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x2250
jmp 0x312e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3125
jmp 0x2e95
movq -0x8(%rbp), %rdi
callq 0x2360
movq %rax, -0x2d0(%rbp)
jmp 0x2ea7
movq -0x2d0(%rbp), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x3113
movq -0x10(%rbp), %rdi
addq $0x13, %rdi
leaq 0x41f1(%rip), %rsi      # 0x70bc
callq 0x2310
cmpl $0x0, %eax
je 0x2eee
movq -0x10(%rbp), %rdi
addq $0x13, %rdi
leaq 0x41d7(%rip), %rsi      # 0x70bb
callq 0x2310
cmpl $0x0, %eax
jne 0x2ef0
jmp 0x2e95
movq -0x10(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x2e0(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x23e0
movq -0x2e0(%rbp), %rsi
movq -0x2d8(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x38c0
jmp 0x2f28
leaq -0x69(%rbp), %rdi
callq 0x2250
leaq -0x298(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x3970
jmp 0x2f47
leaq -0x278(%rbp), %rdi
leaq -0x298(%rbp), %rsi
movl $0x2, %edx
callq 0x2380
jmp 0x2f61
leaq -0x298(%rbp), %rdi
callq 0x2150
movq -0x278(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x278(%rbp,%rax), %rdi
callq 0x2030
movb %al, -0x2e1(%rbp)
jmp 0x2f8d
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x2f99
jmp 0x3016
leaq 0x411e(%rip), %rdi      # 0x70be
callq 0x21b0
jmp 0x2fa7
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x69(%rbp), %rdi
callq 0x2250
jmp 0x3125
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x2150
jmp 0x3108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x2080
jmp 0x3108
leaq -0x278(%rbp), %rdi
callq 0x23c0
movq %rdx, -0x2f8(%rbp)
movq %rax, -0x2f0(%rbp)
jmp 0x3032
movq -0x2f8(%rbp), %rax
movq -0x2f0(%rbp), %rcx
movq %rcx, -0x2b0(%rbp)
movq %rax, -0x2a8(%rbp)
leaq -0x2b0(%rbp), %rdi
callq 0x34c0
movq %rax, -0x300(%rbp)
jmp 0x3063
movq -0x300(%rbp), %rax
movl %eax, -0x29c(%rbp)
xorl %edx, %edx
movl %edx, %esi
leaq -0x278(%rbp), %rdi
callq 0x22f0
jmp 0x3082
movl -0x29c(%rbp), %eax
addl $0x5, %eax
movl %eax, %edi
callq 0x2040
movq %rax, -0x308(%rbp)
jmp 0x309b
movq -0x308(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movq -0x2b8(%rbp), %rax
movl -0x29c(%rbp), %ecx
movl %ecx, (%rax)
movq -0x2b8(%rbp), %rsi
addq $0x4, %rsi
movl -0x29c(%rbp), %eax
movl %eax, %edx
leaq -0x278(%rbp), %rdi
callq 0x22d0
jmp 0x30d9
leaq 0x81e8(%rip), %rdi      # 0xb2c8
leaq -0x2b8(%rbp), %rsi
callq 0x3450
jmp 0x30ee
leaq -0x278(%rbp), %rdi
callq 0x2080
leaq -0x68(%rbp), %rdi
callq 0x2150
jmp 0x2e95
leaq -0x68(%rbp), %rdi
callq 0x2150
jmp 0x3125
leaq -0x30(%rbp), %rdi
callq 0x2150
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x2150
movq -0x40(%rbp), %rdi
callq 0x23d0
nopw (%rax,%rax)