// File: mrGoncharuk[P]foldermonitor/src/main.cpp
// Function: main
int main(void)
{
	int	pidfilehandle;
	pidfilehandle = daemonize();

	std::list<std::string> filenames;
	std::atomic<bool> isRunning;
	std::mutex l_mutex;
	const std::string watching_folder = "/home/foldermonitor/monitorme/";
	const std::string database_folder = "/home/foldermonitor/database/foldermonitor.db";
	DirectoryMonitor dm(watching_folder);
	DBWriter *dbw = new DBWriter(database_folder);
	MigrationManager migManager(dbw, countThreadAmount());

	if (dm.initWatcher() == false)
		exit(EXIT_FAILURE);
	if (dbw->initDB() == false)
		exit(EXIT_FAILURE);
	isRunning = true;

	std::thread threadFWatcher
		( &DirectoryMonitor::startWatching
			, std::ref(dm)
			, std::ref(l_mutex)
			, std::ref(filenames)
			, std::ref(isRunning)
		);
	migManager.migrateData(l_mutex, filenames, isRunning);
	threadFWatcher.join();
	dbw->closeDB();
	delete dbw;
	syslog(LOG_NOTICE, "Stopping daemon-foldermonitor.");
	close(pidfilehandle);
	closelog();
	exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movl $0x0, -0x4(%rbp)
callq 0x35d0
movl %eax, -0x8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x3cc0
leaq -0x50(%rbp), %rdi
callq 0x3ce0
leaq -0x71(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x3370
movq -0x130(%rbp), %rdx
leaq 0x4924(%rip), %rsi      # 0x811e
leaq -0x70(%rbp), %rdi
callq 0x32a0
jmp 0x3805
leaq -0x71(%rbp), %rdi
callq 0x3230
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x3370
movq -0x138(%rbp), %rdx
leaq 0x490e(%rip), %rsi      # 0x813d
leaq -0xa8(%rbp), %rdi
callq 0x32a0
jmp 0x383d
leaq -0xa9(%rbp), %rdi
callq 0x3230
leaq -0xd8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x56f0
jmp 0x385b
movl $0x58, %edi
callq 0x3220
movq %rax, -0x140(%rbp)
jmp 0x386e
movq -0x140(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x5250
jmp 0x3883
movq -0x140(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x150(%rbp)
callq 0x3b50
movl %eax, -0x144(%rbp)
jmp 0x38ac
movl -0x144(%rbp), %edx
movq -0x150(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x63a0
jmp 0x38c7
leaq -0xd8(%rbp), %rdi
callq 0x5760
movb %al, -0x151(%rbp)
jmp 0x38db
movb -0x151(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3992
movl $0x1, %edi
callq 0x3250
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x3230
jmp 0x3b38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xa9(%rbp), %rdi
callq 0x3230
jmp 0x3b2f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x3b23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x3b17
movq -0x140(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x3200
jmp 0x3b17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x3b0b
movq -0xe0(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movb %al, -0x152(%rbp)
jmp 0x39a9
movb -0x152(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x39c3
movl $0x1, %edi
callq 0x3250
leaq -0x21(%rbp), %rdi
movq %rdi, -0x160(%rbp)
movl $0x1, %esi
callq 0x3d00
leaq 0x1e61(%rip), %rax      # 0x5840
movq %rax, -0x108(%rbp)
movq $0x0, -0x100(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3d30
movq %rax, -0x110(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3d60
movq %rax, -0x118(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x3d90
movq -0x160(%rbp), %rdi
movq %rax, -0x120(%rbp)
callq 0x3dc0
movq %rax, -0x128(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x110(%rbp), %rdx
leaq -0x118(%rbp), %rcx
leaq -0x120(%rbp), %r8
leaq -0x128(%rbp), %r9
callq 0x3df0
jmp 0x3a68
leaq -0xf0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x20(%rbp), %rdx
leaq -0x21(%rbp), %rcx
callq 0x6c30
jmp 0x3a82
leaq -0xf8(%rbp), %rdi
callq 0x3340
jmp 0x3a90
movq -0xe0(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0x3aa2
movq -0xe0(%rbp), %rax
movq %rax, -0x168(%rbp)
cmpq $0x0, %rax
je 0x3ac3
movq -0x168(%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
leaq 0x46a1(%rip), %rsi      # 0x816b
xorl %eax, %eax
movl $0x5, %edi
callq 0x3060
jmp 0x3ad8
movl -0x8(%rbp), %edi
callq 0x33f0
jmp 0x3ae2
callq 0x3210
jmp 0x3ae9
xorl %edi, %edi
callq 0x3250
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x3ec0
leaq -0xf0(%rbp), %rdi
callq 0x63e0
leaq -0xd8(%rbp), %rdi
callq 0x5670
leaq -0xa8(%rbp), %rdi
callq 0x3170
leaq -0x70(%rbp), %rdi
callq 0x3170
leaq -0x20(%rbp), %rdi
callq 0x3ef0
movq -0x80(%rbp), %rdi
callq 0x3360
nopw (%rax,%rax)