// File: /workspace/github_cpp_makefile_star2_O3/sile[P]mphf/mkmphf.cc
// Function: main
int main(int argc, char** argv) {
  if(argc < 3) {
    std::cerr << "Usage: mkmphf [--mapping-loop-limit=<N>] [--hash-code-scale=<D>] [--hash-seed=<N>] <index> <keyset>" << std::endl;
    return 1;
  }

  int param_i=1;
  int loop_limit=32;
  int hash_seed=-1;
  double hash_code_scale=2.09;
  
  for(; param_i < argc; param_i++) {
    if(strncmp(argv[param_i], OPT1"=", strlen(OPT1"="))==0) {
      loop_limit = atoi(argv[param_i]+strlen(OPT1"="));
    } else if (strncmp(argv[param_i], OPT2"=", strlen(OPT2"="))==0) {
      hash_code_scale = atof(argv[param_i]+strlen(OPT2"="));
    } else if (strncmp(argv[param_i], OPT3"=", strlen(OPT3"="))==0) {
      hash_seed = atoi(argv[param_i]+strlen(OPT3"="));
    } else if (strncmp(argv[param_i], "--", 2) != 0) {
      break;
    } else {
      std::cerr << "Usage: mkmphf [--mapping-loop-limit=<N>] [--hash-code-scale=<D>] <index> <keyset>" << std::endl;
      return 1;      
    }
  }

  const char* keyset_filepath = argv[param_i+1];
  const char* index_filepath = argv[param_i];

  std::cerr << "= Initialize" << std::endl;
  MPHF::Generator gen(keyset_filepath, hash_code_scale, hash_seed);
  if(!gen) {
    std::cerr << "Can't open file(or file is empty): " << keyset_filepath << std::endl;
    return 1;    
  }

  std::cerr << "  == key count: " << gen.key_count << std::endl;
  std::cerr << "  == hash value limit: " << gen.hash_value_limit << std::endl;
  std::cerr << "DONE" << std::endl;
  
  std::cerr << "= Mapping Step: " << std::endl;
  int loop_count=0;
  for(; loop_count < loop_limit; loop_count++) {
    std::cerr << " == loop: " << loop_count+1 << '/' << loop_limit << std::endl;
    if(gen.mapping()==true)
      break;
  }
  if(loop_count==loop_limit) {
    std::cerr << "Failure: loop limit exceeded" << std::endl;
    return 1;
  }
  std::cerr << "Done" << std::endl;
    
  std::cerr << "= Assigning Step: " << std::endl;
  gen.assigning();
  std::cerr << "Done" << std::endl;

  std::cerr << "= Ranking Step: " << std::endl;
  gen.ranking();
  std::cerr << "Done" << std::endl;

  std::cerr << "= Save: " << index_filepath << std::endl;
  std::ofstream out(index_filepath);
  if(!out) {
    std::cerr << "Can't open file: " << index_filepath << std::endl;
    return 1;
  }
  gen.save(out);
  std::cerr << "Done" << std::endl;

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
cmpl $0x3, %edi
jge 0x240e
movq 0x3c27(%rip), %rbx      # 0x5ff0
leaq 0x1c80(%rip), %rsi      # 0x4050
movl $0x63, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movl $0x1, %ebx
jmp 0x2b96
movq %rsi, %r15
movl %edi, %r14d
movl $0x20, 0x4(%rsp)
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movsd 0x1bdd(%rip), %xmm0     # 0x4008
movsd %xmm0, 0x10(%rsp)
movl $0x1, %r13d
leaq 0x1c76(%rip), %rbx      # 0x40b4
leaq 0x1c85(%rip), %r12      # 0x40ca
movq (%r15,%r13,8), %rbp
movl $0x15, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x20c0
testl %eax, %eax
je 0x249e
movl $0x12, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x20c0
testl %eax, %eax
je 0x24b0
movl $0xc, %edx
movq %rbp, %rdi
leaq 0x1c5d(%rip), %rsi      # 0x40dd
callq 0x20c0
testl %eax, %eax
jne 0x299c
addq $0xc, %rbp
movq %rbp, %rdi
callq 0x2200
movl %eax, (%rsp)
jmp 0x24c2
addq $0x15, %rbp
movq %rbp, %rdi
callq 0x2200
movl %eax, 0x4(%rsp)
jmp 0x24c2
addq $0x12, %rbp
movq %rbp, %rdi
callq 0x21b0
movsd %xmm0, 0x10(%rsp)
incq %r13
cmpq %r13, %r14
jne 0x2445
movl %r14d, %r13d
movl %r13d, %eax
movq (%r15,%rax,8), %rcx
movq %rcx, 0x8(%rsp)
movq 0x8(%r15,%rax,8), %rbx
movq 0x3b07(%rip), %r15      # 0x5ff0
leaq 0x1c4c(%rip), %rsi      # 0x413c
movl $0xc, %edx
movq %r15, %rdi
callq 0x21a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movsd 0x10(%rsp), %xmm0
movl (%rsp), %edx
callq 0x2bd4
cmpl $0x0, 0x28(%r15)
je 0x2746
movq 0x3aa1(%rip), %rdi      # 0x5ff0
leaq 0x1c17(%rip), %rsi      # 0x416d
movl $0x10, %edx
callq 0x21a0
movl 0x40(%rsp), %esi
movq 0x3a85(%rip), %rdi      # 0x5ff0
callq 0x20f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x3a4f(%rip), %rdi      # 0x5ff0
leaq 0x1bd6(%rip), %rsi      # 0x417e
movl $0x17, %edx
callq 0x21a0
movl 0x44(%rsp), %esi
movq 0x3a33(%rip), %rdi      # 0x5ff0
callq 0x20f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x39fd(%rip), %rbx      # 0x5ff0
leaq 0x1b9c(%rip), %rsi      # 0x4196
movl $0x4, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x39cb(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x39b7(%rip), %rbx      # 0x5ff0
leaq 0x1b5b(%rip), %rsi      # 0x419b
movl $0x10, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x3985(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
xorl %ecx, %ecx
movl 0x4(%rsp), %eax
testl %eax, %eax
cmovgl %eax, %ecx
movl %ecx, (%rsp)
movl %ecx, %r12d
negl %r12d
movl $0x1, %r14d
movq 0x3957(%rip), %r15      # 0x5ff0
leaq 0x48(%rsp), %r13
leaq 0x18(%rsp), %rbx
leal (%r12,%r14), %eax
cmpl $0x1, %eax
je 0x2789
movl $0xa, %edx
movq %r15, %rdi
leaq 0x1aed(%rip), %rsi      # 0x41ac
callq 0x21a0
movq %r15, %rdi
movl %r14d, %esi
callq 0x2230
movb $0x2f, 0x48(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x21a0
movq %rax, %rdi
movl 0x4(%rsp), %esi
callq 0x2230
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x307e
movq %rbx, %rdi
callq 0x30f2
movq %rbx, %rdi
callq 0x3270
incl %r14d
testb %al, %al
je 0x26a3
addl $-0x2, %r14d
movl %r14d, %eax
jmp 0x278c
movq 0x38a3(%rip), %r14      # 0x5ff0
leaq 0x19f5(%rip), %rsi      # 0x4149
movl $0x23, %edx
movq %r14, %rdi
callq 0x21a0
testq %rbx, %rbx
je 0x29c8
movq %rbx, %rdi
callq 0x20b0
movq 0x3877(%rip), %rdi      # 0x5ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x21a0
jmp 0x29e0
movl (%rsp), %eax
cmpl 0x4(%rsp), %eax
jne 0x27e2
movq 0x3857(%rip), %rbx      # 0x5ff0
leaq 0x1a17(%rip), %rsi      # 0x41b7
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x3825(%rip), %rdi      # 0x5ff0
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2100
jmp 0x2b8c
movq 0x3807(%rip), %rbx      # 0x5ff0
leaq 0x19e4(%rip), %rsi      # 0x41d4
movl $0x4, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x37d5(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x37c1(%rip), %rbx      # 0x5ff0
leaq 0x19a3(%rip), %rsi      # 0x41d9
movl $0x12, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x378f(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x18(%rsp), %rdi
callq 0x2c42
movq 0x3771(%rip), %rbx      # 0x5ff0
leaq 0x194e(%rip), %rsi      # 0x41d4
movl $0x4, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x373f(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x372b(%rip), %rbx      # 0x5ff0
leaq 0x1920(%rip), %rsi      # 0x41ec
movl $0x10, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x36f9(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x30(%rsp), %rdi
callq 0x3a60
movq 0x36db(%rip), %rbx      # 0x5ff0
leaq 0x18b8(%rip), %rsi      # 0x41d4
movl $0x4, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x36a9(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x3695(%rip), %rbx      # 0x5ff0
leaq 0x189b(%rip), %rsi      # 0x41fd
movl $0x8, %edx
movq %rbx, %rdi
callq 0x21a0
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x2a15
movq %r14, %rdi
callq 0x20b0
movq 0x3664(%rip), %rdi      # 0x5ff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x21a0
jmp 0x2a2c
cmpb $0x2d, (%rbp)
jne 0x24d1
cmpb $0x2d, 0x1(%rbp)
jne 0x24d1
movq 0x3639(%rip), %rbx      # 0x5ff0
leaq 0x172c(%rip), %rsi      # 0x40ea
movl $0x51, %edx
jmp 0x23d5
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x35f2(%rip), %rdi      # 0x5ff0
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2100
jmp 0x2b8c
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x35a6(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x48(%rsp), %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movl $0x10, %edx
callq 0x2190
movq 0x48(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x68(%rsp,%rax)
je 0x2aba
movq 0x356b(%rip), %rbx      # 0x5ff0
leaq 0x177a(%rip), %rsi      # 0x4206
movl $0x11, %edx
movq %rbx, %rdi
callq 0x21a0
testq %r14, %r14
je 0x2b13
movq %r14, %rdi
callq 0x20b0
movq 0x3543(%rip), %rdi      # 0x5ff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x21a0
jmp 0x2b2a
leaq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2e88
movq 0x3520(%rip), %rbx      # 0x5ff0
leaq 0x16fd(%rip), %rsi      # 0x41d4
movl $0x4, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x34ee(%rip), %rdi      # 0x5ff0
callq 0x2040
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x2100
jmp 0x2b5a
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x34a8(%rip), %rdi      # 0x5ff0
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2100
movq 0x346f(%rip), %rax      # 0x5fd0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x50(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x48(%rsp,%rcx)
callq 0x2120
leaq 0x140(%rsp), %rdi
callq 0x2080
leaq 0x18(%rsp), %rdi
callq 0x2f56
movl %ebx, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2bbf
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x21e0
jmp 0x2bc2
jmp 0x2bbf
jmp 0x2bbf
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2f56
movq %rbx, %rdi
callq 0x2240