// File: kobanium[P]Ray/src/mcts/UctRating.cpp
// Function: InputLargePattern(char const*, fm_t*, index_hash_t*)
static void 
InputLargePattern( const char *filename, fm_t params[], index_hash_t pat_index[] )
{
  FILE *fp;
  int index, idx = 0;
  unsigned long long hash;
  double weight;

  for (int i = 0; i < HASH_MAX; i++) {
    pat_index[i].hash = 0;
    pat_index[i].index = -1;
  }

#if defined (_WIN32)
  errno_t err = fopen_s(&fp, filename, "r");
  if (err != 0) {
    std::cerr << "can not open -" << filename << "-" << std::endl;
    exit(1);
  }
  while (fscanf_s(fp, "%d%llu%le", &index, &hash, &weight) != EOF) {
    pat_index[index].hash = hash;
    pat_index[index].index = idx;
    params[idx].w = weight;
    for (int i = 0; i < BTFM_DIMENSION; i++) {
      if (fscanf_s(fp, "%le", &params[idx].v[i]) == EOF) {
        std::cerr << "Read Error : " << filename << std::endl;
        exit(1);
      }
    }
    idx++;
  }
#else
  fp = fopen(filename, "r");
  if (fp == NULL) {
    std::cerr << "can not open -" << filename << "-" << std::endl;
    exit(1);
  }
  while (fscanf(fp, "%d%llu%le", &index, &hash, &weight) != EOF) {
    pat_index[index].hash = hash;
    pat_index[index].index = idx;
    params[idx].w = weight;
    for (int i = 0; i < BTFM_DIMENSION; i++) {
      if (fscanf(fp, "%le", &params[idx].v[i]) == EOF) {
        std::cerr << "Read Error : " << filename << std::endl;
        exit(1);
      }
    }
    idx++;
  }
#endif
  fclose(fp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x100000, -0x3c(%rbp)  # imm = 0x100000
jge 0x87202
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x871c2
movq -0x8(%rbp), %rdi
leaq 0x2631e(%rip), %rsi     # 0xad52b
callq 0x7680
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x87264
movq 0x5fdcc(%rip), %rdi     # 0xe6ff0
leaq 0x25ed5(%rip), %rsi     # 0xad100
callq 0x7530
movq %rax, %rdi
movq -0x8(%rbp), %rsi
callq 0x7530
movq %rax, %rdi
leaq 0x24eb5(%rip), %rsi     # 0xac0fb
callq 0x7530
movq %rax, %rdi
movq 0x5fd13(%rip), %rsi     # 0xe6f68
callq 0x75b0
movl $0x1, %edi
callq 0x76a0
jmp 0x87266
movq -0x20(%rbp), %rdi
leaq 0x27eb0(%rip), %rsi     # 0xaf121
leaq -0x24(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x38(%rbp), %r8
movb $0x0, %al
callq 0x7a00
cmpl $-0x1, %eax
je 0x87365
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0x28(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movsd -0x38(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movl $0x0, -0x40(%rbp)
cmpl $0x5, -0x40(%rbp)
jge 0x87357
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rdx
movslq -0x28(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdx
addq $0x8, %rdx
movslq -0x40(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x27e17(%rip), %rsi     # 0xaf11d
movb $0x0, %al
callq 0x7a00
cmpl $-0x1, %eax
jne 0x8734a
movq 0x5fcd7(%rip), %rdi     # 0xe6ff0
leaq 0x25df2(%rip), %rsi     # 0xad112
callq 0x7530
movq %rax, %rdi
movq -0x8(%rbp), %rsi
callq 0x7530
movq %rax, %rdi
movq 0x5fc2d(%rip), %rsi     # 0xe6f68
callq 0x75b0
movl $0x1, %edi
callq 0x76a0
jmp 0x8734c
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x872d7
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x87266
movq -0x20(%rbp), %rdi
callq 0x7540
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop