// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq %rsi, %r12
cmpl $0x1, %edi
jg 0x2457
movq (%r12), %rbx
testq %rbx, %rbx
je 0x2615
movq %rbx, %rdi
callq 0x2080
movq 0x4ba9(%rip), %rdi      # 0x6ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2130
jmp 0x2633
movl %edi, %ebp
movq 0x8(%r12), %r13
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x2e, %ebx
cmpl $0x2, %edi
jne 0x2476
movl $0x2e, %r15d
jmp 0x2495
movq 0x10(%r12), %rdi
callq 0x2170
movl %eax, %r15d
cmpl $0x4, %ebp
jb 0x2495
movq 0x18(%r12), %rdi
callq 0x2170
movl %eax, %r14d
leal -0x2f(%r15), %eax
cmpl $-0x2e, %eax
cmovael %r15d, %ebx
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testl %ebx, %ebx
je 0x25d2
movq %r13, 0x20(%rsp)
movl %r14d, 0x1c(%rsp)
movl %ebx, %eax
movq %rax, 0x28(%rsp)
leaq (,%rax,8), %rbp
xorl %ebx, %ebx
leaq 0x4c34(%rip), %r14      # 0x7110
leaq 0x58(%rsp), %r15
xorl %r12d, %r12d
xorl %r13d, %r13d
movsd (%r14,%r12,8), %xmm0
movsd (%r13,%r14), %xmm1
movsd %xmm0, 0x58(%rsp)
movsd %xmm1, 0x60(%rsp)
cmpq %r13, %rbx
je 0x2560
divsd %xmm1, %xmm0
movsd 0x2af7(%rip), %xmm1     # 0x5008
ucomisd %xmm0, %xmm1
ja 0x2560
ucomisd 0x2af1(%rip), %xmm0     # 0x5010
jae 0x2560
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2c0d
movq 0x8(%rsp), %rsi
cmpq %rsi, %rax
jne 0x2560
cmpq 0x10(%rsp), %rax
je 0x2555
movupd 0x58(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x8(%rsp)
jmp 0x2560
movq %rsp, %rdi
movq %r15, %rdx
callq 0x2d72
addq $0x8, %r13
cmpq %r13, %rbp
jne 0x24e7
incq %r12
addq $0x8, %rbx
cmpq 0x28(%rsp), %r12
jne 0x24e4
movq (%rsp), %r15
movq 0x8(%rsp), %r12
cmpq %r12, %r15
movl 0x1c(%rsp), %r14d
movq 0x20(%rsp), %r13
je 0x25d2
movq %r12, %rax
subq %r15, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x1e9(%rip), %rcx      # 0x23cc
movq %r15, %rdi
movq %r12, %rsi
callq 0x2eb1
leaq -0x1fb(%rip), %rdx      # 0x23cc
movq %r15, %rdi
movq %r12, %rsi
callq 0x2fde
movq 0x49e7(%rip), %r15      # 0x6fc0
leaq 0x2a86(%rip), %rsi      # 0x5066
movl $0x2, %edx
movq %r15, %rdi
callq 0x2130
testq %r13, %r13
je 0x26ba
movq %r13, %rdi
callq 0x2080
movq 0x49bb(%rip), %rdi      # 0x6fc0
movq %r13, %rsi
movq %rax, %rdx
callq 0x2130
jmp 0x26d2
movq 0x49d4(%rip), %rax      # 0x6ff0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x21d0
movq 0x49b6(%rip), %rbx      # 0x6ff0
leaq 0x29d7(%rip), %rsi      # 0x5018
movl $0x3a, %edx
movq %rbx, %rdi
callq 0x2130
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
leaq 0x29d7(%rip), %rsi      # 0x5053
movl $0x12, %edx
movq %rbx, %rdi
callq 0x2130
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movl $0x1, %eax
jmp 0x2a81
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x21d0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq 0x48d0(%rip), %r15      # 0x6fc0
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq %rax, %r12
leaq 0x295f(%rip), %rsi      # 0x5069
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
testq %r13, %r13
je 0x2760
movq %r13, %rdi
callq 0x2080
movq 0x486d(%rip), %rdi      # 0x6fc0
movq %r13, %rsi
movq %rax, %rdx
callq 0x2130
jmp 0x2778
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x21d0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq 0x482a(%rip), %rdi      # 0x6fc0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movslq %r14d, %rbx
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x4, %rax
cmpq %rbx, %rax
cmovbel %eax, %ebx
movq 0x4800(%rip), %rdi      # 0x6fc0
leaq 0x28a0(%rip), %rsi      # 0x5067
movl $0x1, %edx
callq 0x2130
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x4, %rax
testl %ebx, %ebx
movl %ebx, %esi
cmovsq %rax, %rsi
incq %rsi
movq 0x47d0(%rip), %r14      # 0x6fc0
movq %r14, %rdi
callq 0x20b0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq 0x4780(%rip), %rdi      # 0x6fc0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq 0x476c(%rip), %r14      # 0x6fc0
leaq 0x280e(%rip), %rsi      # 0x5069
movl $0x1, %edx
movq %r14, %rdi
callq 0x2130
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq 0x473a(%rip), %rdi      # 0x6fc0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
testl %ebx, %ebx
js 0x29a5
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
shrq $0x4, %rsi
leaq 0x58(%rsp), %rdi
movl %ebx, %edx
callq 0x2ae2
leaq 0x30(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x38b4
movq (%rsp), %r12
movq 0x8(%rsp), %rax
cmpq %rax, %r12
je 0x2982
xorl %r13d, %r13d
movq 0x46e1(%rip), %rbx      # 0x6fc0
leaq 0x2785(%rip), %r14      # 0x506b
movl %r13d, %r13d
movq 0x30(%rsp), %rcx
movq 0x40(%rsp), %rdx
movl 0x48(%rsp), %esi
subq %rcx, %rdx
leaq (%rsi,%rdx,8), %rdx
cmpq %r13, %rdx
jbe 0x2982
movl %r13d, %edx
shrl $0x6, %edx
movq (%rcx,%rdx,8), %rcx
btq %r13, %rcx
jae 0x2972
movsd (%r12), %xmm0
movq %rbx, %rdi
callq 0x2180
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2130
movsd 0x8(%r12), %xmm0
movq %r15, %rdi
callq 0x2180
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq 0x8(%rsp), %rax
incl %r13d
addq $0x10, %r12
cmpq %rax, %r12
jne 0x28e6
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2999
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
leaq 0x58(%rsp), %rdi
callq 0x2b6a
jmp 0x2a23
movq (%rsp), %r12
cmpq 0x8(%rsp), %r12
je 0x2a23
movq 0x4609(%rip), %rbx      # 0x6fc0
leaq 0x26ad(%rip), %r14      # 0x506b
movsd (%r12), %xmm0
movq %rbx, %rdi
callq 0x2180
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2130
movsd 0x8(%r12), %xmm0
movq %r15, %rdi
callq 0x2180
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
addq $0x10, %r12
cmpq 0x8(%rsp), %r12
jne 0x29be
movq 0x4596(%rip), %rbx      # 0x6fc0
leaq 0x263c(%rip), %rsi      # 0x506d
movl $0x3, %edx
movq %rbx, %rdi
callq 0x2130
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq 0x4564(%rip), %rdi      # 0x6fc0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2a7f
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2ab1
jmp 0x2ac1
movq %rax, %rbx
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
je 0x2ab1
leaq 0x30(%rsp), %rdi
callq 0x2210
leaq 0x58(%rsp), %rdi
callq 0x2b6a
jmp 0x2ac4
jmp 0x2ac1
jmp 0x2ac1
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2ada
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21f0