// File: Chaircrusher[P]primeratiogen/primeratiogen.cpp
// Function: main
int main(int argc, char **argv) {
  if(argc < 2) {
    std::cerr << argv[0];
    std::cerr << ": Usage: primeratiogen Scalename [PrimeCount] [SubsetSize]"
	      << std::endl;
    std::cerr << "missing scale name";
    std::cerr << std::endl;
    return 1;
  }
  const char *scaleName = argv[1];
  // if no primecount given use all primes given above
  unsigned int primeCount(numPrimes);
  if(argc > 2)
    primeCount = atoi(argv[2]);
  int subset(-1);
  if(argc > 3)
    subset = atoi(argv[3]);
  // sanity check on prime count
  if(primeCount <= 0 || primeCount > numPrimes)
    primeCount = numPrimes;
  // vector to hold rational numbers
  rationalVec v;
  // permute throuth the first 'primeCount' primes, record the ratios
  for(unsigned i=0; i < primeCount; ++i) {
    for(unsigned j=0; j < primeCount; ++j) {
      rational cur(primes[i],primes[j]);
      if(j == i ||			  // don't include 1/1
	 cur.val() < 1.0 ||  // don't include numbers < 1
	 cur.val() >= 2.0 || // don't include numbers > 2
	 alreadyIn(v,cur))	  // don't include the same value twice
	// (shouldn't ever happen)
	continue;
      v.push_back(cur);		  // add to list
    }
  }
  std::sort(v.begin(), v.end(), ratioCompare); // sort the list ascending
  // put out scala header
  std::cout << "! " << scaleName << std::endl
	    << "!" << std::endl;
  // scale name
  std::cout << scaleName << std::endl;

  // if subset is larger than list of generated ratio, set it to that.
  if(subset >= v.size())
    subset = v.size();

  // size of scale
  std::cout << " ";
  std::cout << ((subset < 0 ? v.size() : subset))+1 << std::endl;
  std::cout << std::endl;
  std::cout << "!" << std::endl;
  // no subset requested, print all
  if(subset < 0) {
    for(rationalIt it = v.begin(); it != v.end(); ++it) {
      std::cout << it->num() << "/" << it->denom() << std::endl;
    }
  } else {
    Bjorklund b(v.size(), subset);
    std::vector<bool> bv = b.LoadSequence();
    rationalIt it = v.begin();
    for(unsigned i = 0;
	it != v.end() && i < bv.size();
	++i, ++it) {
      if(bv[i])
	std::cout << it->num() << "/" << it->denom() << std::endl;
    }
  }
  // cap with octave
  std::cout << "2/1" << std::endl;
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x24a6
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq 0xcba3(%rip), %rdi      # 0xeff0
callq 0x20e0
movq 0xcb97(%rip), %rdi      # 0xeff0
leaq 0x7bc8(%rip), %rsi      # 0xa028
callq 0x20e0
movq %rax, %rdi
movq 0xcb39(%rip), %rsi      # 0xefa8
callq 0x2110
movq 0xcb75(%rip), %rdi      # 0xeff0
leaq 0x7be1(%rip), %rsi      # 0xa063
callq 0x20e0
movq 0xcb62(%rip), %rdi      # 0xeff0
movq 0xcb13(%rip), %rsi      # 0xefa8
callq 0x2110
movl $0x1, -0x4(%rbp)
jmp 0x2b45
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x2e, -0x1c(%rbp)
cmpl $0x2, -0x8(%rbp)
jle 0x24cf
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2160
movl %eax, -0x1c(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
cmpl $0x3, -0x8(%rbp)
jle 0x24ec
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2160
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x1c(%rbp)
jbe 0x24f8
cmpl $0x2e, -0x1c(%rbp)
jbe 0x24ff
movl $0x2e, -0x1c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2c70
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x260f
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x25ff
movl -0x3c(%rbp), %eax
movl %eax, %ecx
leaq 0xcbd6(%rip), %rax      # 0xf110
movsd (%rax,%rcx,8), %xmm0
movl -0x40(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm1
leaq -0x50(%rbp), %rdi
callq 0x2c90
jmp 0x2552
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x25cd
leaq -0x50(%rbp), %rdi
callq 0x2b60
movsd %xmm0, -0x138(%rbp)
jmp 0x256d
movsd -0x138(%rbp), %xmm1
movsd 0x7a8b(%rip), %xmm0     # 0xa008
ucomisd %xmm1, %xmm0
ja 0x25cd
leaq -0x50(%rbp), %rdi
callq 0x2b60
movsd %xmm0, -0x140(%rbp)
jmp 0x2596
movsd -0x140(%rbp), %xmm0
movsd 0x7a6a(%rip), %xmm1     # 0xa010
ucomisd %xmm1, %xmm0
jae 0x25cd
leaq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x23b0
movb %al, -0x141(%rbp)
jmp 0x25c1
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0x25cd
jmp 0x25e0
jmp 0x25f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x2b3a
leaq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2cc0
jmp 0x25ef
jmp 0x25f1
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2522
jmp 0x2601
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x250f
leaq -0x38(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x2c10
movq -0x150(%rbp), %rdi
movq %rax, -0x68(%rbp)
callq 0x2c40
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
leaq -0x2d2(%rip), %rdx      # 0x2370
callq 0x2d30
jmp 0x2649
movq 0xc970(%rip), %rdi      # 0xefc0
leaq 0x7a1f(%rip), %rsi      # 0xa076
callq 0x20e0
movq %rax, -0x158(%rbp)
jmp 0x2665
movq -0x158(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x20e0
movq %rax, -0x160(%rbp)
jmp 0x267e
movq -0x160(%rbp), %rdi
movq 0xc91c(%rip), %rsi      # 0xefa8
callq 0x2110
movq %rax, -0x168(%rbp)
jmp 0x269a
movq -0x168(%rbp), %rdi
leaq 0x79d1(%rip), %rsi      # 0xa079
callq 0x20e0
movq %rax, -0x170(%rbp)
jmp 0x26b6
movq -0x170(%rbp), %rdi
movq 0xc8e4(%rip), %rsi      # 0xefa8
callq 0x2110
jmp 0x26cb
movq -0x18(%rbp), %rsi
movq 0xc8ea(%rip), %rdi      # 0xefc0
callq 0x20e0
movq %rax, -0x178(%rbp)
jmp 0x26e4
movq -0x178(%rbp), %rdi
movq 0xc8b6(%rip), %rsi      # 0xefa8
callq 0x2110
jmp 0x26f9
movslq -0x20(%rbp), %rax
movq %rax, -0x180(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2d80
movq %rax, %rcx
movq -0x180(%rbp), %rax
cmpq %rcx, %rax
jb 0x2728
leaq -0x38(%rbp), %rdi
callq 0x2d80
movl %eax, -0x20(%rbp)
movq 0xc891(%rip), %rdi      # 0xefc0
leaq 0x7941(%rip), %rsi      # 0xa077
callq 0x20e0
jmp 0x273d
cmpl $0x0, -0x20(%rbp)
jge 0x2755
leaq -0x38(%rbp), %rdi
callq 0x2d80
movq %rax, -0x188(%rbp)
jmp 0x2760
movslq -0x20(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rsi
incq %rsi
movq 0xc84f(%rip), %rdi      # 0xefc0
callq 0x2040
movq %rax, -0x190(%rbp)
jmp 0x277f
movq -0x190(%rbp), %rdi
movq 0xc81b(%rip), %rsi      # 0xefa8
callq 0x2110
jmp 0x2794
movq 0xc825(%rip), %rdi      # 0xefc0
movq 0xc806(%rip), %rsi      # 0xefa8
callq 0x2110
jmp 0x27a9
movq 0xc810(%rip), %rdi      # 0xefc0
leaq 0x78c2(%rip), %rsi      # 0xa079
callq 0x20e0
movq %rax, -0x198(%rbp)
jmp 0x27c5
movq -0x198(%rbp), %rdi
movq 0xc7d5(%rip), %rsi      # 0xefa8
callq 0x2110
jmp 0x27da
cmpl $0x0, -0x20(%rbp)
jge 0x28ca
leaq -0x38(%rbp), %rdi
callq 0x2c10
movq %rax, -0x78(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2c40
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2b80
testb $0x1, %al
jne 0x2814
jmp 0x28c5
leaq -0x78(%rbp), %rdi
callq 0x2da0
movq %rax, %rdi
callq 0x2dc0
movsd %xmm0, -0x1a0(%rbp)
jmp 0x282f
movsd -0x1a0(%rbp), %xmm0
movq 0xc782(%rip), %rdi      # 0xefc0
callq 0x21e0
movq %rax, -0x1a8(%rbp)
jmp 0x284c
movq -0x1a8(%rbp), %rdi
leaq 0x7821(%rip), %rsi      # 0xa07b
callq 0x20e0
movq %rax, -0x1b0(%rbp)
jmp 0x2868
leaq -0x78(%rbp), %rdi
callq 0x2da0
movq %rax, %rdi
callq 0x2de0
movsd %xmm0, -0x1b8(%rbp)
jmp 0x2883
movsd -0x1b8(%rbp), %xmm0
movq -0x1b0(%rbp), %rdi
callq 0x21e0
movq %rax, -0x1c0(%rbp)
jmp 0x28a0
movq -0x1c0(%rbp), %rdi
movq 0xc6fa(%rip), %rsi      # 0xefa8
callq 0x2110
jmp 0x28b5
jmp 0x28b7
leaq -0x78(%rbp), %rdi
callq 0x2e00
jmp 0x27f1
jmp 0x2af7
leaq -0x38(%rbp), %rdi
callq 0x2d80
movl %eax, %esi
movl -0x20(%rbp), %edx
leaq -0xe0(%rbp), %rdi
callq 0x2e20
jmp 0x28e6
leaq -0x108(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x6450
jmp 0x28fb
leaq -0x38(%rbp), %rdi
callq 0x2c10
movq %rax, -0x110(%rbp)
movl $0x0, -0x114(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2c40
movq %rax, -0x120(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x2b80
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x1c1(%rbp)
jne 0x2949
jmp 0x2978
movl -0x114(%rbp), %eax
movq %rax, -0x1d0(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x2ed0
movq %rax, %rcx
movq -0x1d0(%rbp), %rax
cmpq %rcx, %rax
setb %al
movb %al, -0x1c1(%rbp)
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0x2987
jmp 0x2acf
movl -0x114(%rbp), %eax
movl %eax, %esi
leaq -0x108(%rbp), %rdi
callq 0x2f50
movq %rdx, -0x1e0(%rbp)
movq %rax, -0x1d8(%rbp)
jmp 0x29ab
movq -0x1e0(%rbp), %rax
movq -0x1d8(%rbp), %rcx
movq %rcx, -0x130(%rbp)
movq %rax, -0x128(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x2fb0
testb $0x1, %al
jne 0x29dc
jmp 0x2aad
leaq -0x110(%rbp), %rdi
callq 0x2da0
movq %rax, %rdi
callq 0x2dc0
movsd %xmm0, -0x1e8(%rbp)
jmp 0x29fa
movsd -0x1e8(%rbp), %xmm0
movq 0xc5b7(%rip), %rdi      # 0xefc0
callq 0x21e0
movq %rax, -0x1f0(%rbp)
jmp 0x2a17
movq -0x1f0(%rbp), %rdi
leaq 0x7656(%rip), %rsi      # 0xa07b
callq 0x20e0
movq %rax, -0x1f8(%rbp)
jmp 0x2a33
leaq -0x110(%rbp), %rdi
callq 0x2da0
movq %rax, %rdi
callq 0x2de0
movsd %xmm0, -0x200(%rbp)
jmp 0x2a51
movsd -0x200(%rbp), %xmm0
movq -0x1f8(%rbp), %rdi
callq 0x21e0
movq %rax, -0x208(%rbp)
jmp 0x2a6e
movq -0x208(%rbp), %rdi
movq 0xc52c(%rip), %rsi      # 0xefa8
callq 0x2110
jmp 0x2a83
jmp 0x2aad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x2ae9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x2fe0
jmp 0x2ae9
jmp 0x2aaf
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x2e00
jmp 0x2915
leaq -0x108(%rbp), %rdi
callq 0x2fe0
leaq -0xe0(%rbp), %rdi
callq 0x3000
jmp 0x2af7
leaq -0xe0(%rbp), %rdi
callq 0x3000
jmp 0x2b3a
movq 0xc4c2(%rip), %rdi      # 0xefc0
leaq 0x7578(%rip), %rsi      # 0xa07d
callq 0x20e0
movq %rax, -0x210(%rbp)
jmp 0x2b13
movq -0x210(%rbp), %rdi
movq 0xc487(%rip), %rsi      # 0xefa8
callq 0x2110
jmp 0x2b28
movl $0x0, -0x4(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3060
jmp 0x2b45
leaq -0x38(%rbp), %rdi
callq 0x3060
jmp 0x2b51
movl -0x4(%rbp), %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x21c0
nopw (%rax,%rax)