// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r12
cmpl $0x1, %edi
jg 0x23c4
movq (%r12), %rsi
movq 0x5c6a(%rip), %rbx      # 0x7ff0
movq %rbx, %rdi
callq 0x20e0
leaq 0x2c83(%rip), %rsi      # 0x5018
movq %rbx, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2070
leaq 0x2ca7(%rip), %rsi      # 0x5053
movq %rbx, %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x2070
pushq $0x1
popq %rax
jmp 0x26a0
movl %edi, %ebp
movq 0x8(%r12), %rax
movq %rax, 0x30(%rsp)
pushq $-0x1
popq %rbx
pushq $0x2e
popq %r14
cmpl $0x2, %edi
jne 0x23e8
movl %ebx, 0xc(%rsp)
movq %r14, %rcx
movl %ecx, %r15d
jmp 0x2411
movq 0x10(%r12), %rdi
callq 0x2150
movl %eax, %r15d
cmpl $0x4, %ebp
jb 0x240a
movq 0x18(%r12), %rdi
callq 0x2150
movl %eax, 0xc(%rsp)
jmp 0x240e
movl %ebx, 0xc(%rsp)
movq %r14, %rcx
leal -0x2f(%r15), %eax
cmpl $-0x2e, %eax
cmovael %r15d, %ecx
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rax
andq $0x0, 0x10(%rax)
movapd %xmm0, (%rax)
leaq (,%rcx,8), %rbp
xorl %ebx, %ebx
leaq 0x5cc1(%rip), %r14      # 0x8100
leaq 0x68(%rsp), %r12
xorl %r13d, %r13d
movq %rcx, 0x38(%rsp)
cmpq %rcx, %r13
je 0x24c6
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0x24b8
movsd (%r14,%r13,8), %xmm0
movsd (%r15,%r14), %xmm1
movsd %xmm0, 0x68(%rsp)
movsd %xmm1, 0x70(%rsp)
cmpq %r15, %rbx
jne 0x247c
addq $0x8, %r15
jmp 0x2454
divsd %xmm1, %xmm0
movsd 0x2b80(%rip), %xmm1     # 0x5008
ucomisd %xmm0, %xmm1
ja 0x2476
ucomisd 0x2b7a(%rip), %xmm0     # 0x5010
jae 0x2476
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2346
testb %al, %al
jne 0x2476
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x273c
jmp 0x2476
incq %r13
addq $0x8, %rbx
movq 0x38(%rsp), %rcx
jmp 0x244c
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq -0x1bb(%rip), %rdx      # 0x231c
callq 0x2b7f
movq 0x30(%rsp), %rbx
movq 0x5ad8(%rip), %rdi      # 0x7fc0
leaq 0x2b77(%rip), %rsi      # 0x5066
callq 0x20e0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x20e0
movq %rax, %rdi
callq 0x2070
leaq 0x2b5b(%rip), %rsi      # 0x5069
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2070
movq 0x5a9b(%rip), %rdi      # 0x7fc0
movq %rbx, %rsi
callq 0x20e0
movq %rax, %rdi
callq 0x2070
movslq 0xc(%rsp), %rbx
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x4, %rax
cmpq %rbx, %rax
cmovbel %eax, %ebx
movq 0x5a6b(%rip), %rdi      # 0x7fc0
leaq 0x2b0b(%rip), %rsi      # 0x5067
callq 0x20e0
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x4, %rax
testl %ebx, %ebx
movl %ebx, %esi
cmovsq %rax, %rsi
incq %rsi
movq 0x5a3f(%rip), %rdi      # 0x7fc0
callq 0x20a0
movq %rax, %rdi
callq 0x2070
movq 0x5a2b(%rip), %rdi      # 0x7fc0
callq 0x2070
movq 0x5a1f(%rip), %rdi      # 0x7fc0
leaq 0x2ac1(%rip), %rsi      # 0x5069
callq 0x20e0
movq %rax, %rdi
callq 0x2070
testl %ebx, %ebx
js 0x26b2
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
shrq $0x4, %rsi
leaq 0x68(%rsp), %rdi
movl %ebx, %edx
callq 0x275a
leaq 0x40(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x359a
xorl %ebp, %ebp
movq 0x10(%rsp), %r12
leaq 0x40(%rsp), %rbx
movq 0x59c7(%rip), %r14      # 0x7fc0
leaq 0x2a6b(%rip), %r15      # 0x506b
cmpq 0x18(%rsp), %r12
je 0x2665
movl %ebp, %esi
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
subq 0x40(%rsp), %rax
leaq (%rcx,%rax,8), %rax
cmpq %rsi, %rax
jbe 0x2665
movq %rbx, %rdi
callq 0x27d0
testq %rdx, (%rax)
je 0x265d
movsd (%r12), %xmm0
movq %r14, %rdi
callq 0x2160
movq %rax, %rdi
movq %r15, %rsi
callq 0x20e0
movsd 0x8(%r12), %xmm0
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x2070
incl %ebp
addq $0x10, %r12
jmp 0x2600
leaq 0x40(%rsp), %rdi
callq 0x27ee
leaq 0x68(%rsp), %rdi
callq 0x27fe
movq 0x5940(%rip), %rdi      # 0x7fc0
leaq 0x29e6(%rip), %rsi      # 0x506d
callq 0x20e0
movq %rax, %rdi
callq 0x2070
leaq 0x10(%rsp), %rdi
callq 0x2a04
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %r15
movq 0x5902(%rip), %rbx      # 0x7fc0
leaq 0x29a6(%rip), %r14      # 0x506b
cmpq 0x18(%rsp), %r15
je 0x2679
movsd (%r15), %xmm0
movq %rbx, %rdi
callq 0x2160
movq %rax, %rdi
movq %r14, %rsi
callq 0x20e0
movsd 0x8(%r15), %xmm0
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x2070
addq $0x10, %r15
jmp 0x26c5
movq %rax, %rbx
jmp 0x2718
jmp 0x2726
jmp 0x270b
jmp 0x2726
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x27ee
leaq 0x68(%rsp), %rdi
callq 0x27fe
jmp 0x2729
jmp 0x2726
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2a04
movq %rbx, %rdi
callq 0x21c0
nop