// File: 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:
subq $0x2c8, %rsp            # imm = 0x2C8
movl $0x0, 0x2c4(%rsp)
movl %edi, 0x2c0(%rsp)
movq %rsi, 0x2b8(%rsp)
cmpl $0x3, 0x2c0(%rsp)
jl 0x39f5
cmpl $0x4, 0x2c0(%rsp)
jle 0x3a05
movl $0xffffffff, 0x2c4(%rsp) # imm = 0xFFFFFFFF
jmp 0x43d7
movq 0x2b8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x90(%rsp)
leaq 0x297(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x33f0
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
leaq 0x298(%rsp), %rdi
callq 0x4400
jmp 0x3a4d
leaq 0x297(%rsp), %rdi
callq 0x3270
leaq 0x298(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x3320
movq 0x80(%rsp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3460
movq %rax, 0x88(%rsp)
jmp 0x3a8c
movq 0x88(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x3af1
leaq 0x298(%rsp), %rdi
movl $0x2f, %esi
callq 0x3150
jmp 0x3ab0
jmp 0x3af1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
leaq 0x297(%rsp), %rdi
callq 0x3270
jmp 0x43e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0x43c8
movq 0x2b8(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x70(%rsp)
leaq 0x25f(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x33f0
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
leaq 0x260(%rsp), %rdi
callq 0x4400
jmp 0x3b2d
leaq 0x25f(%rsp), %rdi
callq 0x3270
leaq 0x237(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x33f0
movq 0x68(%rsp), %rdx
leaq 0x44c3(%rip), %rsi      # 0x801b
leaq 0x238(%rsp), %rdi
callq 0x4400
jmp 0x3b67
leaq 0x237(%rsp), %rdi
callq 0x3270
cmpl $0x4, 0x2c0(%rsp)
jne 0x3c04
movq 0x2b8(%rsp), %rax
movq 0x18(%rax), %rsi
leaq 0x238(%rsp), %rdi
callq 0x32e0
jmp 0x3b9d
jmp 0x3c04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
leaq 0x25f(%rsp), %rdi
callq 0x3270
jmp 0x43c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
leaq 0x237(%rsp), %rdi
callq 0x3270
jmp 0x43bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0x43ae
leaq 0x218(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x4580
movq 0x60(%rsp), %rsi
leaq 0x298(%rsp), %rdi
callq 0x3880
jmp 0x3c2a
leaq 0x1e8(%rsp), %rdi
callq 0x4590
movl $0x0, 0x1e4(%rsp)
movslq 0x1e4(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x45a0
movq %rax, %rcx
movq 0x58(%rsp), %rax
cmpq %rcx, %rax
jae 0x401c
leaq 0x43a9(%rip), %rsi      # 0x801d
leaq 0x1a0(%rsp), %rdi
leaq 0x238(%rsp), %rdx
callq 0x4610
jmp 0x3c8b
leaq 0x4398(%rip), %rdx      # 0x802a
leaq 0x1c0(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x45c0
jmp 0x3ca9
leaq 0x1a0(%rsp), %rdi
callq 0x3140
movslq 0x1e4(%rsp), %rsi
leaq 0x218(%rsp), %rdi
callq 0x4820
movq %rax, %rdx
leaq 0x140(%rsp), %rdi
leaq 0x298(%rsp), %rsi
callq 0x4790
jmp 0x3ce5
leaq 0x4343(%rip), %rdx      # 0x802f
leaq 0x160(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x45c0
jmp 0x3d03
leaq 0x180(%rsp), %rdi
leaq 0x160(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x4740
jmp 0x3d22
leaq 0x1c0(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x32d0
jmp 0x3d39
leaq 0x180(%rsp), %rdi
callq 0x3140
leaq 0x160(%rsp), %rdi
callq 0x3140
leaq 0x140(%rsp), %rdi
callq 0x3140
leaq 0x120(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x35b0
jmp 0x3d77
leaq 0x108(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x4580
movq 0x50(%rsp), %rdx
leaq 0x120(%rsp), %rdi
movl $0xa, %esi
callq 0x3780
jmp 0x3da2
movl $0x0, 0x104(%rsp)
movslq 0x104(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x45a0
movq %rax, %rcx
movq 0x48(%rsp), %rax
cmpq %rcx, %rax
jae 0x3fb3
leaq 0xe8(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x4580
movslq 0x104(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x4820
movq 0x40(%rsp), %rdx
movq %rax, %rdi
movl $0x9, %esi
callq 0x3780
jmp 0x3e13
xorl %eax, %eax
movl %eax, %esi
leaq 0xe8(%rsp), %rdi
callq 0x4820
movq %rax, %rsi
leaq 0x1e8(%rsp), %rdi
callq 0x4840
movq %rax, 0x38(%rsp)
jmp 0x3e3b
leaq 0xe8(%rsp), %rdi
movl $0x1, %esi
callq 0x4820
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x32b0
movq 0x38(%rsp), %rdi
movsd %xmm0, 0xe0(%rsp)
leaq 0xe0(%rsp), %rsi
callq 0x4930
jmp 0x3e7a
leaq 0xe8(%rsp), %rdi
callq 0x4960
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x3dad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0x43a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0x4394
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x3140
jmp 0x4394
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0x400a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0x3f68
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0x3f5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x3140
leaq 0x160(%rsp), %rdi
callq 0x3140
leaq 0x140(%rsp), %rdi
callq 0x3140
jmp 0x400a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0x3ff0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x4960
jmp 0x3ff0
leaq 0x108(%rsp), %rdi
callq 0x4960
leaq 0x120(%rsp), %rdi
callq 0x3140
leaq 0x1c0(%rsp), %rdi
callq 0x3140
movl 0x1e4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e4(%rsp)
jmp 0x3c42
leaq 0x108(%rsp), %rdi
callq 0x4960
leaq 0x120(%rsp), %rdi
callq 0x3140
leaq 0x1c0(%rsp), %rdi
callq 0x3140
jmp 0x4394
movq 0x7fb5(%rip), %rdi      # 0xbfd8
leaq 0x4007(%rip), %rsi      # 0x8031
callq 0x3210
jmp 0x4031
movl $0x0, 0xdc(%rsp)
movslq 0xdc(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x45a0
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x40b6
movq 0x7f6e(%rip), %rdi      # 0xbfd8
leaq 0x3fcb(%rip), %rsi      # 0x803c
callq 0x3210
movq %rax, 0x28(%rsp)
jmp 0x407d
movslq 0xdc(%rsp), %rsi
leaq 0x218(%rsp), %rdi
callq 0x4820
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x31f0
jmp 0x40a1
jmp 0x40a3
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x403c
movq 0x7f1b(%rip), %rdi      # 0xbfd8
movq 0x7f04(%rip), %rsi      # 0xbfc8
callq 0x3250
jmp 0x40cb
leaq 0xd0(%rsp), %rdi
callq 0x49c0
leaq 0x1e8(%rsp), %rdi
callq 0x49e0
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0xd0(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x4a30
movq %rax, 0xc0(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x4a10
testb $0x1, %al
jne 0x4130
jmp 0x4346
leaq 0xd0(%rsp), %rdi
callq 0x4a60
movq %rax, %rsi
movq 0x7e91(%rip), %rdi      # 0xbfd8
callq 0x31f0
jmp 0x414e
movsd 0x3eb2(%rip), %xmm0     # 0x8008
movsd %xmm0, 0xb8(%rsp)
movl $0x0, 0xb4(%rsp)
movl $0x0, 0xb0(%rsp)
movslq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x4a60
movq %rax, %rdi
addq $0x20, %rdi
callq 0x4a80
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x4234
leaq 0xd0(%rsp), %rdi
callq 0x4a60
movq %rax, %rdi
addq $0x20, %rdi
movslq 0xb0(%rsp), %rsi
callq 0x4aa0
movsd (%rax), %xmm1
movsd 0xb8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x421c
leaq 0xd0(%rsp), %rdi
callq 0x4a60
movq %rax, %rdi
addq $0x20, %rdi
movslq 0xb0(%rsp), %rsi
callq 0x4aa0
movsd (%rax), %xmm0
movsd %xmm0, 0xb8(%rsp)
movl 0xb0(%rsp), %eax
movl %eax, 0xb4(%rsp)
jmp 0x421e
movl 0xb0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb0(%rsp)
jmp 0x4175
movq 0x7d9d(%rip), %rdi      # 0xbfd8
leaq 0x3dfa(%rip), %rsi      # 0x803c
callq 0x3210
movq %rax, 0x18(%rsp)
jmp 0x424e
movslq 0xb4(%rsp), %rsi
leaq 0x218(%rsp), %rdi
callq 0x4820
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x31f0
jmp 0x4272
movl $0x0, 0xac(%rsp)
movslq 0xac(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x4a60
movq %rax, %rdi
addq $0x20, %rdi
callq 0x4a80
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x4313
movq 0x7d21(%rip), %rdi      # 0xbfd8
leaq 0x3d7e(%rip), %rsi      # 0x803c
callq 0x3210
movq %rax, 0x8(%rsp)
jmp 0x42ca
leaq 0xd0(%rsp), %rdi
callq 0x4a60
movq %rax, %rdi
addq $0x20, %rdi
movslq 0xac(%rsp), %rsi
callq 0x4aa0
movq 0x8(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x3420
jmp 0x42fb
jmp 0x42fd
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x427d
movq 0x7cbe(%rip), %rdi      # 0xbfd8
movq 0x7ca7(%rip), %rsi      # 0xbfc8
callq 0x3250
jmp 0x4328
jmp 0x432a
leaq 0xd0(%rsp), %rdi
xorl %esi, %esi
callq 0x4ac0
movq %rax, 0xa0(%rsp)
jmp 0x40fd
movl $0x0, 0x2c4(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x4b00
leaq 0x218(%rsp), %rdi
callq 0x4960
leaq 0x238(%rsp), %rdi
callq 0x3140
leaq 0x260(%rsp), %rdi
callq 0x3140
leaq 0x298(%rsp), %rdi
callq 0x3140
jmp 0x43d7
leaq 0x1e8(%rsp), %rdi
callq 0x4b00
leaq 0x218(%rsp), %rdi
callq 0x4960
leaq 0x238(%rsp), %rdi
callq 0x3140
leaq 0x260(%rsp), %rdi
callq 0x3140
leaq 0x298(%rsp), %rdi
callq 0x3140
jmp 0x43e6
movl 0x2c4(%rsp), %eax
addq $0x2c8, %rsp            # imm = 0x2C8
retq
movq 0x288(%rsp), %rdi
callq 0x33e0
nopw %cs:(%rax,%rax)
nopl (%rax)