// File: BleuLlama[P]msf-tools/DiskUtils.cpp
// Function: DiskUtils::CopyFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
bool DiskUtils::CopyFile( std::string fromPath, std::string toPath, bool skipIfExists )
{
	char buf[ kCopyFileBufSize ];

	// if the file is already there, and it's okay to skip, we're done
	if( skipIfExists ) {
		if( DiskUtils::IsSimilarFile( fromPath, toPath )) return true;
	}
	
	// copy the file from fromPath to toPath. ;)

	// open the files
	FILE * inf = fopen( fromPath.c_str(), "rb" );
	if( !inf ) {
		std::cerr << "Couldn't open input file " << fromPath << std::endl;
		return true;
	}

	FILE * outf = fopen( toPath.c_str(), "wb" );
	if( !outf ) {
		std::cerr << "Couldn't open output file " << toPath << std::endl;
		fclose( inf );
		return true;
	}


	// copy it over one buffer at a time
	size_t n = 0;
	do {
		n = fread( buf, 1, kCopyFileBufSize, inf );
		fwrite( buf, n, 1, outf );
	} while( n!= 0 );

	// close the files
	fclose( inf );
	fclose( outf );

	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x400a0, %rsp          # imm = 0x400A0
movq %rsi, -0x40098(%rbp)
movq %rdi, -0x40090(%rbp)
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
je 0x2cd7
movq -0x40090(%rbp), %rsi
leaq -0x40040(%rbp), %rdi
callq 0x20a0
movq -0x40098(%rbp), %rsi
leaq -0x40060(%rbp), %rdi
callq 0x20a0
jmp 0x2c4a
leaq -0x40040(%rbp), %rdi
leaq -0x40060(%rbp), %rsi
callq 0x26f0
movb %al, -0x40099(%rbp)
jmp 0x2c65
leaq -0x40060(%rbp), %rdi
callq 0x20e0
leaq -0x40040(%rbp), %rdi
callq 0x20e0
movb -0x40099(%rbp), %al
testb $0x1, %al
jne 0x2c89
jmp 0x2cd5
movb $0x1, -0x1(%rbp)
jmp 0x2e20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40068(%rbp)
movl %eax, -0x4006c(%rbp)
jmp 0x2cc4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40068(%rbp)
movl %eax, -0x4006c(%rbp)
leaq -0x40060(%rbp), %rdi
callq 0x20e0
leaq -0x40040(%rbp), %rdi
callq 0x20e0
jmp 0x2e2e
jmp 0x2cd7
movq -0x40090(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
leaq 0x3332(%rip), %rsi      # 0x601f
callq 0x2210
movq %rax, -0x40078(%rbp)
cmpq $0x0, -0x40078(%rbp)
jne 0x2d3d
movq 0x62e6(%rip), %rdi      # 0x8ff0
leaq 0x3311(%rip), %rsi      # 0x6022
callq 0x2180
movq -0x40090(%rbp), %rsi
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movq 0x6291(%rip), %rsi      # 0x8fc0
callq 0x21a0
movb $0x1, -0x1(%rbp)
jmp 0x2e20
movq -0x40098(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
leaq 0x32e9(%rip), %rsi      # 0x603c
callq 0x2210
movq %rax, -0x40080(%rbp)
cmpq $0x0, -0x40080(%rbp)
jne 0x2dac
movq 0x6280(%rip), %rdi      # 0x8ff0
leaq 0x32c8(%rip), %rsi      # 0x603f
callq 0x2180
movq -0x40098(%rbp), %rsi
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movq 0x622b(%rip), %rsi      # 0x8fc0
callq 0x21a0
movq -0x40078(%rbp), %rdi
callq 0x2190
movb $0x1, -0x1(%rbp)
jmp 0x2e20
movq $0x0, -0x40088(%rbp)
leaq -0x40020(%rbp), %rdi
movq -0x40078(%rbp), %rcx
movl $0x1, %esi
movl $0x40000, %edx          # imm = 0x40000
callq 0x2280
movq %rax, -0x40088(%rbp)
leaq -0x40020(%rbp), %rdi
movq -0x40088(%rbp), %rsi
movq -0x40080(%rbp), %rcx
movl $0x1, %edx
callq 0x2380
cmpq $0x0, -0x40088(%rbp)
jne 0x2db7
movq -0x40078(%rbp), %rdi
callq 0x2190
movq -0x40080(%rbp), %rdi
callq 0x2190
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x400a0, %rsp          # imm = 0x400A0
popq %rbp
retq
movq -0x40068(%rbp), %rdi
callq 0x2320
nopw (%rax,%rax)