// File: /workspace/github_cpp_makefile_star2_O3/kchan1[P]helloworld_test1/main.cpp
// Function: compress(double**&, double**&, double**&, int, int, unsigned char*&, int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, int)
void compress(double** &blue_data,double** &green_data, 
	      double** &red_data, int height,int width,
              unsigned char* &image_header_data, int &bitmap_offset,
	      std::string filename , int decomposition_loops, int quant){

	filename+=".205";
	std::ofstream output_file;

	output_file.open(filename.c_str(), std::ofstream::out | std::ofstream::binary);
	output_file.write(reinterpret_cast<const char*>(image_header_data), bitmap_offset);
	
	unsigned char depth[1];
	depth[0] = decomposition_loops;
	unsigned char how_many[1];
	how_many[0] = 0;
	char value[1];
	value[0] = 0;
	double current;
	int saved = 0;
	
	output_file.write(reinterpret_cast<const char*>(depth), 1);

	depth[0] = quant;

	output_file.write(reinterpret_cast<const char*>(depth), 1);

	current = blue_data[0][0];
	how_many[0]=1;
	//int cout_count = 0;
	int count = 0;

	for (int i = 0; i<height; i++){
		for (int j = 0; j<height; j++){
			if (blue_data[i][j]!=current){
				value[0] = current;
				output_file.write(reinterpret_cast<const char*>(how_many), 1);
				output_file.write(reinterpret_cast<const char*>(value),1);
				//if(cout_count<49927){
				//std::cout<<(int)how_many[0]<<" "<<(int)value[0]<<std::endl;
				//cout_count++;
				//std::cout<<cout_count<<std::endl;
				//}
				saved+=how_many[0]-2;
				current = blue_data[i][j];
				count+=how_many[0];
				how_many[0] = 1;
				continue;		
			}
			if (how_many[0] == 255){
				value[0] =  current;
				output_file.write(reinterpret_cast<const char*>(how_many), 1);
				output_file.write(reinterpret_cast<const char*>(value),1);
				//if(cout_count<49927){
				//std::cout<<(int)how_many[0]<<" "<<(int)value[0]<<std::endl;
				//cout_count++;
				//std::cout<<cout_count<<std::endl;
				//}
				saved+=how_many[0]-2;
				count+=how_many[0];
				how_many[0] = 1;
				continue;
			}
			how_many[0]++;
		}
	}
	value[0] =  current;
	output_file.write(reinterpret_cast<const char*>(how_many), 1);
	output_file.write(reinterpret_cast<const char*>(value),1);
	//std::cout<<(int)how_many[0]<<" "<<(int)value[0]<<std::endl;
	count+=how_many[0];
	//std::cout<<count<<std::endl;

	current = green_data[0][0];
	how_many[0]=1;
	count=0;

	for (int i = 0; i<height; i++){
		for (int j = 0; j<height; j++){
			if (green_data[i][j]!=current){
				value[0] = current;
				output_file.write(reinterpret_cast<const char*>(how_many), 1);
				output_file.write(reinterpret_cast<const char*>(value),1);
				//std::cout<<(int)how_many[0]<<" "<<(int)value[0]<<std::endl;
				saved+=how_many[0]-2;
				current = green_data[i][j];
				count+=how_many[0];
				how_many[0] = 1;
				continue;		
			}
			if (how_many[0] == 255){
				value[0] = current;
				output_file.write(reinterpret_cast<const char*>(how_many), 1);
				output_file.write(reinterpret_cast<const char*>(value),1);
				//std::cout<<(int)how_many[0]<<" "<<(int)value[0]<<std::endl;
				saved+=how_many[0]-2;
				count+=how_many[0];
				how_many[0] = 1;
				continue;
			}
			how_many[0]++;
		}
	}
	value[0] =  current;
	output_file.write(reinterpret_cast<const char*>(how_many), 1);
	output_file.write(reinterpret_cast<const char*>(value),1);
	count+=how_many[0];
	//std::cout<<count<<std::endl;

	current = red_data[0][0];
	how_many[0]=1;
	count = 0;

	for (int i = 0; i<height; i++){
		for (int j = 0; j<height; j++){
			if (red_data[i][j]!=current){
				value[0] = current;
				output_file.write(reinterpret_cast<const char*>(how_many),1);
				output_file.write(reinterpret_cast<const char*>(value),1);
				//std::cout<<(int)how_many[0]<<" "<<(int)value[0]<<std::endl;
				saved+=how_many[0]-2;
				count+=how_many[0];
				current = red_data[i][j];
				how_many[0] = 1;
				continue;		
			}
			if (how_many[0] == 255){
				value[0] = current;
				output_file.write(reinterpret_cast<const char*>(how_many), 1);
				output_file.write(reinterpret_cast<const char*>(value),1);
				//std::cout<<(int)how_many[0]<<" "<<(int)value[0]<<std::endl;
				saved+=how_many[0]-2;
				count+=how_many[0];
				how_many[0] = 1;
				continue;
			}
			how_many[0]++;
		}
	}
	value[0] =  current;
	output_file.write(reinterpret_cast<const char*>(how_many), 1);
	output_file.write(reinterpret_cast<const char*>(value),1);
	count+=how_many[0];
	//std::cout<<count<<std::endl;	

	//std::cout<<saved<<std::endl;
	
	output_file.close();
	return;
	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %r9, %r12
movl %ecx, %ebx
movq %rdx, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movq 0x268(%rsp), %r13
leaq 0x20f3(%rip), %rsi      # 0x6195
movq %r13, %rdi
callq 0x2230
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
callq 0x21f0
movq (%r13), %rsi
movq %rbp, %rdi
movl $0x14, %edx
callq 0x2050
movq 0x260(%rsp), %rax
movq (%r12), %rsi
movslq (%rax), %rdx
leaq 0x28(%rsp), %rdi
callq 0x2190
movl 0x270(%rsp), %eax
leaq 0xf(%rsp), %rsi
movb %al, (%rsi)
leaq 0x28(%rsp), %rdi
movl $0x1, %edx
callq 0x2190
movl 0x278(%rsp), %eax
leaq 0xf(%rsp), %rsi
movb %al, (%rsi)
leaq 0x28(%rsp), %rdi
movl $0x1, %edx
callq 0x2190
movq (%r15), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movb $0x1, 0xd(%rsp)
movl %ebx, %r13d
movl %ebx, 0x1c(%rsp)
testl %ebx, %ebx
jle 0x41fc
movb $0x1, %al
xorl %ebp, %ebp
leaq 0x28(%rsp), %r12
xorl %ebx, %ebx
movq (%r15), %rcx
movq (%rcx,%rbp,8), %rcx
movsd (%rcx,%rbx,8), %xmm0
ucomisd %xmm1, %xmm0
jne 0x4158
jnp 0x4199
cvttsd2si %xmm1, %eax
movb %al, 0xe(%rsp)
movl $0x1, %edx
movq %r12, %rdi
leaq 0xd(%rsp), %rsi
callq 0x2190
movl $0x1, %edx
movq %r12, %rdi
leaq 0xe(%rsp), %rsi
callq 0x2190
movq (%r15), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%rbx,8), %xmm1
movb $0x1, 0xd(%rsp)
movb $0x1, %al
jmp 0x41e4
cmpb $-0x1, %al
je 0x41a5
incb %al
movb %al, 0xd(%rsp)
jmp 0x41e4
movsd %xmm1, 0x10(%rsp)
cvttsd2si %xmm1, %eax
movb %al, 0xe(%rsp)
movl $0x1, %edx
movq %r12, %rdi
leaq 0xd(%rsp), %rsi
callq 0x2190
movl $0x1, %edx
movq %r12, %rdi
leaq 0xe(%rsp), %rsi
callq 0x2190
movb $0x1, 0xd(%rsp)
movb $0x1, %al
movsd 0x10(%rsp), %xmm1
incq %rbx
cmpq %rbx, %r13
jne 0x4144
incq %rbp
cmpq %r13, %rbp
jne 0x4142
cvttsd2si %xmm1, %eax
movb %al, 0xe(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0xd(%rsp), %rsi
movl $0x1, %edx
callq 0x2190
leaq 0x28(%rsp), %rdi
leaq 0xe(%rsp), %rsi
movl $0x1, %edx
callq 0x2190
movq (%r14), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movb $0x1, 0xd(%rsp)
cmpl $0x0, 0x1c(%rsp)
jle 0x430b
movb $0x1, %al
xorl %r12d, %r12d
leaq 0x28(%rsp), %r15
leaq 0xe(%rsp), %rbp
xorl %ebx, %ebx
movq (%r14), %rcx
movq (%rcx,%r12,8), %rcx
movsd (%rcx,%rbx,8), %xmm0
ucomisd %xmm1, %xmm0
jne 0x426b
jnp 0x42aa
cvttsd2si %xmm1, %eax
movb %al, 0xe(%rsp)
movl $0x1, %edx
movq %r15, %rdi
leaq 0xd(%rsp), %rsi
callq 0x2190
movl $0x1, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2190
movq (%r14), %rax
movq (%rax,%r12,8), %rax
movsd (%rax,%rbx,8), %xmm1
movb $0x1, 0xd(%rsp)
movb $0x1, %al
jmp 0x42f3
cmpb $-0x1, %al
je 0x42b6
incb %al
movb %al, 0xd(%rsp)
jmp 0x42f3
movsd %xmm1, 0x10(%rsp)
cvttsd2si %xmm1, %eax
movb %al, 0xe(%rsp)
movl $0x1, %edx
movq %r15, %rdi
leaq 0xd(%rsp), %rsi
callq 0x2190
movl $0x1, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2190
movb $0x1, 0xd(%rsp)
movb $0x1, %al
movsd 0x10(%rsp), %xmm1
incq %rbx
cmpq %rbx, %r13
jne 0x4257
incq %r12
cmpq %r13, %r12
jne 0x4255
cvttsd2si %xmm1, %eax
movb %al, 0xe(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0xd(%rsp), %rsi
movl $0x1, %edx
callq 0x2190
leaq 0x28(%rsp), %rdi
leaq 0xe(%rsp), %rsi
movl $0x1, %edx
callq 0x2190
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movb $0x1, 0xd(%rsp)
cmpl $0x0, 0x1c(%rsp)
jle 0x4429
movb $0x1, %al
xorl %ebp, %ebp
leaq 0x28(%rsp), %r14
leaq 0xd(%rsp), %r15
leaq 0xe(%rsp), %r12
xorl %ebx, %ebx
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movq (%rcx,%rbp,8), %rcx
movsd (%rcx,%rbx,8), %xmm0
ucomisd %xmm1, %xmm0
jne 0x4388
jnp 0x43ca
cvttsd2si %xmm1, %eax
movb %al, 0xe(%rsp)
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2190
movl $0x1, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2190
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%rbx,8), %xmm1
movb $0x1, 0xd(%rsp)
movb $0x1, %al
jmp 0x4411
cmpb $-0x1, %al
je 0x43d6
incb %al
movb %al, 0xd(%rsp)
jmp 0x4411
movsd %xmm1, 0x10(%rsp)
cvttsd2si %xmm1, %eax
movb %al, 0xe(%rsp)
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2190
movl $0x1, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2190
movb $0x1, 0xd(%rsp)
movb $0x1, %al
movsd 0x10(%rsp), %xmm1
incq %rbx
cmpq %rbx, %r13
jne 0x436f
incq %rbp
cmpq %r13, %rbp
jne 0x436d
cvttsd2si %xmm1, %eax
movb %al, 0xe(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0xd(%rsp), %rsi
movl $0x1, %edx
callq 0x2190
leaq 0x28(%rsp), %rdi
leaq 0xe(%rsp), %rsi
movl $0x1, %edx
callq 0x2190
leaq 0x28(%rsp), %rdi
callq 0x21b0
movq 0x3b66(%rip), %rax      # 0x7fd0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x30(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x28(%rsp,%rcx)
callq 0x20f0
leaq 0x120(%rsp), %rdi
callq 0x2080
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x44b1
jmp 0x44b1
jmp 0x44b1
jmp 0x44b1
jmp 0x44b1
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x21c0
movq %rbx, %rdi
callq 0x2210