// File: /workspace/github_cpp_makefile_star2_O2/Agade09[P]CG-Send-Binary/Binary_To_Base85.cpp
// Function: main
int main(int argc,char** argv){
	if(argc<2){
		cerr << "Program takes at least one argument, the name of the program to convert to base 85" << endl;
	}
	const string Program_Name{argv[1]};
	if(Program_Name=="--version"){
		cout << "CG-Send-Binary V1.0\nBy github.com/Agade09" << endl;
		return 0;
	}
	ifstream Program_File(Program_Name,ios::binary | ios::ate);
	if(!Program_File){
		cerr << "Couldn't open " << Program_Name << endl;
		return 0;
	}
	const streamsize binary_size{Program_File.tellg()};
	Program_File.seekg(0,ios::beg);
	const long binary_bytes{binary_size-Program_File.tellg()};
	vector<unsigned char> Program_Binary(binary_size);
	Program_File.read(reinterpret_cast<char*>(Program_Binary.data()),binary_size);
	for(int i=0;i<85;i++){
		int ch{en85[i]};
		de85[ch]=i;
	}
	const string base85_Program_Binary=encode_85(Program_Binary);
	ofstream Program_Base85_File(Program_Name+"_Base85.cpp",ios::trunc);
	Program_Base85_File << half1 << base85_Program_Binary << half2 << endl;
	const size_t size_before_comments{string(half1).size()+binary_bytes+string(half2).size()};
	if(size_before_comments>Code_Size_Limit){
		cerr << "Warning: Base85 encoded binary is too large to be sent to Codingame" << endl;
	}
	if(argc>=3){//Append source code as comment
		const string Source_Filename{argv[2]};
		ifstream Source_File(Source_Filename,ios::ate);
		const streamsize source_size{Source_File.tellg()};
		Source_File.seekg(0,ios::beg);
		vector<char> Source(source_size);
		Source_File.read(reinterpret_cast<char*>(Source.data()),source_size);
		const string source_code(Source.begin(),Source.end());
		if(size_before_comments+source_code.size()<=Code_Size_Limit || size_before_comments>Code_Size_Limit){//If the file is going to be too big anyway, we might as well include the comments
			Program_Base85_File << "#if 0" << endl;
			Program_Base85_File << "//Source file: " << Source_Filename << endl;
			Program_Base85_File << source_code << endl;
			Program_Base85_File << "#endif" << endl;
		}
		else{
			cerr << "Warning: Could not include source code as a comment without exceeding Codingame code size limit" << endl;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x6c8, %rsp            # imm = 0x6C8
movq %rsi, %r14
movl %edi, %ebp
cmpl $0x1, %edi
jg 0x25c5
movq 0x2a3f(%rip), %rdi      # 0x4ff0
leaq 0xaae(%rip), %rsi       # 0x3066
callq 0x2100
movq %rax, %rdi
callq 0x2080
movq 0x8(%r14), %rsi
leaq 0x78(%rsp), %rbx
leaq 0x2c0(%rsp), %rdx
movq %rbx, %rdi
callq 0x2060
leaq 0xad4(%rip), %rsi       # 0x30b9
movq %rbx, %rdi
callq 0x2a6d
testb %al, %al
je 0x2611
movq 0x29d8(%rip), %rdi      # 0x4fd0
leaq 0xac4(%rip), %rsi       # 0x30c3
callq 0x2100
movq %rax, %rdi
callq 0x2080
jmp 0x2983
leaq 0x2c0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
pushq $0x6
popq %rdx
callq 0x2170
movq 0x2c0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x2e0(%rsp,%rax)
je 0x2669
movq 0x29ad(%rip), %rdi      # 0x4ff0
leaq 0xaa3(%rip), %rsi       # 0x30ed
callq 0x2100
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x2080
jmp 0x2976
leaq 0x2c0(%rsp), %rdi
callq 0x2180
movq %rax, %rbx
leaq 0x2c0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2130
leaq 0x2c0(%rsp), %rdi
callq 0x2180
movq %rax, %r15
leaq 0x60(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
movq %rbx, %rsi
callq 0x2a7a
movq 0x60(%rsp), %rsi
leaq 0x2c0(%rsp), %rdi
movq %rbx, %rdx
callq 0x2120
subq %r15, %rbx
xorl %eax, %eax
leaq 0x940(%rip), %rcx       # 0x3010
leaq 0x2a59(%rip), %rdx      # 0x5130
cmpq $0x55, %rax
je 0x26ea
movsbq (%rax,%rcx), %rsi
movb %al, (%rsi,%rdx)
incq %rax
jmp 0x26d7
leaq 0x98(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x23f8
leaq 0x9f9(%rip), %rdx       # 0x30fc
leaq 0xb8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x2acb
leaq 0x4c8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
pushq $0x20
popq %rdx
callq 0x21c0
leaq 0xb8(%rsp), %rdi
callq 0x2070
leaq 0xabf(%rip), %rsi       # 0x3200
leaq 0x4c8(%rsp), %rdi
callq 0x2100
leaq 0x98(%rsp), %rsi
movq %rax, %rdi
callq 0x20d0
leaq 0xbbb(%rip), %rsi       # 0x3320
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2080
leaq 0xa84(%rip), %rsi       # 0x3200
leaq 0xb8(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x2060
movq 0xc0(%rsp), %r15
leaq 0xb83(%rip), %rsi       # 0x3320
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2060
addq %r15, %rbx
leaq 0x40(%rsp), %rdi
addq 0x8(%rdi), %rbx
callq 0x2070
leaq 0xb8(%rsp), %rdi
callq 0x2070
cmpq $0x186a1, %rbx          # imm = 0x186A1
jb 0x27ee
movq 0x2816(%rip), %rdi      # 0x4ff0
leaq 0x927(%rip), %rsi       # 0x3108
callq 0x2100
movq %rax, %rdi
callq 0x2080
cmpl $0x3, %ebp
jl 0x2952
movq 0x10(%r14), %rsi
leaq 0x40(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
callq 0x2060
leaq 0xb8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0x2170
leaq 0xb8(%rsp), %rdi
callq 0x2180
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2130
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r14, %rsi
callq 0x2b04
movq 0x8(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
movq %r14, %rdx
callq 0x2120
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x20(%rsp), %rdi
callq 0x2cc8
cmpq $0x186a0, %rbx          # imm = 0x186A0
ja 0x28ae
addq 0x28(%rsp), %rbx
cmpq $0x186a0, %rbx          # imm = 0x186A0
jbe 0x28ae
leaq 0x8c4(%rip), %rsi       # 0x3169
movq 0x2744(%rip), %rbx      # 0x4ff0
jmp 0x2917
leaq 0x897(%rip), %rsi       # 0x314c
leaq 0x4c8(%rsp), %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2080
leaq 0x881(%rip), %rsi       # 0x3152
leaq 0x4c8(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x2080
leaq 0x4c8(%rsp), %rbx
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x2080
leaq 0x84b(%rip), %rsi       # 0x3162
movq %rbx, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2080
leaq 0x20(%rsp), %rdi
callq 0x2070
leaq 0x8(%rsp), %rdi
callq 0x2c6c
leaq 0xb8(%rsp), %rdi
callq 0x2030
leaq 0x40(%rsp), %rdi
callq 0x2070
leaq 0x4c8(%rsp), %rdi
callq 0x2150
leaq 0x98(%rsp), %rdi
callq 0x2070
leaq 0x60(%rsp), %rdi
callq 0x2bc0
leaq 0x2c0(%rsp), %rdi
callq 0x2030
leaq 0x78(%rsp), %rdi
callq 0x2070
xorl %eax, %eax
addq $0x6c8, %rsp            # imm = 0x6C8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x299f
movq %rax, %rbx
jmp 0x29fa
jmp 0x29a8
jmp 0x29a8
movq %rax, %rbx
jmp 0x2a04
movq %rax, %rbx
jmp 0x2a11
jmp 0x2a1d
jmp 0x2a1d
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x2a16
jmp 0x2a1d
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x2070
jmp 0x2a2d
movq %rax, %rbx
jmp 0x2a2d
jmp 0x29de
movq %rax, %rbx
jmp 0x2a3a
jmp 0x2a46
jmp 0x2a46
jmp 0x2a46
jmp 0x2a46
jmp 0x2a58
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2070
leaq 0x8(%rsp), %rdi
callq 0x2c6c
leaq 0xb8(%rsp), %rdi
callq 0x2030
leaq 0x40(%rsp), %rdi
callq 0x2070
jmp 0x2a20
movq %rax, %rbx
leaq 0x4c8(%rsp), %rdi
callq 0x2150
leaq 0x98(%rsp), %rdi
callq 0x2070
leaq 0x60(%rsp), %rdi
callq 0x2bc0
jmp 0x2a49
movq %rax, %rbx
leaq 0x2c0(%rsp), %rdi
callq 0x2030
jmp 0x2a5b
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2190