// File: shancheng[P]shancheng/src/sudoku.cpp
// Function: (anonymous namespace)::Sudoku::Init()
bool Init() {
    char buf[1024];
    FILE* fp = fopen(options.opt_file.c_str(), "r");
    boost::shared_ptr<FILE> fileguard(fp, fclose);
    if (fp == NULL) {
      cerr << "Failed to open file " << options.opt_file << "\n";
      return false;
    }
    uint32_t row = 0;
    while (fgets(buf, sizeof(buf), fp) != NULL) {
      uint32_t col = 0;
      char* tok = strtok(buf, " ");
      while (tok != NULL) {
        Cell& cell = cells_[row][col];
        cell.row = row;
        cell.col = col;
        cell.rowflag = &rowflags_[row];
        cell.colflag = &colflags_[col];
        cell.blockflag = &blockflags_[row / options.opt_blocksize][col / options.opt_blocksize];
        cell.value = strtoull(tok, NULL, 10);
        cell.SetFlag(cell.value);
        ++col;
        tok = strtok(NULL, " ");
      }
      ++row;
    }
    Print(cout);
    if (options.opt_debug) {
      cout << "\nDetails:\n";
      cout << "-----------------------------------------------------------\n";
    }
    for (uint32_t row = 0; row < options.opt_size; ++row) {
      for (uint32_t col = 0; col < options.opt_size; ++col) {
        Cell& cell = cells_[row][col];
        if (cell.value == 0) {
          uint32_t flags = *cell.rowflag | *cell.colflag | *cell.blockflag;
          for (uint32_t i = 1; i <= options.opt_size; ++i) {
            if (!CheckBit(flags, i)) {
              cell.candidates.push_back(i);
            }
          }
          cell.key = MAXSIZE * MAXSIZE * cell.candidates.size() + MAXSIZE * cell.row + cell.col;
          vec_.push_back(&cell);
        }
        if (options.opt_debug) {
          cout << cells_[row][col];
        }
      }
    }
    sort(vec_.begin(), vec_.end(), CellComparator());
    if (options.opt_debug) {
      cout << "\nEmpty cells:\n";
      cout << "-----------------------------------------------------------\n";
      for (auto it = vec_.begin(); it != vec_.end(); ++it) {
        cout << *(*it);
      }
    }
    return true;
  }

// Assembly:
subq $0x4d8, %rsp            # imm = 0x4D8
movq %rdi, 0x4c8(%rsp)
movq 0x4c8(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x19fb5(%rip), %rdi     # 0x21378
callq 0x6100
movq %rax, %rdi
leaq 0xfd04(%rip), %rsi      # 0x170d6
callq 0x63c0
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
movq 0x19baa(%rip), %rdx     # 0x20fa0
callq 0xa890
cmpq $0x0, 0xb8(%rsp)
jne 0x748d
movq 0x19bdf(%rip), %rdi     # 0x20ff0
leaq 0xfcc0(%rip), %rsi      # 0x170d8
callq 0x62e0
movq %rax, 0x20(%rsp)
jmp 0x7424
movq 0x20(%rsp), %rdi
leaq 0x19f48(%rip), %rsi     # 0x21378
callq 0x62c0
movq %rax, 0x18(%rsp)
jmp 0x743c
movq 0x18(%rsp), %rdi
leaq 0xfc24(%rip), %rsi      # 0x1706c
callq 0x62e0
jmp 0x744f
movb $0x0, 0x4d7(%rsp)
movl $0x1, 0x98(%rsp)
jmp 0x791d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xa960
jmp 0x793b
movl $0x0, 0x94(%rsp)
movq 0xb8(%rsp), %rdx
leaq 0xc0(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x6500
movq %rax, 0x10(%rsp)
jmp 0x74b9
movq 0x10(%rsp), %rax
cmpq $0x0, %rax
je 0x7649
movl $0x0, 0x90(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xfbd8(%rip), %rsi      # 0x170ba
callq 0x64e0
movq %rax, 0x88(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x7633
movq 0x28(%rsp), %rax
movl 0x94(%rsp), %ecx
imulq $0x708, %rcx, %rdx      # imm = 0x708
movq %rax, %rcx
addq %rdx, %rcx
movl 0x90(%rsp), %edx
leaq (%rdx,%rdx,8), %rdx
leaq (%rcx,%rdx,8), %rcx
movq %rcx, 0x80(%rsp)
movl 0x94(%rsp), %edx
movq 0x80(%rsp), %rcx
movl %edx, (%rcx)
movl 0x90(%rsp), %edx
movq 0x80(%rsp), %rcx
movl %edx, 0x4(%rcx)
movl 0x94(%rsp), %ecx
leaq 0xafc8(%rax,%rcx,4), %rdx
movq 0x80(%rsp), %rcx
movq %rdx, 0x10(%rcx)
movl 0x90(%rsp), %ecx
leaq 0xb02c(%rax,%rcx,4), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x18(%rax)
movl 0x94(%rsp), %eax
movl 0x19e08(%rip), %esi     # 0x2139c
xorl %edx, %edx
movl %edx, 0xc(%rsp)
divl %esi
movl 0xc(%rsp), %edx
movl %eax, %ecx
movq 0x28(%rsp), %rax
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,4), %rcx
movl 0x90(%rsp), %eax
divl %esi
movl %eax, %edx
movl 0xc(%rsp), %eax
leaq 0xb090(%rcx,%rdx,4), %rdx
movq 0x80(%rsp), %rcx
movq %rdx, 0x20(%rcx)
movq 0x88(%rsp), %rdi
movl %eax, %esi
movl $0xa, %edx
callq 0x6440
movl %eax, %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x80(%rsp), %rdi
movl 0x8(%rdi), %esi
callq 0x7ab0
jmp 0x7605
movl 0x90(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x90(%rsp)
xorl %eax, %eax
movl %eax, %edi
leaq 0xfa99(%rip), %rsi      # 0x170ba
callq 0x64e0
movq %rax, 0x88(%rsp)
jmp 0x74ef
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x7498
movq 0x28(%rsp), %rdi
movq 0x19963(%rip), %rsi     # 0x20fb8
callq 0x7b00
jmp 0x765c
testb $0x1, 0x19d3d(%rip)     # 0x213a0
je 0x7691
movq 0x1994c(%rip), %rdi     # 0x20fb8
leaq 0xfa7a(%rip), %rsi      # 0x170ed
callq 0x62e0
jmp 0x767a
movq 0x19937(%rip), %rdi     # 0x20fb8
leaq 0xf9ea(%rip), %rsi      # 0x17072
callq 0x62e0
jmp 0x768f
jmp 0x7691
movl $0x0, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0x19cf5(%rip), %eax     # 0x21398
jae 0x782e
movl $0x0, 0x78(%rsp)
movl 0x78(%rsp), %eax
cmpl 0x19cdd(%rip), %eax     # 0x21398
jae 0x781c
movq 0x28(%rsp), %rax
movl 0x7c(%rsp), %ecx
imulq $0x708, %rcx, %rcx      # imm = 0x708
addq %rcx, %rax
movl 0x78(%rsp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x77d2
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax), %eax
movq 0x70(%rsp), %rcx
movq 0x18(%rcx), %rcx
orl (%rcx), %eax
movq 0x70(%rsp), %rcx
movq 0x20(%rcx), %rcx
orl (%rcx), %eax
movl %eax, 0x6c(%rsp)
movl $0x1, 0x68(%rsp)
movl 0x68(%rsp), %eax
cmpl 0x19c6e(%rip), %eax     # 0x21398
ja 0x7777
movl 0x6c(%rsp), %edi
movl 0x68(%rsp), %esi
callq 0x7be0
movb %al, 0xb(%rsp)
jmp 0x773f
movb 0xb(%rsp), %al
testb $0x1, %al
jne 0x7768
jmp 0x7749
movq 0x70(%rsp), %rdi
addq $0x28, %rdi
movl 0x68(%rsp), %eax
movl %eax, 0x64(%rsp)
leaq 0x64(%rsp), %rsi
callq 0xa910
jmp 0x7766
jmp 0x7768
jmp 0x776a
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x7720
movq 0x70(%rsp), %rdi
addq $0x28, %rdi
callq 0xa940
movq 0x28(%rsp), %rdi
imulq $0x271, %rax, %rcx      # imm = 0x271
movq 0x70(%rsp), %rax
movl (%rax), %r8d
movl 0x4(%rax), %edx
movl %r8d, %esi
leal (%rsi,%rsi,4), %r8d
movl %r8d, %esi
leal (%rsi,%rsi,4), %esi
addq %rsi, %rcx
addq %rdx, %rcx
movq %rcx, 0x40(%rax)
addq $0xb0f8, %rdi           # imm = 0xB0F8
movq 0x70(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x58(%rsp), %rsi
callq 0x7c10
jmp 0x77d0
jmp 0x77d2
testb $0x1, 0x19bc7(%rip)     # 0x213a0
je 0x780a
movq 0x28(%rsp), %rax
movl 0x7c(%rsp), %ecx
imulq $0x708, %rcx, %rcx      # imm = 0x708
addq %rcx, %rax
movl 0x78(%rsp), %ecx
leaq (%rcx,%rcx,8), %rcx
leaq (%rax,%rcx,8), %rsi
movq 0x197b7(%rip), %rdi     # 0x20fb8
callq 0x7c40
jmp 0x7808
jmp 0x780a
jmp 0x780c
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
jmp 0x76b1
jmp 0x781e
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x7699
movq 0x28(%rsp), %rdi
addq $0xb0f8, %rdi           # imm = 0xB0F8
movq %rdi, (%rsp)
callq 0x7da0
movq (%rsp), %rdi
movq %rax, 0x50(%rsp)
callq 0x7dd0
movq %rax, 0x48(%rsp)
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x7d60
jmp 0x7867
testb $0x1, 0x19b32(%rip)     # 0x213a0
je 0x790a
movq 0x1973d(%rip), %rdi     # 0x20fb8
leaq 0xf876(%rip), %rsi      # 0x170f8
callq 0x62e0
jmp 0x7889
movq 0x19728(%rip), %rdi     # 0x20fb8
leaq 0xf7db(%rip), %rsi      # 0x17072
callq 0x62e0
jmp 0x789e
movq 0x28(%rsp), %rdi
addq $0xb0f8, %rdi           # imm = 0xB0F8
callq 0x7da0
movq %rax, 0x38(%rsp)
movq 0x28(%rsp), %rdi
addq $0xb0f8, %rdi           # imm = 0xB0F8
callq 0x7dd0
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x7e00
testb $0x1, %al
jne 0x78df
jmp 0x7908
leaq 0x38(%rsp), %rdi
callq 0x7e40
movq (%rax), %rsi
movq 0x196c5(%rip), %rdi     # 0x20fb8
callq 0x7c40
jmp 0x78fa
jmp 0x78fc
leaq 0x38(%rsp), %rdi
callq 0x7e50
jmp 0x78b4
jmp 0x790a
movb $0x1, 0x4d7(%rsp)
movl $0x1, 0x98(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xa960
movb 0x4d7(%rsp), %al
andb $0x1, %al
addq $0x4d8, %rsp            # imm = 0x4D8
retq
movq 0xa0(%rsp), %rdi
callq 0x65c0
nopl (%rax,%rax)