// File: /workspace/github_cpp_makefile_star2_O1/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 0x260d
movq %rbx, %rdi
callq 0x2080
movq 0x4ba9(%rip), %rdi      # 0x6ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2130
jmp 0x262b
movl %edi, %ebp
movq 0x8(%r12), %rbx
movl $0x2e, %r15d
cmpl $0x2, %edi
je 0x2476
movq 0x10(%r12), %rdi
callq 0x2170
movl %eax, %r15d
movq %rbx, 0x48(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x4, %ebp
jl 0x248f
movq 0x18(%r12), %rdi
callq 0x2170
movl %eax, 0x1c(%rsp)
leal -0x2f(%r15), %eax
cmpl $-0x2e, %eax
movl $0x2e, %eax
cmovael %r15d, %eax
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testl %eax, %eax
je 0x2578
movl %eax, %eax
movq %rax, 0x50(%rsp)
leaq (,%rax,8), %rbp
xorl %ebx, %ebx
leaq 0x4c3b(%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 0x2559
divsd %xmm1, %xmm0
movsd 0x2afe(%rip), %xmm1     # 0x5008
ucomisd %xmm0, %xmm1
ja 0x2559
ucomisd 0x2af8(%rip), %xmm0     # 0x5010
jae 0x2559
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2c19
movq 0x8(%rsp), %rsi
cmpq %rsi, %rax
jne 0x2559
cmpq 0x10(%rsp), %rsi
je 0x254e
movupd 0x58(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x8(%rsp)
jmp 0x2559
movq %rsp, %rdi
movq %r15, %rdx
callq 0x2d5c
addq $0x8, %r13
cmpq %r13, %rbp
jne 0x24e0
incq %r12
addq $0x8, %rbx
cmpq 0x50(%rsp), %r12
jne 0x24dd
movq (%rsp), %r15
movq 0x8(%rsp), %r12
cmpq %r12, %r15
movl 0x1c(%rsp), %ebx
movq 0x48(%rsp), %r14
je 0x25ca
movq %r12, %rax
subq %r15, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x1d1(%rip), %rcx      # 0x23dc
movq %r15, %rdi
movq %r12, %rsi
callq 0x2e9b
leaq -0x1e3(%rip), %rdx      # 0x23dc
movq %r15, %rdi
movq %r12, %rsi
callq 0x2fdb
movq 0x49ef(%rip), %r15      # 0x6fc0
leaq 0x2a8e(%rip), %rsi      # 0x5066
movl $0x2, %edx
movq %r15, %rdi
callq 0x2130
testq %r14, %r14
je 0x26b2
movq %r14, %rdi
callq 0x2080
movq 0x49c3(%rip), %rdi      # 0x6fc0
movq %r14, %rsi
movq %rax, %rdx
callq 0x2130
jmp 0x26ca
movq 0x49dc(%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 0x49be(%rip), %rbx      # 0x6ff0
leaq 0x29df(%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 0x29df(%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 0x2a8c
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 0x48d8(%rip), %r15      # 0x6fc0
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq %rax, %r12
leaq 0x2967(%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 %r14, %r14
je 0x2758
movq %r14, %rdi
callq 0x2080
movq 0x4875(%rip), %rdi      # 0x6fc0
movq %r14, %rsi
movq %rax, %rdx
callq 0x2130
jmp 0x2770
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 0x4832(%rip), %rdi      # 0x6fc0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movslq %ebx, %rbx
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x4, %rax
cmpq %rbx, %rax
cmovbel %eax, %ebx
movq 0x4808(%rip), %rdi      # 0x6fc0
leaq 0x28a8(%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 0x47d8(%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 0x4788(%rip), %rdi      # 0x6fc0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq 0x4774(%rip), %r14      # 0x6fc0
leaq 0x2816(%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 0x4742(%rip), %rdi      # 0x6fc0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
testl %ebx, %ebx
js 0x29b0
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
shrq $0x4, %rsi
leaq 0x58(%rsp), %rdi
movl %ebx, %edx
callq 0x2aee
leaq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x39ba
movq (%rsp), %r12
cmpq 0x8(%rsp), %r12
je 0x2974
xorl %r13d, %r13d
movq 0x46ec(%rip), %rbx      # 0x6fc0
leaq 0x2790(%rip), %r14      # 0x506b
movl %r13d, %r13d
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rcx
movl 0x38(%rsp), %edx
subq %rax, %rcx
leaq (%rdx,%rcx,8), %rcx
cmpq %r13, %rcx
jbe 0x2974
movl %r13d, %ecx
shrl $0x6, %ecx
movq (%rax,%rcx,8), %rax
btq %r13, %rax
jae 0x2962
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
incl %r13d
addq $0x10, %r12
cmpq 0x8(%rsp), %r12
jne 0x28db
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x29a4
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x2b76
jmp 0x2a2e
movq (%rsp), %r12
cmpq 0x8(%rsp), %r12
je 0x2a2e
movq 0x45fe(%rip), %rbx      # 0x6fc0
leaq 0x26a2(%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 0x29c9
movq 0x458b(%rip), %rbx      # 0x6fc0
leaq 0x2631(%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 0x4559(%rip), %rdi      # 0x6fc0
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2a8a
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 0x2abc
jmp 0x2acc
movq %rax, %rbx
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0x2abc
leaq 0x20(%rsp), %rdi
callq 0x2210
leaq 0x58(%rsp), %rdi
callq 0x2b76
jmp 0x2acf
jmp 0x2acc
jmp 0x2acc
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2ae5
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21f0
nop