// File: /workspace/github_cpp_makefile_star2_O1/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 0x1c40(%rip), %rsi      # 0x4010
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 0x2b91
movq %rsi, %r15
movl %edi, %r14d
movl $0x20, 0x4(%rsp)
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movsd 0x1bdc(%rip), %xmm0     # 0x4008
movsd %xmm0, 0x10(%rsp)
movl $0x1, %r13d
leaq 0x1c35(%rip), %rbx      # 0x4074
leaq 0x1c44(%rip), %r12      # 0x408a
movq (%r15,%r13,8), %rbp
movl $0x15, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x20c0
testl %eax, %eax
je 0x24a0
movl $0x12, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x20c0
testl %eax, %eax
je 0x24b2
movl $0xc, %edx
movq %rbp, %rdi
leaq 0x1c1c(%rip), %rsi      # 0x409d
callq 0x20c0
testl %eax, %eax
jne 0x27e1
addq $0xc, %rbp
movq %rbp, %rdi
callq 0x2200
movl %eax, 0x8(%rsp)
jmp 0x24c4
addq $0x15, %rbp
movq %rbp, %rdi
callq 0x2200
movl %eax, 0x4(%rsp)
jmp 0x24c4
addq $0x12, %rbp
movq %rbp, %rdi
callq 0x21b0
movsd %xmm0, 0x10(%rsp)
incq %r13
cmpq %r13, %r14
jne 0x2446
movl %r14d, %r13d
movl %r13d, %eax
movq (%r15,%rax,8), %r14
movq 0x8(%r15,%rax,8), %rbx
movq 0x3b0a(%rip), %r15      # 0x5ff0
leaq 0x1c12(%rip), %rsi      # 0x40ff
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 0x8(%rsp), %edx
callq 0x2bd0
cmpl $0x0, 0x28(%r15)
je 0x279e
movq 0x3aa3(%rip), %rdi      # 0x5ff0
leaq 0x1bdc(%rip), %rsi      # 0x4130
movl $0x10, %edx
callq 0x21a0
movl 0x40(%rsp), %esi
movq 0x3a87(%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 0x3a51(%rip), %rdi      # 0x5ff0
leaq 0x1b9b(%rip), %rsi      # 0x4141
movl $0x17, %edx
callq 0x21a0
movl 0x44(%rsp), %esi
movq 0x3a35(%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 0x39ff(%rip), %rbx      # 0x5ff0
leaq 0x1b61(%rip), %rsi      # 0x4159
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 0x39cd(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x39b9(%rip), %rbx      # 0x5ff0
leaq 0x1b20(%rip), %rsi      # 0x415e
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 0x3987(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq %r14, 0x8(%rsp)
xorl %r15d, %r15d
movl 0x4(%rsp), %eax
testl %eax, %eax
cmovgl %eax, %r15d
negl %r15d
movl $0x1, %ecx
movq 0x3959(%rip), %r14      # 0x5ff0
leaq 0x48(%rsp), %r12
leaq 0x18(%rsp), %rbx
movl %ecx, %r13d
leal (%r15,%r13), %eax
cmpl $0x1, %eax
je 0x273f
movl $0xa, %edx
movq %r14, %rdi
leaq 0x1aaf(%rip), %rsi      # 0x416f
callq 0x21a0
movq %r14, %rdi
movl %r13d, %esi
callq 0x2230
movb $0x2f, 0x48(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %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 0x30a2
movq %rbx, %rdi
callq 0x3116
movq %rbx, %rdi
callq 0x3294
leal 0x1(%r13), %ecx
testb %al, %al
je 0x26a1
subl 0x4(%rsp), %r13d
cmpl $0x1, %r13d
jne 0x2815
movq 0x389b(%rip), %rbx      # 0x5ff0
leaq 0x1a1e(%rip), %rsi      # 0x417a
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 0x3869(%rip), %rdi      # 0x5ff0
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2100
jmp 0x2b87
movq 0x384b(%rip), %r14      # 0x5ff0
leaq 0x1960(%rip), %rsi      # 0x410c
movl $0x23, %edx
movq %r14, %rdi
callq 0x21a0
testq %rbx, %rbx
je 0x29c8
movq %rbx, %rdi
callq 0x20b0
movq 0x381f(%rip), %rdi      # 0x5ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x21a0
jmp 0x29e0
leaq 0x18c2(%rip), %rsi      # 0x40aa
movl $0x2, %edx
movq %rbp, %rdi
callq 0x20c0
testl %eax, %eax
jne 0x24d3
movq 0x37ec(%rip), %rbx      # 0x5ff0
leaq 0x18a2(%rip), %rsi      # 0x40ad
movl $0x51, %edx
jmp 0x23d5
movq 0x37d4(%rip), %rbx      # 0x5ff0
leaq 0x1974(%rip), %rsi      # 0x4197
movl $0x4, %edx
movq %rbx, %rdi
callq 0x21a0
movq 0x8(%rsp), %r14
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x379d(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x3789(%rip), %rbx      # 0x5ff0
leaq 0x192e(%rip), %rsi      # 0x419c
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 0x3757(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x18(%rsp), %rdi
callq 0x2c3e
movq 0x3739(%rip), %rbx      # 0x5ff0
leaq 0x18d9(%rip), %rsi      # 0x4197
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 0x3707(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x36f3(%rip), %rbx      # 0x5ff0
leaq 0x18ab(%rip), %rsi      # 0x41af
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 0x36c1(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x30(%rsp), %rdi
callq 0x3aac
movq 0x36a3(%rip), %rbx      # 0x5ff0
leaq 0x1843(%rip), %rsi      # 0x4197
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 0x3671(%rip), %rdi      # 0x5ff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x365d(%rip), %rbx      # 0x5ff0
leaq 0x1826(%rip), %rsi      # 0x41c0
movl $0x8, %edx
movq %rbx, %rdi
callq 0x21a0
testq %r14, %r14
je 0x2a15
movq %r14, %rdi
callq 0x20b0
movq 0x3635(%rip), %rdi      # 0x5ff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x21a0
jmp 0x2a2c
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 0x2b87
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 %r14, %rsi
movl $0x10, %edx
callq 0x2190
movq 0x48(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x68(%rsp,%rax)
je 0x2ab5
movq 0x3570(%rip), %rbx      # 0x5ff0
leaq 0x1742(%rip), %rsi      # 0x41c9
movl $0x11, %edx
movq %rbx, %rdi
callq 0x21a0
testq %r14, %r14
je 0x2b0e
movq %r14, %rdi
callq 0x20b0
movq 0x3548(%rip), %rdi      # 0x5ff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x21a0
jmp 0x2b25
leaq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2eb6
movq 0x3525(%rip), %rbx      # 0x5ff0
leaq 0x16c5(%rip), %rsi      # 0x4197
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 0x34f3(%rip), %rdi      # 0x5ff0
callq 0x2040
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x2100
jmp 0x2b55
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 0x34ad(%rip), %rdi      # 0x5ff0
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2100
movq 0x3474(%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 0x2f84
movl %ebx, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2bba
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x21e0
jmp 0x2bbd
jmp 0x2bba
jmp 0x2bba
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2f84
movq %rbx, %rdi
callq 0x2240
nop