// File: bobverity[P]MavericK/misc.cpp
// Function: StirlingSecond(int)
vector<double> StirlingSecond(int n) {
    
    vector<double> oldVec(2,0);
    vector<double> newVec(2,0);
    
    // simple answer if n<=0, n==1 or n==2
    if (n<=0)
        return(vector<double>(1,log(0.0)));
    else if (n==1)
        return(vector<double>(1));
    else if (n==2)
        return(oldVec);
    
    // otherwise calculate by looping
    for (int i=2; i<n; i++) {
        for (int j=1; j<int(oldVec.size()); j++) {
            newVec[j] = logSum(oldVec[j-1],oldVec[j]+log(double(j+1)));
        }
        newVec.push_back(0);
        oldVec = vector<double>(newVec);
    }
    
    return(newVec);
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x40(%rsp)
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq %rdi, 0x100(%rsp)
movl %esi, 0xfc(%rsp)
movq $0x0, 0xd8(%rsp)
leaq 0xd7(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x8780
movq 0x50(%rsp), %rcx
leaq 0xe0(%rsp), %rdi
movl $0x2, %esi
leaq 0xd8(%rsp), %rdx
callq 0x8cf0
jmp 0x34a72
leaq 0xd7(%rsp), %rdi
callq 0x8910
movq $0x0, 0xa0(%rsp)
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x8780
movq 0x38(%rsp), %rcx
leaq 0xa8(%rsp), %rdi
movl $0x2, %esi
leaq 0xa0(%rsp), %rdx
callq 0x8cf0
jmp 0x34abe
leaq 0x9f(%rsp), %rdi
callq 0x8910
cmpl $0x0, 0xfc(%rsp)
jg 0x34ba9
xorps %xmm0, %xmm0
callq 0x4390
movsd %xmm0, 0x90(%rsp)
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x8780
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rcx
movl $0x1, %esi
leaq 0x90(%rsp), %rdx
callq 0x8cf0
jmp 0x34b1a
leaq 0x8f(%rsp), %rdi
callq 0x8910
movl $0x1, 0x88(%rsp)
jmp 0x34dc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0xd7(%rsp), %rdi
callq 0x8910
jmp 0x34e07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0x9f(%rsp), %rdi
callq 0x8910
jmp 0x34dfa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0x8f(%rsp), %rdi
callq 0x8910
jmp 0x34ded
cmpl $0x1, 0xfc(%rsp)
jne 0x34c1e
leaq 0x87(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x8780
movq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rdx
movl $0x1, %esi
callq 0x8790
jmp 0x34bdb
leaq 0x87(%rsp), %rdi
callq 0x8910
movl $0x1, 0x88(%rsp)
jmp 0x34dc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0x87(%rsp), %rdi
callq 0x8910
jmp 0x34ded
cmpl $0x2, 0xfc(%rsp)
jne 0x34c4a
movq 0x40(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x36f00
movl $0x1, 0x88(%rsp)
jmp 0x34dc6
jmp 0x34c4c
jmp 0x34c4e
movl $0x2, 0x80(%rsp)
movl 0x80(%rsp), %eax
cmpl 0xfc(%rsp), %eax
jge 0x34da9
movl $0x1, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
movl %eax, 0x24(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x9b80
movq %rax, %rcx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jge 0x34d30
movl 0x7c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq 0xe0(%rsp), %rdi
callq 0x8c20
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movslq 0x7c(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x8c20
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0x7c(%rsp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm0
callq 0x4390
movsd 0x8(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
addsd %xmm2, %xmm1
callq 0x339b0
movsd %xmm0, 0x18(%rsp)
movslq 0x7c(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x8c20
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x34c75
movq $0x0, 0x70(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x36f30
jmp 0x34d4d
leaq 0x58(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x9a80
jmp 0x34d61
leaq 0xe0(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x8be0
leaq 0x58(%rsp), %rdi
callq 0x88b0
movl 0x80(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x80(%rsp)
jmp 0x34c59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
jmp 0x34ded
movq 0x40(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x36f00
movl $0x1, 0x88(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x88b0
leaq 0xe0(%rsp), %rdi
callq 0x88b0
movq 0x48(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
retq
leaq 0xa8(%rsp), %rdi
callq 0x88b0
leaq 0xe0(%rsp), %rdi
callq 0x88b0
movq 0xc8(%rsp), %rdi
callq 0x4730
nopw %cs:(%rax,%rax)