// File: /workspace/github_cpp_makefile_star2_O2/byronknoll[P]paqclass/runner.cpp
// Function: main
int main(int argc, char** argv) {
  if (argc < 3 || argc > 4) return -1;
  string train = argv[1];
  if (train[train.length() - 1] != '/') train += '/';
  string test = argv[2];
  string compression_level = "5";
  if (argc == 4) compression_level = argv[3];
  vector<string> labels;
  list(train, &labels);
  map<string, vector<double> > results;
  for (int i = 0; i < labels.size(); ++i) {
    string command = "./PAQclass -" + compression_level + " temp ";
    command += train + labels[i] + " " + test;
    string output = exec(command);
    vector<string> lines;
    split(output, '\n', &lines);
    for (int j = 0; j < lines.size(); ++j) {
      vector<string> cols;
      split(lines[j], '\t', &cols);
      results[cols[0]].push_back(atof(cols[1].c_str()));
    }
  }

  cout << "name\tclass";
  for (int i = 0; i < labels.size(); ++i) {
    cout << "\t" << labels[i];
  }
  cout << endl;

  map<string, vector<double> >::iterator it;
  for (it = results.begin(); it != results.end(); it++) {
    cout << it->first;
    double best = 100;
    int best_index = 0;
    for (int i = 0; i < it->second.size(); ++i) {
      if (it->second[i] < best) {
        best = it->second[i];
        best_index = i;
      }
    }
    cout << "\t" << labels[best_index];
    for (int i = 0; i < it->second.size(); ++i) {
      cout << "\t" << it->second[i];
    }
    cout << endl;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movl %edi, %r14d
leal -0x5(%r14), %eax
cmpl $-0x2, %eax
jae 0x2668
pushq $-0x1
popq %rax
jmp 0x2a41
movq %rsi, %rbx
movq 0x8(%rsi), %rsi
leaq 0xa8(%rsp), %r15
leaq 0x78(%rsp), %rdx
movq %r15, %rdi
callq 0x2b3c
movq (%r15), %rax
movq 0x8(%r15), %rcx
cmpb $0x2f, -0x1(%rax,%rcx)
je 0x26a2
leaq 0xa8(%rsp), %rdi
pushq $0x2f
popq %rsi
callq 0x2140
movq 0x10(%rbx), %rsi
leaq 0x108(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x2b3c
leaq 0x196c(%rip), %rsi      # 0x402b
leaq 0xe8(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x2b3c
cmpl $0x4, %r14d
jne 0x26e8
movq 0x18(%rbx), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x22f0
xorpd %xmm0, %xmm0
movq %rsp, %rsi
movapd %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
leaq 0xa8(%rsp), %rdi
callq 0x258c
leaq 0x80(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorl %ebx, %ebx
leaq 0xc8(%rsp), %r14
leaq 0x128(%rsp), %r12
leaq 0x30(%rsp), %rbp
leaq 0x50(%rsp), %r13
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x5, %rax
cmpq %rbx, %rax
jbe 0x28c6
movq %r14, %rdi
leaq 0x18cf(%rip), %rsi      # 0x402d
leaq 0xe8(%rsp), %rdx
callq 0x2bcd
movq %r12, %rdi
movq %r14, %rsi
leaq 0x18c2(%rip), %rdx      # 0x403a
callq 0x2bae
movq %r14, %rdi
callq 0x20c0
movq %rbx, %rdx
shlq $0x5, %rdx
addq (%rsp), %rdx
movq %rbp, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2c62
movq %r13, %rdi
movq %rbp, %rsi
leaq 0x1892(%rip), %rdx      # 0x403f
callq 0x2bae
movq %r14, %rdi
movq %r13, %rsi
leaq 0x108(%rsp), %rdx
callq 0x2c43
movq %r12, %rdi
movq %r14, %rsi
callq 0x2300
movq %r14, %rdi
callq 0x20c0
movq %r13, %rdi
callq 0x20c0
movq %rbp, %rdi
callq 0x20c0
movq %r14, %rdi
movq %r12, %rsi
callq 0x243c
movq %rbx, 0x20(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movq %r14, %rdi
pushq $0xa
popq %rsi
movq %r13, %rdx
callq 0x24ea
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %rbx, %rax
jbe 0x2899
movq %r12, %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
addq %r14, %rdi
pushq $0x9
popq %rsi
movq %rbp, %rdx
callq 0x24ea
movq 0x30(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x2c9a
movq %rax, %r12
movq 0x30(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x21b0
movsd %xmm0, 0x28(%rsp)
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
callq 0x3470
movq %rbp, %rdi
callq 0x2d00
incq %rbx
addq $0x20, %r14
movq %r15, %r12
jmp 0x281b
movq %r13, %rdi
callq 0x2d00
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
callq 0x20c0
movq %r12, %rdi
callq 0x20c0
movq 0x20(%rsp), %rbx
incq %rbx
jmp 0x273e
movq 0x370b(%rip), %rdi      # 0x5fd8
leaq 0x176d(%rip), %rsi      # 0x4041
callq 0x2170
xorl %r15d, %r15d
movq 0x36f5(%rip), %rbx      # 0x5fd8
leaq 0x1762(%rip), %r14      # 0x404c
xorl %r12d, %r12d
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x5, %rax
cmpq %r12, %rax
jbe 0x2922
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2170
movq (%rsp), %rsi
addq %r15, %rsi
movq %rax, %rdi
callq 0x2160
incq %r12
addq $0x20, %r15
jmp 0x28ed
movq 0x36af(%rip), %rdi      # 0x5fd8
callq 0x20d0
movq 0x90(%rsp), %r14
movq 0x369b(%rip), %rbx      # 0x5fd8
leaq 0x1708(%rip), %r15      # 0x404c
leaq 0x80(%rsp), %rax
cmpq %rax, %r14
je 0x2a06
leaq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x2160
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
xorl %edx, %edx
movsd 0x168e(%rip), %xmm0     # 0x4008
xorl %ebp, %ebp
cmpq %rdx, %rcx
je 0x299a
movsd (%rax,%rdx,8), %xmm1
ucomisd %xmm1, %xmm0
cmoval %edx, %ebp
minsd %xmm0, %xmm1
incq %rdx
movapd %xmm1, %xmm0
jmp 0x297c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2170
movslq %ebp, %rsi
shlq $0x5, %rsi
addq (%rsp), %rsi
movq %rax, %rdi
callq 0x2160
xorl %r12d, %r12d
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
sarq $0x3, %rax
cmpq %r12, %rax
jbe 0x29ee
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2170
movq 0x40(%r14), %rcx
movsd (%rcx,%r12,8), %xmm0
movq %rax, %rdi
callq 0x2280
incq %r12
jmp 0x29bb
movq %rbx, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x20f0
movq %rax, %r14
jmp 0x2944
leaq 0x78(%rsp), %rdi
callq 0x2d2c
movq %rsp, %rdi
callq 0x2d00
leaq 0xe8(%rsp), %rdi
callq 0x20c0
leaq 0x108(%rsp), %rdi
callq 0x20c0
leaq 0xa8(%rsp), %rdi
callq 0x20c0
xorl %eax, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2b0d
jmp 0x2a6d
movq %rax, %rbx
jmp 0x2b05
movq %rax, %rbx
jmp 0x2b1a
movq %rax, %rbx
jmp 0x2b27
jmp 0x2ac5
jmp 0x2ac5
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x2af6
jmp 0x2a94
movq %rax, %rbx
jmp 0x2aa9
movq %rax, %rbx
jmp 0x2ab3
jmp 0x2ac5
movq %rax, %rbx
jmp 0x2aee
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x20c0
leaq 0x50(%rsp), %rdi
callq 0x20c0
leaq 0x30(%rsp), %rdi
jmp 0x2ae9
movq %rax, %rbx
jmp 0x2ad7
jmp 0x2ac5
jmp 0x2ac5
jmp 0x2aca
movq %rax, %rbx
jmp 0x2afb
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2d00
leaq 0x50(%rsp), %rdi
callq 0x2d00
leaq 0xc8(%rsp), %rdi
callq 0x20c0
leaq 0x128(%rsp), %rdi
callq 0x20c0
leaq 0x78(%rsp), %rdi
callq 0x2d2c
movq %rsp, %rdi
callq 0x2d00
leaq 0xe8(%rsp), %rdi
callq 0x20c0
leaq 0x108(%rsp), %rdi
callq 0x20c0
leaq 0xa8(%rsp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x22b0