// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x6c8, %rsp            # imm = 0x6C8
movq %rsi, %r14
movl %edi, %ebp
cmpl $0x1, %edi
jg 0x271a
movq 0x3911(%rip), %rbx      # 0x5ff0
leaq 0x1980(%rip), %rsi      # 0x4066
movl $0x52, %edx
movq %rbx, %rdi
callq 0x2160
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq 0x8(%r14), %rsi
leaq 0x60(%rsp), %rbx
leaq 0x4c0(%rsp), %rdx
movq %rbx, %rdi
callq 0x2090
leaq 0x197f(%rip), %rsi      # 0x40b9
movq %rbx, %rdi
callq 0x2050
testl %eax, %eax
je 0x27d8
leaq 0x4c0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movl $0x6, %edx
callq 0x21b0
movq 0x4c0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x4e0(%rsp,%rax)
je 0x2823
movq 0x386e(%rip), %rdi      # 0x5ff0
leaq 0x1964(%rip), %rsi      # 0x40ed
movl $0xe, %edx
callq 0x2160
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x384c(%rip), %rdi      # 0x5ff0
callq 0x2160
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
jmp 0x2d07
movq 0x37f1(%rip), %rbx      # 0x5fd0
leaq 0x18dd(%rip), %rsi      # 0x40c3
movl $0x29, %edx
movq %rbx, %rdi
callq 0x2160
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq 0x37bf(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
jmp 0x2d14
leaq 0x4c0(%rsp), %rdi
callq 0x21c0
movq %rax, %rbx
leaq 0x4c0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2180
leaq 0x4c0(%rsp), %rdi
callq 0x21c0
movq %rax, %r15
leaq 0x80(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
movq %rbx, %rsi
callq 0x2e58
movq 0x80(%rsp), %rsi
leaq 0x4c0(%rsp), %rdi
movq %rbx, %rdx
callq 0x2170
subq %r15, %rbx
xorl %eax, %eax
leaq 0x1780(%rip), %rcx      # 0x4010
leaq 0x38a9(%rip), %rdx      # 0x6140
movsbq (%rax,%rcx), %rsi
movb %al, (%rsi,%rdx)
incq %rax
cmpq $0x55, %rax
jne 0x2897
leaq 0x98(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x249a
leaq 0xc8(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x2f18
leaq 0x1812(%rip), %rsi      # 0x40fc
leaq 0xb8(%rsp), %rdi
callq 0x21f0
leaq 0x2c0(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
movl $0x20, %edx
callq 0x2200
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x2923
callq 0x2130
leaq 0x1906(%rip), %rsi      # 0x4230
leaq 0x2c0(%rsp), %rdi
movl $0x11c, %edx            # imm = 0x11C
callq 0x2160
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
leaq 0x2c0(%rsp), %rdi
callq 0x2160
movq %rax, %r15
leaq 0x19ed(%rip), %rsi      # 0x4350
movl $0x2a2, %edx            # imm = 0x2A2
movq %rax, %rdi
callq 0x2160
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
leaq 0xb8(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x1887(%rip), %rsi      # 0x4230
leaq 0x199c(%rip), %rdx      # 0x434c
callq 0x2fa8
movq 0xc0(%rsp), %r15
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1982(%rip), %rsi      # 0x4350
leaq 0x1c1d(%rip), %rdx      # 0x45f2
leaq 0x8(%rsp), %rdi
callq 0x2fa8
addq %r15, %rbx
addq 0x10(%rsp), %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x29f6
callq 0x2130
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x2a08
callq 0x2130
cmpq $0x186a1, %rbx          # imm = 0x186A1
jb 0x2a57
movq 0x35d8(%rip), %r15      # 0x5ff0
leaq 0x16e9(%rip), %rsi      # 0x4108
movl $0x43, %edx
movq %r15, %rdi
callq 0x2160
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq 0x35a6(%rip), %rdi      # 0x5ff0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
cmpl $0x3, %ebp
jl 0x2ca7
movq 0x10(%r14), %rsi
leaq 0x8(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
callq 0x2090
leaq 0xb8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x2, %edx
callq 0x21b0
leaq 0xb8(%rsp), %rdi
callq 0x21c0
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2180
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %r14, %rsi
callq 0x2eb8
movq 0x48(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
movq %r14, %rdx
callq 0x2170
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0x38(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x28(%rsp), %rdi
callq 0x30a8
cmpq $0x186a0, %rbx          # imm = 0x186A0
ja 0x2b3d
addq 0x30(%rsp), %rbx
cmpq $0x186a0, %rbx          # imm = 0x186A0
jbe 0x2b3d
movq 0x34e0(%rip), %rbx      # 0x5ff0
leaq 0x1652(%rip), %rsi      # 0x4169
movl $0x5f, %edx
movq %rbx, %rdi
callq 0x2160
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
jmp 0x2c5a
leaq 0x1608(%rip), %rsi      # 0x414c
leaq 0x2c0(%rsp), %rbx
movl $0x5, %edx
movq %rbx, %rdi
callq 0x2160
movq 0x2c0(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
leaq 0x2c0(%rsp), %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
leaq 0x15c1(%rip), %rsi      # 0x4152
leaq 0x2c0(%rsp), %rdi
movl $0xf, %edx
callq 0x2160
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x2c0(%rsp), %rdi
callq 0x2160
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x2c0(%rsp), %rdi
callq 0x2160
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
leaq 0x1536(%rip), %rsi      # 0x4162
leaq 0x2c0(%rsp), %rbx
movl $0x6, %edx
movq %rbx, %rdi
callq 0x2160
movq 0x2c0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c7c
callq 0x2130
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x2c8b
callq 0x2130
leaq 0xb8(%rsp), %rdi
callq 0x2040
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x2ca7
callq 0x2130
movq 0x331a(%rip), %rax      # 0x5fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x2c8(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x2c0(%rsp,%rcx)
callq 0x20f0
leaq 0x3b8(%rsp), %rdi
callq 0x2070
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2cf5
callq 0x2130
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x2d07
callq 0x2130
leaq 0x4c0(%rsp), %rdi
callq 0x2040
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2d27
callq 0x2130
xorl %eax, %eax
addq $0x6c8, %rsp            # imm = 0x6C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2d3d
movq %rax, %rbx
jmp 0x2dc1
jmp 0x2d46
jmp 0x2d46
movq %rax, %rbx
jmp 0x2dd0
movq %rax, %rbx
jmp 0x2ddd
jmp 0x2dee
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
jne 0x2de7
jmp 0x2df1
jmp 0x2dee
jmp 0x2d74
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x2dfe
callq 0x2130
jmp 0x2dfe
movq %rax, %rbx
jmp 0x2dfe
jmp 0x2d92
movq %rax, %rbx
jmp 0x2e14
jmp 0x2e2d
jmp 0x2e2d
jmp 0x2e2d
jmp 0x2e2d
jmp 0x2dee
jmp 0x2e28
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x2dc1
callq 0x2130
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x2dd0
callq 0x2130
leaq 0xb8(%rsp), %rdi
callq 0x2040
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x2df1
callq 0x2130
jmp 0x2df1
movq %rax, %rbx
leaq 0x2c0(%rsp), %rdi
callq 0x2190
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e14
callq 0x2130
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x2e30
callq 0x2130
jmp 0x2e30
movq %rax, %rbx
jmp 0x2e3d
movq %rax, %rbx
leaq 0x4c0(%rsp), %rdi
callq 0x2040
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e50
callq 0x2130
movq %rbx, %rdi
callq 0x21d0