// File: /workspace/github_cpp_makefile_star2_O1/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 0x2468(%rip), %rsi      # 0x5028
leaq 0x246b(%rip), %rdx      # 0x5032
leaq -0x60(%rbp), %rdi
callq 0x2fb6
cmpl $0x4, (%rbx)
jl 0x2e4e
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
movl %ebx, -0x3c(%rbp)
leaq -0x2a8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x20e0
leaq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x20e0
movq %rsp, -0x88(%rbp)
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, -0x30(%rbp)
imull %eax, %ecx
leaq 0xf(,%rcx,4), %rax
andq $-0x10, %rax
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
movl -0x30(%rbp), %esi
testl %esi, %esi
jle 0x2cfe
xorl %r13d, %r13d
leaq -0x2a8(%rbp), %r12
movl -0x2c(%rbp), %eax
testl %eax, %eax
jle 0x2cf3
xorl %ebx, %ebx
testl %r13d, %r13d
je 0x2cad
movl -0x30(%rbp), %ecx
decl %ecx
cmpl %ecx, %r13d
jne 0x2cca
imull %r13d, %eax
addl %ebx, %eax
cltq
leaq (%r14,%rax,4), %rsi
movl $0x0, (%rsi)
incl %ebx
movl -0x2c(%rbp), %eax
cmpl %eax, %ebx
jl 0x2c9e
jmp 0x2cf3
testl %ebx, %ebx
sete %cl
leal -0x1(%rax), %edx
cmpl %edx, %ebx
sete %dl
orb %cl, %dl
imull %r13d, %eax
addl %ebx, %eax
cltq
leaq (%r14,%rax,4), %rsi
testb %dl, %dl
jne 0x2cb9
movq %r12, %rdi
callq 0x20e0
jmp 0x2cbf
incl %r13d
movl -0x30(%rbp), %esi
cmpl %esi, %r13d
jl 0x2c95
movl -0x2c(%rbp), %edx
movq %r14, %rdi
movl -0x3c(%rbp), %ecx
movl %r15d, %r8d
leaq -0x50(%rbp), %r12
callq 0x241c
movq 0x429e(%rip), %rax      # 0x6fb8
movq 0x8(%rax), %rdi
leaq -0x80(%rbp), %rsi
callq 0x21f0
cmpl $0x0, -0x80(%rbp)
jne 0x2e2f
movq %rsp, %r15
movabsq $0x100000001, %rax      # imm = 0x100000001
leaq -0xa0(%rbp), %rdx
movq %rax, (%rdx)
movl -0x2c(%rbp), %eax
leal -0x2(%rax), %ecx
movl %ecx, 0x8(%rdx)
movl -0x30(%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 -0x2c(%rbp), %esi
movq %r14, %rdi
movq %rbx, %rcx
callq 0x39f3
movq 0x4246(%rip), %r14      # 0x6fd0
leaq 0x22d9(%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 0x4214(%rip), %rdi      # 0x6fd0
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq -0x80(%rbp), %rdi
movq %rbx, %rsi
callq 0x30cc
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq 0x41ec(%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 0x2e2c
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 0x2f34
movq 0x4163(%rip), %rax      # 0x6fb8
movq 0x8(%rax), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x21f0
cmpl $0x0, -0x2a8(%rbp)
jne 0x2f2a
movq 0x4157(%rip), %rbx      # 0x6fd0
leaq 0x21b3(%rip), %rsi      # 0x5033
movl $0x8, %edx
movq %rbx, %rdi
callq 0x21b0
movq -0x38(%rbp), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x2eb5
movq %r14, %rdi
callq 0x20c0
movq 0x4128(%rip), %rdi      # 0x6fd0
movq %r14, %rsi
movq %rax, %rdx
callq 0x21b0
jmp 0x2ecc
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2270
movq 0x40fd(%rip), %rdi      # 0x6fd0
leaq 0x2201(%rip), %rsi      # 0x50db
movl $0x1, %edx
callq 0x21b0
movq 0x40e5(%rip), %rbx      # 0x6fd0
leaq 0x214a(%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 0x40b3(%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 0x2f49
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 0x2f85
jmp 0x2f80
movq %rax, %rbx
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f88
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x2f88
jmp 0x2f85
jmp 0x2f85
movq %rax, %rbx
jmp 0x2f94
movq %rax, %rbx
leaq -0x2a8(%rbp), %rdi
callq 0x2060
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x2fad
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x2290
nop