// File: /workspace/github_c_makefile_star2_O1/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 %rcx, -0x28(%rsp)
movq %rdx, -0x20(%rsp)
leal -0x1(%rsi), %eax
movslq %eax, %rbx
movslq %esi, %rax
movl %eax, %r14d
movl %eax, %ecx
sarl $0x1f, %ecx
andl %esi, %ecx
movq %rcx, -0x70(%rsp)
decl %ecx
movl %ecx, -0x3c(%rsp)
movq %rax, %rcx
imulq %rbx, %rcx
leaq (%rdi,%rcx,8), %r11
leaq (,%rax,8), %r10
movq %r10, %rcx
negq %rcx
movq %rcx, -0x38(%rsp)
leaq -0x1(%rax), %rcx
imulq %rax, %rcx
movq %rdi, -0x50(%rsp)
leaq (%rdi,%rcx,8), %r15
movq %rsi, -0x58(%rsp)
movl %esi, %r9d
imull %ebx, %r9d
xorpd %xmm0, %xmm0
leaq -0x8(,%rax,8), %r13
leaq (,%rbx,8), %rcx
movq %rax, %rbp
movq %r8, -0x78(%rsp)
testq %rbp, %rbp
jle 0x1a9a8
movq %rbp, %r12
movl %r12d, %edx
negq %rdx
leaq -0x1(%rbp), %rsi
movq %rsi, -0x30(%rsp)
movl %r9d, -0x48(%rsp)
movl %r9d, %r8d
movq %rcx, %r9
movq %r11, -0x68(%rsp)
movq %rbx, -0x80(%rsp)
movq %rbx, %rdi
movl %r8d, -0x60(%rsp)
movl %edi, %r8d
negq %r8
movb $0x1, %sil
movl $0x1, %ebx
leaq (%r8,%rbx), %rbp
cmpq $0x1, %rbp
je 0x1a86d
movsd -0x8(%r11,%rbx,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1a886
jp 0x1a886
cmpq %r12, %rbx
setl %sil
leaq (%rdx,%rbx), %rbp
incq %rbp
incq %rbx
cmpq $0x1, %rbp
jne 0x1a854
jmp 0x1a8d4
testb $0x1, %sil
je 0x1a8d4
leaq -0x1(%rdi), %rsi
addq -0x38(%rsp), %r11
movabsq $0x7fffffff8, %r8       # imm = 0x7FFFFFFF8
addq %r8, %r9
movl -0x60(%rsp), %r8d
subl -0x58(%rsp), %r8d
testq %rdi, %rdi
movq %rsi, %rdi
jg 0x1a841
movl %esi, %edi
movq -0x78(%rsp), %r8
movq -0x80(%rsp), %rbx
movq -0x68(%rsp), %r11
movl -0x48(%rsp), %r9d
movq -0x30(%rsp), %rbp
jmp 0x1a976
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
movq -0x78(%rsp), %r8
movq -0x30(%rsp), %rbp
movsd %xmm1, (%r8,%rbp,8)
cmpl %ebp, %edi
jne 0x1a900
movq -0x80(%rsp), %rbx
movq -0x68(%rsp), %r11
movl -0x48(%rsp), %r9d
jmp 0x1a976
shlq $0x1d, %r9
sarq $0x1d, %r9
movq -0x50(%rsp), %rdx
xorl %esi, %esi
movq -0x68(%rsp), %r11
movsd (%rdx,%r9), %xmm1
movsd (%rdx,%r13), %xmm2
movsd %xmm2, (%rdx,%r9)
movsd %xmm1, (%rdx,%r13)
incq %rsi
addq %r10, %rdx
cmpq %r12, %rsi
jl 0x1a914
cmpl $0x0, -0x58(%rsp)
movq -0x80(%rsp), %rbx
movl -0x48(%rsp), %r9d
jle 0x1a976
movslq -0x60(%rsp), %rdx
movq -0x50(%rsp), %rsi
leaq (%rsi,%rdx,8), %rdx
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm1
movsd (%r15,%rsi,8), %xmm2
movsd %xmm2, (%rdx,%rsi,8)
movsd %xmm1, (%r15,%rsi,8)
incq %rsi
cmpq %rsi, %r14
jne 0x1a958
decq %rbx
movq -0x38(%rsp), %rdx
addq %rdx, %r11
addq $-0x8, %r13
movabsq $0x7fffffff8, %rsi      # imm = 0x7FFFFFFF8
addq %rsi, %rcx
addq %rdx, %r15
subl -0x58(%rsp), %r9d
testl %edi, %edi
jns 0x1a80e
movl %ebp, -0x3c(%rsp)
jmp 0x1a9ad
movq -0x70(%rsp), %r12
movl %r12d, %r11d
testl %r12d, %r12d
movq %r12, -0x70(%rsp)
jle 0x1ab63
leaq 0x8(,%rax,8), %rcx
movq %rcx, -0x18(%rsp)
movq %r11, %r15
negq %r15
movl $0x1, %ecx
xorl %edx, %edx
xorpd %xmm0, %xmm0
movq -0x50(%rsp), %r12
movq %r12, %r9
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
movq %r9, -0x48(%rsp)
movb $0x1, %r8b
movq %rdx, -0x38(%rsp)
movl %edx, %r9d
movq %rbx, -0x30(%rsp)
movq %rbx, %rdx
movq %r12, %r13
xorl %ebp, %ebp
movq %rsi, %rbx
movq %rcx, -0x80(%rsp)
movl %r9d, -0x68(%rsp)
movb %r8b, -0x60(%rsp)
movq %rcx, %r8
movq %r13, -0x8(%rsp)
movq %r13, %rcx
movq %rbp, -0x10(%rsp)
movb $0x1, %r9b
subq $0x1, %rbp
jb 0x1aa3e
movsd (%rcx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1aa5a
jp 0x1aa5a
cmpq %r11, %r8
setb %r9b
addq %r10, %rcx
leaq (%r15,%r8), %r13
incq %r13
incq %r8
cmpq $0x1, %r13
jne 0x1aa2c
jmp 0x1aa9c
testb $0x1, %r9b
je 0x1aa9c
incq %rbx
cmpq %r11, %rbx
setb %r8b
movq -0x10(%rsp), %rbp
incq %rbp
movq -0x8(%rsp), %r13
addq $0x8, %r13
addq $0x8, %rdx
movl -0x68(%rsp), %r9d
addl -0x58(%rsp), %r9d
cmpq %r11, %rbx
movq -0x80(%rsp), %rcx
jne 0x1aa0f
jmp 0x1ab67
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
movq -0x78(%rsp), %rcx
movsd %xmm1, (%rcx,%rsi,8)
movl %ebx, %ecx
cmpq %rsi, %rcx
movq -0x48(%rsp), %r9
movq -0x30(%rsp), %rbx
je 0x1ab1c
shlq $0x1d, %rdx
sarq $0x1d, %rdx
movq %r11, %rcx
movq -0x50(%rsp), %r8
movsd (%r8,%rdx), %xmm1
movsd (%r8,%rdi), %xmm2
movsd %xmm2, (%r8,%rdx)
movsd %xmm1, (%r8,%rdi)
addq %r10, %r8
decq %rcx
jne 0x1aace
cmpq %rax, %rsi
jge 0x1ab1c
movslq -0x68(%rsp), %rcx
leaq (%r9,%rcx,8), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm1
movsd (%r12,%rdx,8), %xmm2
movsd %xmm2, (%rcx,%rdx,8)
movsd %xmm1, (%r12,%rdx,8)
incq %rdx
cmpq %rdx, %r14
jne 0x1aafe
testb $0x1, -0x60(%rsp)
movq -0x78(%rsp), %r8
je 0x1ab6c
incq %rsi
addq -0x18(%rsp), %r12
movq -0x80(%rsp), %rcx
incq %rcx
addq $0x8, %rdi
addq $0x8, %rbx
addq $0x8, %r9
movq -0x38(%rsp), %rdx
addl -0x58(%rsp), %edx
decq %r14
cmpq %r11, %rsi
jne 0x1a9ea
movq -0x70(%rsp), %r12
movl %r12d, %esi
jmp 0x1ab71
xorl %esi, %esi
jmp 0x1ab71
movq -0x78(%rsp), %r8
movq -0x70(%rsp), %r12
movq -0x28(%rsp), %rcx
movl -0x3c(%rsp), %edx
movl %edx, (%rcx)
movq -0x20(%rsp), %rcx
movl %esi, (%rcx)
cmpl %r12d, %esi
jge 0x1aba8
movl %esi, %ecx
leaq (%r8,%rcx,8), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movl %esi, %edi
movq %rdx, (%rcx)
addq $0x8, %rcx
incl %edi
cmpl %edi, %r12d
jg 0x1ab9a
cmpl %r12d, %esi
jge 0x1ad84
movslq %esi, %rdi
movslq %r12d, %rdx
leaq 0x8(,%rax,8), %r9
imulq %rdi, %r9
movq -0x50(%rsp), %rcx
addq %rcx, %r9
movq %r9, -0x78(%rsp)
movq %rdx, %r15
subq %rdi, %r15
subq %rdi, %rax
movq %rdi, -0x60(%rsp)
leaq (%rcx,%rdi,8), %rcx
movq %rcx, -0x80(%rsp)
xorpd %xmm0, %xmm0
movsd 0x1942d(%rip), %xmm1    # 0x34020
movsd 0x1940d(%rip), %xmm2    # 0x34008
movsd 0x19415(%rip), %xmm3    # 0x34018
movsd 0x21215(%rip), %xmm4    # 0x3be20
movsd 0x19475(%rip), %xmm5    # 0x34088
movapd 0x21225(%rip), %xmm6    # 0x3be40
movl $0x1, %ecx
movq -0x80(%rsp), %r12
movq -0x78(%rsp), %r14
movq %r14, %r13
xorl %ebp, %ebp
movq -0x60(%rsp), %rdi
xorpd %xmm7, %xmm7
movq %r13, %rbx
xorl %r9d, %r9d
xorpd %xmm9, %xmm9
cmpq %r9, %rbp
je 0x1ac67
movsd (%rbx), %xmm8
andpd %xmm6, %xmm8
addsd %xmm8, %xmm7
movsd (%r14,%r9,8), %xmm8
andpd %xmm6, %xmm8
addsd %xmm8, %xmm9
incq %r9
addq %r10, %rbx
cmpq %r9, %r15
jne 0x1ac43
ucomisd %xmm0, %xmm7
jne 0x1ac7e
jnp 0x1ad59
ucomisd %xmm0, %xmm9
jne 0x1ac8b
jnp 0x1ad59
movapd %xmm9, %xmm11
mulsd %xmm1, %xmm11
ucomisd %xmm7, %xmm11
movapd %xmm2, %xmm8
movapd %xmm7, %xmm10
jbe 0x1acc1
movapd %xmm7, %xmm10
movapd %xmm2, %xmm8
addsd %xmm8, %xmm8
mulsd %xmm3, %xmm10
ucomisd %xmm10, %xmm11
ja 0x1acb0
movapd %xmm9, %xmm11
addsd %xmm9, %xmm11
ucomisd %xmm11, %xmm10
jb 0x1acde
mulsd %xmm1, %xmm8
mulsd %xmm5, %xmm10
jmp 0x1accb
addsd %xmm9, %xmm7
addsd %xmm9, %xmm10
divsd %xmm8, %xmm10
mulsd %xmm4, %xmm7
ucomisd %xmm10, %xmm7
jbe 0x1ad59
movsd (%r8,%rdi,8), %xmm7
mulsd %xmm8, %xmm7
movsd %xmm7, (%r8,%rdi,8)
cmpl -0x58(%rsp), %esi
jge 0x1ad33
movapd %xmm2, %xmm7
divsd %xmm8, %xmm7
xorl %ecx, %ecx
movsd (%r14,%rcx,8), %xmm9
mulsd %xmm7, %xmm9
movsd %xmm9, (%r14,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x1ad1a
xorl %ecx, %ecx
movq %r11, %rbx
movq %r12, %r9
cmpl $0x0, -0x70(%rsp)
jle 0x1ad59
movsd (%r9), %xmm7
mulsd %xmm8, %xmm7
movsd %xmm7, (%r9)
addq %r10, %r9
decq %rbx
jne 0x1ad42
incq %rdi
addq %r10, %r14
incq %rbp
addq $0x8, %r13
addq $0x8, %r12
cmpq %rdx, %rdi
jne 0x1ac34
testl %ecx, %ecx
movq -0x70(%rsp), %rcx
jne 0x1ad84
cmpl %ecx, %esi
jl 0x1ac1b
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq