// File: Rubenmp[P]Rubik/src/searchBugs.cpp
// Function: main
int main(int argc, char* argv[]){
   Rubik rubik, aux;
   ofstream os;
   vector<char> solution;
   bool boolean = true;
   string file;
   int i = 1;

   if (argv[1][0] == '-' && argv[1][1] == 's' && argc == 2){ // Search mode
     for (unsigned int j=0; j<100000 && boolean; j++){
       aux = rubik = Rubik::randomRubik();
       
       rubik.solve(solution);
       if(!rubik.isSolved()){
         file += "./data/error" + i;
         os.open(file);
         
         // Original rubik is solved, we want original positions to debug
         os << aux;
         os.close();

         file = "";
         boolean = false;
         ++i;
       }
     }
     if (!boolean)
       cout << "There are bugs :D" << endl;
     else
       cout << "There aren't any bugs" << endl;
   }
   else{ // Fix bugs mode
     ifstream is(argv[1]);

     is >> rubik;
     cout << rubik;

     rubik.solveStepByStep(solution);
     cout << rubik;
   }
   
   cout << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x540, %rsp            # imm = 0x540
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x46(%rbp), %rdi
callq 0x106b0
leaq -0x7c(%rbp), %rdi
callq 0x106b0
leaq -0x280(%rbp), %rdi
callq 0x2350
leaq -0x298(%rbp), %rdi
callq 0x28b0
movb $0x1, -0x299(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x22c0
movl $0x1, -0x2c4(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x279d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x73, %eax
jne 0x279d
cmpl $0x2, -0x8(%rbp)
jne 0x279d
movl $0x0, -0x2c8(%rbp)
xorl %eax, %eax
cmpl $0x186a0, -0x2c8(%rbp)  # imm = 0x186A0
movb %al, -0x519(%rbp)
jae 0x25ed
movb -0x299(%rbp), %al
movb %al, -0x519(%rbp)
movb -0x519(%rbp), %al
testb $0x1, %al
jne 0x25fc
jmp 0x2729
leaq -0x2fe(%rbp), %rdi
callq 0x13290
jmp 0x260a
leaq -0x46(%rbp), %rdi
leaq -0x2fe(%rbp), %rsi
callq 0x107d0
movq %rax, -0x528(%rbp)
jmp 0x2623
movq -0x528(%rbp), %rsi
leaq -0x7c(%rbp), %rdi
callq 0x107d0
jmp 0x2635
movb $0x42, -0x30d(%rbp)
leaq -0x46(%rbp), %rdi
leaq -0x298(%rbp), %rsi
leaq -0x30d(%rbp), %rdx
callq 0x130f0
jmp 0x2655
leaq -0x46(%rbp), %rdi
callq 0x10b30
movb %al, -0x529(%rbp)
jmp 0x2666
movb -0x529(%rbp), %al
testb $0x1, %al
jne 0x2713
jmp 0x2676
movslq -0x2c4(%rbp), %rax
leaq 0x13980(%rip), %rsi     # 0x16004
addq %rax, %rsi
leaq -0x2c0(%rbp), %rdi
callq 0x21c0
jmp 0x2695
leaq -0x280(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
movl $0x10, %edx
callq 0x20d0
jmp 0x26af
leaq -0x280(%rbp), %rdi
leaq -0x7c(%rbp), %rsi
callq 0x132d0
jmp 0x26c1
leaq -0x280(%rbp), %rdi
callq 0x22d0
jmp 0x26cf
leaq 0x14eb4(%rip), %rsi     # 0x1758a
leaq -0x2c0(%rbp), %rdi
callq 0x22b0
jmp 0x26e4
movb $0x0, -0x299(%rbp)
movl -0x2c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c4(%rbp)
jmp 0x2713
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x308(%rbp)
movl %eax, -0x30c(%rbp)
jmp 0x2873
jmp 0x2715
movl -0x2c8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c8(%rbp)
jmp 0x25cd
testb $0x1, -0x299(%rbp)
jne 0x2765
movq 0x1888f(%rip), %rdi     # 0x1afc8
leaq 0x138d1(%rip), %rsi     # 0x16011
callq 0x21e0
movq %rax, -0x538(%rbp)
jmp 0x274e
movq -0x538(%rbp), %rdi
movq 0x1885c(%rip), %rsi     # 0x1afb8
callq 0x2210
jmp 0x2763
jmp 0x2798
movq 0x1885c(%rip), %rdi     # 0x1afc8
leaq 0x138b0(%rip), %rsi     # 0x16023
callq 0x21e0
movq %rax, -0x540(%rbp)
jmp 0x2781
movq -0x540(%rbp), %rdi
movq 0x18829(%rip), %rsi     # 0x1afb8
callq 0x2210
jmp 0x2796
jmp 0x2798
jmp 0x282e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x518(%rbp), %rdi
movl $0x8, %edx
callq 0x2390
jmp 0x27b8
leaq -0x518(%rbp), %rdi
leaq -0x46(%rbp), %rsi
callq 0x148b0
jmp 0x27ca
movq 0x187f7(%rip), %rdi     # 0x1afc8
leaq -0x46(%rbp), %rsi
callq 0x132d0
jmp 0x27dc
leaq -0x46(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x12d60
jmp 0x27ee
movq 0x187d3(%rip), %rdi     # 0x1afc8
leaq -0x46(%rbp), %rsi
callq 0x132d0
jmp 0x2800
leaq -0x518(%rbp), %rdi
callq 0x2070
jmp 0x282e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x308(%rbp)
movl %eax, -0x30c(%rbp)
leaq -0x518(%rbp), %rdi
callq 0x2070
jmp 0x2873
movq 0x18793(%rip), %rdi     # 0x1afc8
movq 0x1877c(%rip), %rsi     # 0x1afb8
callq 0x2210
jmp 0x2843
leaq -0x2c0(%rbp), %rdi
callq 0x2110
leaq -0x298(%rbp), %rdi
callq 0x28d0
leaq -0x280(%rbp), %rdi
callq 0x2300
movl -0x4(%rbp), %eax
addq $0x540, %rsp            # imm = 0x540
popq %rbp
retq
leaq -0x2c0(%rbp), %rdi
callq 0x2110
leaq -0x298(%rbp), %rdi
callq 0x28d0
leaq -0x280(%rbp), %rdi
callq 0x2300
movq -0x308(%rbp), %rdi
callq 0x2360
nopw %cs:(%rax,%rax)
nopl (%rax)