// File: /workspace/github_c_makefile_star2_O2/dapogon[P]cellcoal/src/eigen.c
// Function: balance
void balance(double mat[], int n,int *low, int *hi, double scale[])
{
/* Balance a matrix for calculation of eigenvalues and eigenvectors
*/
    double c,f,g,r,s;
    int i,j,k,l,done;
        /* search for rows isolating an eigenvalue and push them down */
    for (k = n - 1; k >= 0; k--) {
        for (j = k; j >= 0; j--) {
            for (i = 0; i <= k; i++) {
                if (i != j && fabs(mat[pos(j,i,n)]) != 0) break;
            }

            if (i > k) {
                scale[k] = j;

                if (j != k) {
                    for (i = 0; i <= k; i++) {
                       c = mat[pos(i,j,n)];
                       mat[pos(i,j,n)] = mat[pos(i,k,n)];
                       mat[pos(i,k,n)] = c;
                    }

                    for (i = 0; i < n; i++) {
                       c = mat[pos(j,i,n)];
                       mat[pos(j,i,n)] = mat[pos(k,i,n)];
                       mat[pos(k,i,n)] = c;
                    }
                }
                break;
            }
        }
        if (j < 0) break;
    }

    /* search for columns isolating an eigenvalue and push them left */

    for (l = 0; l <= k; l++) {
        for (j = l; j <= k; j++) {
            for (i = l; i <= k; i++) {
                if (i != j && fabs(mat[pos(i,j,n)]) != 0) break;
            }
            if (i > k) {
                scale[l] = j;
                if (j != l) {
                    for (i = 0; i <= k; i++) {
                       c = mat[pos(i,j,n)];
                       mat[pos(i,j,n)] = mat[pos(i,l,n)];
                       mat[pos(i,l,n)] = c;
                    }

                    for (i = l; i < n; i++) {
                       c = mat[pos(j,i,n)];
                       mat[pos(j,i,n)] = mat[pos(l,i,n)];
                       mat[pos(l,i,n)] = c;
                    }
                }

                break;
            }
        }

        if (j > k) break;
    }

    *hi = k;
    *low = l;

    /* balance the submatrix in rows l through k */

    for (i = l; i <= k; i++) {
        scale[i] = 1;
    }

    do {
        for (done = 1,i = l; i <= k; i++) {
            for (c = 0,r = 0,j = l; j <= k; j++) {
                if (j != i) {
                    c += fabs(mat[pos(j,i,n)]);
                    r += fabs(mat[pos(i,j,n)]);
                }
            }

            if (c != 0 && r != 0) {
                g = r / BASE;
                f = 1;
                s = c + r;

                while (c < g) {
                    f *= BASE;
                    c *= BASE * BASE;
                }

                g = r * BASE;

                while (c >= g) {
                    f /= BASE;
                    c /= BASE * BASE;
                }

                if ((c + r) / f < 0.95 * s) {
                    done = 0;
                    g = 1 / f;
                    scale[i] *= f;

                    for (j = l; j < n; j++) {
                        mat[pos(i,j,n)] *= g;
                    }

                    for (j = 0; j <= k; j++) {
                        mat[pos(j,i,n)] *= f;
                    }
                }
            }
        }
    } while (!done);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r8, -0x50(%rsp)
movq %rcx, -0x30(%rsp)
movq %rdx, -0x28(%rsp)
leal -0x1(%rsi), %eax
movslq %eax, %rbx
movslq %esi, %rax
xorl %r15d, %r15d
testl %eax, %eax
cmovgl %esi, %r15d
movq %rax, %rcx
imulq %rbx, %rcx
leaq (%rdi,%rcx,8), %rcx
movq %rcx, -0x68(%rsp)
leaq (,%rax,8), %r9
movq %r9, %rcx
negq %rcx
movq %rcx, -0x58(%rsp)
leaq -0x8(,%rax,8), %r11
leaq (,%rbx,8), %r13
leaq -0x1(%rax), %rcx
imulq %rax, %rcx
movq %rdi, -0x70(%rsp)
leaq (%rdi,%rcx,8), %r12
movq %rsi, -0x60(%rsp)
movl %esi, %ebp
imull %ebx, %ebp
xorpd %xmm0, %xmm0
movq %rax, %rdx
movl %edx, %r10d
leaq -0x1(%rdx), %rcx
movq %rcx, -0x48(%rsp)
testq %rdx, %rdx
movq %rdx, -0x38(%rsp)
jle 0x17115
movl %ebp, %esi
movq %r13, %r8
movq -0x68(%rsp), %rcx
movq %rbx, %r14
testq %r14, %r14
js 0x17115
movq %rbx, %rdi
movl %r14d, %ebx
xorl %edx, %edx
cmpq %rdx, %r10
je 0x1706c
cmpq %rdx, %rbx
je 0x17044
movsd (%rcx,%rdx,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x17049
jp 0x17049
incq %rdx
jmp 0x1702d
decq %r14
addq -0x58(%rsp), %rcx
movabsq $0x7fffffff8, %rdx      # imm = 0x7FFFFFFF8
addq %rdx, %r8
subl -0x60(%rsp), %esi
movq -0x38(%rsp), %rdx
movq %rdi, %rbx
jmp 0x1701c
cvtsi2sd %r14d, %xmm1
movq -0x50(%rsp), %rcx
movq -0x48(%rsp), %rdx
movsd %xmm1, (%rcx,%rdx,8)
cmpq %rdx, %r14
movq %rdi, %rbx
jne 0x170b7
decq %rbx
movq -0x58(%rsp), %rcx
addq %rcx, -0x68(%rsp)
addq $-0x8, %r11
movabsq $0x7fffffff8, %rdx      # imm = 0x7FFFFFFF8
addq %rdx, %r13
addq %rcx, %r12
subl -0x60(%rsp), %ebp
movq -0x48(%rsp), %rdx
jmp 0x16ff5
shlq $0x1d, %r8
sarq $0x1d, %r8
movq -0x70(%rsp), %rcx
subq $0x1, %r10
jb 0x170e7
movsd (%rcx,%r8), %xmm1
movsd (%rcx,%r11), %xmm2
movsd %xmm2, (%rcx,%r8)
movsd %xmm1, (%rcx,%r11)
addq %r9, %rcx
jmp 0x170c4
movslq %esi, %rcx
movq -0x70(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
xorl %edx, %edx
cmpq %rdx, %r15
je 0x17088
movsd (%rcx,%rdx,8), %xmm1
movsd (%r12,%rdx,8), %xmm2
movsd %xmm2, (%rcx,%rdx,8)
movsd %xmm1, (%r12,%rdx,8)
incq %rdx
jmp 0x170f5
xorl %ebx, %ebx
testl %edx, %edx
movl $0x0, %ebp
cmovgl %edx, %ebp
movl %edx, %ecx
movq %rcx, -0x10(%rsp)
movq %r10, %r13
negq %r13
leaq 0x8(,%rax,8), %rcx
movq %rcx, -0x18(%rsp)
xorpd %xmm0, %xmm0
xorl %edx, %edx
movq -0x60(%rsp), %rcx
movq -0x70(%rsp), %rdi
movq %rdi, %r14
xorl %esi, %esi
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %rbp, -0x20(%rsp)
cmpl %r15d, %ecx
movl %r15d, %r11d
cmovgl %ecx, %r11d
cmpq %rbp, %r15
je 0x1728a
movq %r14, -0x8(%rsp)
movq %rbx, -0x58(%rsp)
addq %rbx, %r11
movl %edx, -0x3c(%rsp)
movl %edx, %ecx
movq %rsi, -0x68(%rsp)
movq %rsi, %rdx
xorl %r8d, %r8d
movq %rdi, %r14
movq %r15, %rbp
cmpq -0x10(%rsp), %rbp
je 0x17285
movq %r14, %rsi
xorl %ebx, %ebx
cmpq %rbx, %r13
je 0x171d4
cmpq %rbx, %r8
je 0x171b8
movsd (%rsi), %xmm1
ucomisd %xmm0, %xmm1
jne 0x171c0
jp 0x171c0
decq %rbx
addq %r9, %rsi
jmp 0x171a2
incq %rbp
addq $0x8, %r14
decq %r8
addq $0x8, %rdx
addl -0x60(%rsp), %ecx
jmp 0x17192
cvtsi2sd %ebp, %xmm1
movq -0x50(%rsp), %rsi
movsd %xmm1, (%rsi,%r15,8)
movl %ebp, %esi
cmpq %r15, %rsi
movq -0x20(%rsp), %rbp
movq -0x58(%rsp), %rbx
movq -0x8(%rsp), %r14
movq -0x68(%rsp), %rsi
jne 0x17228
incq %r15
incq %r13
addq -0x18(%rsp), %rdi
addq $0x8, %r12
addq $0x8, %rsi
addq $0x8, %r14
movq -0x60(%rsp), %rcx
movl -0x3c(%rsp), %edx
addl %ecx, %edx
decq %rbx
jmp 0x1715b
shlq $0x1d, %rdx
sarq $0x1d, %rdx
movq -0x70(%rsp), %rsi
movq %r10, %r8
subq $0x1, %r8
jb 0x17259
movsd (%rsi,%rdx), %xmm1
movsd (%rsi,%r12), %xmm2
movsd %xmm2, (%rsi,%rdx)
movsd %xmm1, (%rsi,%r12)
addq %r9, %rsi
jmp 0x17238
movslq %ecx, %rcx
leaq (%r14,%rcx,8), %rcx
xorl %edx, %edx
movq -0x68(%rsp), %rsi
cmpq %rdx, %r11
je 0x171fe
movsd (%rcx,%rdx,8), %xmm1
movsd (%rdi,%rdx,8), %xmm2
movsd %xmm2, (%rcx,%rdx,8)
movsd %xmm1, (%rdi,%rdx,8)
incq %rdx
jmp 0x17267
movl %r15d, %ebp
jmp 0x1728d
movl %ebp, %r15d
movq -0x30(%rsp), %rcx
movq -0x48(%rsp), %rdx
movl %edx, (%rcx)
movq -0x28(%rsp), %rcx
movl %r15d, (%rcx)
movslq -0x38(%rsp), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rbp, %rsi
movq -0x50(%rsp), %r14
movq -0x70(%rsp), %r12
cmpq %rcx, %rsi
jge 0x172cb
movq %rdx, (%r14,%rsi,8)
incq %rsi
jmp 0x172bd
movq %rbp, %rdx
imulq %rax, %rdx
leaq (%r12,%rdx,8), %rdx
movl $0x1, %esi
xorpd %xmm0, %xmm0
movsd 0x7de1(%rip), %xmm1     # 0x1f0c8
movapd 0xfb91(%rip), %xmm2     # 0x26e80
movsd 0xfb49(%rip), %xmm3     # 0x26e40
movsd 0x7db1(%rip), %xmm4     # 0x1f0b0
movapd 0xfb69(%rip), %xmm5     # 0x26e70
movapd 0xfb51(%rip), %xmm6     # 0x26e60
movq %rbp, %rbx
movl %esi, %edi
cmpq %rcx, %rbx
jge 0x17356
movq %rbx, %r8
imulq %rax, %r8
leaq (%r12,%r8,8), %r8
leaq (%rdx,%rbx,8), %r11
xorpd %xmm8, %xmm8
movq %rbp, %r15
cmpq %r15, %r10
je 0x17364
cmpq %r15, %rbx
je 0x1734e
movsd (%r11), %xmm7
movhpd (%r8,%r15,8), %xmm7     # xmm7 = xmm7[0],mem[0]
andpd %xmm6, %xmm7
addpd %xmm7, %xmm8
incq %r15
addq %r9, %r11
jmp 0x17330
movq %rbp, %rbx
testl %edi, %edi
movl %esi, %edi
je 0x17314
jmp 0x17450
ucomisd %xmm0, %xmm8
jne 0x17371
jnp 0x17448
movapd %xmm8, %xmm9
unpckhpd %xmm8, %xmm9            # xmm9 = xmm9[1],xmm8[1]
ucomisd %xmm0, %xmm9
jne 0x17388
jnp 0x17448
movapd %xmm9, %xmm10
mulsd %xmm1, %xmm10
movapd %xmm8, %xmm7
movhpd 0x7d11(%rip), %xmm7     # xmm7 = xmm7[0],mem[0]
ucomisd %xmm7, %xmm10
jbe 0x173ac
mulpd %xmm2, %xmm7
jmp 0x1739f
movapd %xmm9, %xmm10
addsd %xmm9, %xmm10
ucomisd %xmm10, %xmm7
jb 0x173c3
mulpd %xmm5, %xmm7
jmp 0x173b6
movapd %xmm9, %xmm10
addsd %xmm8, %xmm10
movapd %xmm7, %xmm8
addsd %xmm9, %xmm8
unpckhpd %xmm7, %xmm7            # xmm7 = xmm7[1,1]
divsd %xmm7, %xmm8
mulsd %xmm3, %xmm10
ucomisd %xmm8, %xmm10
jbe 0x17448
movapd %xmm4, %xmm8
divsd %xmm7, %xmm8
movsd (%r14,%rbx,8), %xmm9
mulsd %xmm7, %xmm9
movsd %xmm9, (%r14,%rbx,8)
movq %rbp, %rdi
cmpq %rax, %rdi
jge 0x17425
movsd (%r8,%rdi,8), %xmm9
mulsd %xmm8, %xmm9
movsd %xmm9, (%r8,%rdi,8)
incq %rdi
jmp 0x1740a
leaq (%r12,%rbx,8), %rdi
movq %r10, %r8
subq $0x1, %r8
jb 0x17446
movsd (%rdi), %xmm8
mulsd %xmm7, %xmm8
movsd %xmm8, (%rdi)
addq %r9, %rdi
jmp 0x1742c
xorl %edi, %edi
incq %rbx
jmp 0x17314
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq