// File: /workspace/github_cpp_makefile_star2_O1/Chaircrusher[P]primeratiogen/Bjorklund.cpp
// Function: Bjorklund::iter()
void Bjorklund::iter(){
    //\Bjorklund algorithm
    //\do E[k,n]. k is number of one's in sequence, and n is the length of sequence.
    int divisor = lengthOfSeq - pulseAmt; //initial amount of zero's
    if(divisor < 0) throw out_of_range{"Divisor has to be greator than 0"};
    
    remainder.push_back(pulseAmt);
    //iteration
    int index = 0; //we start algorithm from first index.
    
    while(true){
        count.push_back(std::floor(divisor / remainder[index]));
        remainder.push_back(divisor % remainder[index]);
        divisor = remainder.at(index);
        index += 1; //move to next step.
        if(remainder[index] <= 1){
            break;
        }
    }
    count.push_back(divisor);
    buildSeq(index); //place one's and zero's
    reverse(sequence.begin(), sequence.end());
    
    //position correction. some of result of algorithm is one step rotated.
    int zeroCount =0;
    if(sequence.at(0) != 1){
        do{
            zeroCount ++;
        }while(sequence.at(zeroCount) == 0);
        std::rotate(sequence.begin(), sequence.begin() + zeroCount, sequence.end());
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x58(%rdi), %ecx
movl 0x5c(%rdi), %eax
subl %eax, %ecx
movl %ecx, 0xc(%rsp)
js 0x3765
movq %rdi, %rbx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x3607
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3613
leaq 0x5c(%rbx), %rdx
movq %rbx, %rdi
callq 0x3ae6
leaq 0x18(%rbx), %r14
xorl %r15d, %r15d
leaq 0x14(%rsp), %r12
leaq 0x10(%rsp), %r13
movl 0xc(%rsp), %eax
movq (%rbx), %rcx
cltd
idivl (%rcx,%r15,4)
movl %eax, 0x14(%rsp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x364a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x3655
movq %r14, %rdi
movq %r12, %rdx
callq 0x3c22
movl 0xc(%rsp), %eax
movq (%rbx), %rcx
cltd
idivl (%rcx,%r15,4)
movl %edx, 0x10(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x367b
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3686
movq %rbx, %rdi
movq %r13, %rdx
callq 0x3c22
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r15, %rdx
jbe 0x3754
movl (%rax,%r15,4), %ecx
movl %ecx, 0xc(%rsp)
leaq 0x1(%r15), %rbp
cmpl $0x1, 0x4(%rax,%r15,4)
movq %rbp, %r15
jg 0x3624
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x36ce
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x36db
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
callq 0x3ae6
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3866
leaq 0x30(%rbx), %r14
movq 0x30(%rbx), %rdi
movq 0x40(%rbx), %rdx
movl 0x48(%rbx), %ecx
xorl %esi, %esi
callq 0x3cfd
movq %r14, %rdi
xorl %esi, %esi
callq 0x3a32
testq %rdx, (%rax)
jne 0x3745
xorl %r15d, %r15d
incq %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3a32
testq %rdx, (%rax)
je 0x370d
movq %r15, %rax
shrq $0x6, %rax
movq 0x30(%rbx), %rdi
movq 0x40(%rbx), %r8
leaq (%rdi,%rax,8), %rdx
andl $0x3f, %r15d
movl 0x48(%rbx), %r9d
xorl %esi, %esi
movl %r15d, %ecx
callq 0x3d94
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19bd(%rip), %rdi      # 0x5118
movq %r15, %rsi
xorl %eax, %eax
callq 0x2150
movl $0x10, %edi
callq 0x2090
movq %rax, %rbx
leaq 0x1926(%rip), %rsi      # 0x509f
movq %rax, %rdi
callq 0x2040
movq 0x3848(%rip), %rsi      # 0x6fd0
movq 0x3839(%rip), %rdx      # 0x6fc8
movq %rbx, %rdi
callq 0x21e0
movq %rax, %r14
movq %rbx, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x21f0