// File: /workspace/github_cpp_makefile_star2_O3/lioncedric[P]cimpressGridCoverage/src/main.cc
// Function: main
int main(int argc, char ** argv) {
    //init parameters
    MPI::Init(argc, argv);
    string puzzle_path = "puzzle.txt";
    int duration = 8;
    int nbNeigbours = 200;
    if (argc > 3) {
        puzzle_path = argv[1];
        duration = atoi(argv[2]);
        nbNeigbours = atoi(argv[3]);
    } else {
        if (MPI::COMM_WORLD.Get_rank() == 0)
            cout << "Usage : " << argv[0] << " " << "/puzzle/path.txt int_duration int_nbNeigbours" << endl;
        MPI::Finalize();
        return -1;
    }

    //read the puzzle from file and ad a border full of 0
    std::ifstream file(puzzle_path.c_str());
    int width, height;
    file >> width >> height;
    width+=2;
    height+=2;
    int puzzle[width * height];
    for (int y = 0; y <height ; ++y) {
        for (int x = 0; x <width ; ++x) {
	
    		if(y==0 || y==height-1){
			puzzle[y*width+x]=0;
		}else{
			if(x==0 || x==width-1){
				puzzle[y*width+x]=0;
			}else{
        			file >> puzzle[y*width+x];
			}
   		 }
	}
    }
    //process
    algoTabuMPI(puzzle, height, width, nbNeigbours, duration);
    if (MPI::COMM_WORLD.Get_rank() == 0){
	    //retreive the squares result by clearing the puzzle
	    int area[4] = {1, 1, width - 2, height - 2};
	    int squares_removed[height * width * 3];
	    clear_squares(puzzle, width, area, squares_removed);

	    //print json result
	    cout << "Result:"<<endl;
	    cout << result(squares_removed)<<endl;

    }
    MPI::Finalize();
    return 0;


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
leaq -0x8c(%rbp), %rbx
movl %edi, (%rbx)
leaq -0x38(%rbp), %rax
movq %rsi, (%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2200
callq 0x2240
leaq -0x50(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x246c(%rip), %rsi      # 0x5028
leaq 0x246f(%rip), %rdx      # 0x5032
leaq -0x60(%rbp), %rdi
callq 0x2fb4
cmpl $0x4, (%rbx)
jl 0x2e4d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rbx
leaq -0x60(%rbp), %r14
movq 0x8(%r14), %r15
movq %rbx, %rdi
callq 0x20c0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x2220
movq -0x38(%rbp), %rbx
movq 0x10(%rbx), %rdi
callq 0x2230
movl %eax, %r15d
movq 0x18(%rbx), %rdi
callq 0x2230
movl %eax, %ebx
movq -0x60(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
movl $0x8, %edx
callq 0x22b0
leaq -0x2a8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x20e0
leaq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x20e0
movl %ebx, -0x3c(%rbp)
movq %rsp, -0x88(%rbp)
movl -0x30(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, -0x2c(%rbp)
imull %eax, %ecx
leaq 0xf(,%rcx,4), %rax
andq $-0x10, %rax
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
testl %esi, %esi
jle 0x2d00
xorl %r13d, %r13d
leaq -0x2a8(%rbp), %r12
movl %edx, %eax
testl %eax, %eax
jle 0x2cf8
xorl %ebx, %ebx
testl %r13d, %r13d
je 0x2cab
movl -0x2c(%rbp), %ecx
decl %ecx
cmpl %ecx, %r13d
jne 0x2cc5
imull %r13d, %eax
addl %ebx, %eax
cltq
movl $0x0, (%r14,%rax,4)
incl %ebx
movl %edx, %eax
cmpl %edx, %ebx
jl 0x2c9c
jmp 0x2cf3
movl %r13d, %ecx
imull %eax, %ecx
addl %ebx, %ecx
movslq %ecx, %rcx
leaq (%r14,%rcx,4), %rsi
testl %ebx, %ebx
je 0x2ceb
decl %eax
cmpl %eax, %ebx
je 0x2ceb
movq %r12, %rdi
callq 0x20e0
movl -0x30(%rbp), %edx
jmp 0x2cbb
movl $0x0, (%rsi)
jmp 0x2cbb
movl -0x2c(%rbp), %esi
movl %edx, %eax
incl %r13d
cmpl %esi, %r13d
jl 0x2c96
movq %r14, %rdi
movl -0x3c(%rbp), %ecx
movl %r15d, %r8d
leaq -0x50(%rbp), %r12
callq 0x241c
movq 0x429f(%rip), %rax      # 0x6fb8
movq 0x8(%rax), %rdi
leaq -0x80(%rbp), %rsi
callq 0x21f0
cmpl $0x0, -0x80(%rbp)
jne 0x2e2e
movq %rsp, %r15
movabsq $0x100000001, %rax      # imm = 0x100000001
leaq -0xa0(%rbp), %rdx
movq %rax, (%rdx)
movl -0x30(%rbp), %eax
leal -0x2(%rax), %ecx
movl %ecx, 0x8(%rdx)
movl -0x2c(%rbp), %ecx
leal -0x2(%rcx), %esi
movl %esi, 0xc(%rdx)
imull %eax, %ecx
leal (%rcx,%rcx,2), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
movl -0x30(%rbp), %esi
movq %r14, %rdi
movq %rbx, %rcx
callq 0x39be
movq 0x4247(%rip), %r14      # 0x6fd0
leaq 0x22da(%rip), %rsi      # 0x506a
movl $0x7, %edx
movq %r14, %rdi
callq 0x21b0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0x4215(%rip), %rdi      # 0x6fd0
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq -0x80(%rbp), %rdi
movq %rbx, %rsi
callq 0x30d0
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq 0x41ed(%rip), %rdi      # 0x6fd0
callq 0x21b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e2b
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2190
movq %r15, %rsp
callq 0x2110
movq -0x88(%rbp), %rsp
leaq -0x2a8(%rbp), %rdi
callq 0x2060
xorl %ebx, %ebx
jmp 0x2f33
movq 0x4164(%rip), %rax      # 0x6fb8
movq 0x8(%rax), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x21f0
cmpl $0x0, -0x2a8(%rbp)
jne 0x2f29
movq 0x4158(%rip), %rbx      # 0x6fd0
leaq 0x21b4(%rip), %rsi      # 0x5033
movl $0x8, %edx
movq %rbx, %rdi
callq 0x21b0
movq -0x38(%rbp), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x2eb4
movq %r14, %rdi
callq 0x20c0
movq 0x4129(%rip), %rdi      # 0x6fd0
movq %r14, %rsi
movq %rax, %rdx
callq 0x21b0
jmp 0x2ecb
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2270
movq 0x40fe(%rip), %rdi      # 0x6fd0
leaq 0x2202(%rip), %rsi      # 0x50db
movl $0x1, %edx
callq 0x21b0
movq 0x40e6(%rip), %rbx      # 0x6fd0
leaq 0x214b(%rip), %rsi      # 0x503c
movl $0x2d, %edx
movq %rbx, %rdi
callq 0x21b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0x40b4(%rip), %rdi      # 0x6fd0
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x2110
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x2f48
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2190
movl %ebx, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f84
jmp 0x2f7f
movq %rax, %rbx
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f87
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x2f87
jmp 0x2f84
jmp 0x2f84
movq %rax, %rbx
jmp 0x2f93
movq %rax, %rbx
leaq -0x2a8(%rbp), %rdi
callq 0x2060
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x2fac
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x2290