// File: /workspace/github_c_makefile_star2_O3/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, -0x48(%rsp)
movl %esi, %r13d
movl %esi, %r9d
testl %esi, %esi
jle 0x1ac05
movq %rcx, -0x40(%rsp)
movq %rdx, -0x38(%rsp)
leaq -0x1(%r9), %rsi
movq %rsi, %rax
imulq %r9, %rax
movq %rdi, -0x60(%rsp)
leaq (%rdi,%rax,8), %rax
leaq (,%r9,8), %r11
movq %r11, %rdx
negq %rdx
leal -0x1(%r13), %edi
leaq -0x8(,%r9,8), %r8
movabsq $0x7fffffff8, %rcx      # imm = 0x7FFFFFFF8
leaq (%rcx,%r13,8), %r15
movq %r13, -0x58(%rsp)
imull %r13d, %edi
xorpd %xmm0, %xmm0
movq %r9, %r12
movq %rsi, %r13
movl %edi, %ecx
movq %r15, %rsi
movq %rax, %rbx
movq %r13, %r14
movl %r14d, %ebp
xorl %r10d, %r10d
cmpq %r10, %rbp
je 0x1ab39
movsd (%rbx,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1ab43
jp 0x1ab43
incq %r10
cmpq %r10, %r12
jne 0x1ab26
jmp 0x1ab68
leaq -0x1(%r14), %r10
addq %rdx, %rbx
movabsq $0x7fffffff8, %rbp      # imm = 0x7FFFFFFF8
addq %rbp, %rsi
subl -0x58(%rsp), %ecx
testq %r14, %r14
movq %r10, %r14
jg 0x1ab20
jmp 0x1ac1c
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movq -0x48(%rsp), %r10
movsd %xmm1, (%r10,%r13,8)
cmpq %r13, %rbp
je 0x1abd8
shlq $0x1d, %rsi
sarq $0x1d, %rsi
movq %r12, %r10
movq -0x60(%rsp), %rbx
movsd (%rbx,%rsi), %xmm1
movq (%rbx,%r8), %xmm2
movq %xmm2, (%rbx,%rsi)
movsd %xmm1, (%rbx,%r8)
addq %r11, %rbx
decq %r10
jne 0x1ab90
movslq %ecx, %rcx
movq -0x60(%rsp), %rsi
leaq (%rsi,%rcx,8), %rcx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm1
movq (%rax,%rsi,8), %xmm2
movq %xmm2, (%rcx,%rsi,8)
movsd %xmm1, (%rax,%rsi,8)
incq %rsi
cmpq %rsi, %r9
jne 0x1abbc
leaq -0x1(%r13), %rsi
decq %r12
addq %rdx, %rax
addq $-0x8, %r8
movabsq $0x7fffffff8, %rcx      # imm = 0x7FFFFFFF8
addq %rcx, %r15
subl -0x58(%rsp), %edi
movq %r13, %rbp
testq %r13, %r13
jg 0x1ab12
jmp 0x1ac22
leal -0x1(%r13), %esi
movl $0x0, -0x4c(%rsp)
movl %r13d, %ebp
xorl %r14d, %r14d
jmp 0x1ade5
movq %r12, %rbp
movq %r13, %rsi
testl %ebp, %ebp
setg %al
jle 0x1ada1
movq %rsi, -0x28(%rsp)
movl %eax, -0x4c(%rsp)
movq %rbp, -0x20(%rsp)
movl %ebp, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
leaq 0x8(,%r9,8), %rax
movq %rax, -0x10(%rsp)
movq %r13, -0x30(%rsp)
negq %r13
xorl %ebp, %ebp
xorpd %xmm0, %xmm0
movq %r9, %rax
movq -0x60(%rsp), %r8
movq %r8, %rbx
xorl %esi, %esi
xorl %edx, %edx
xorl %r15d, %r15d
movq %rbx, -0x8(%rsp)
movl %ebp, %ecx
movq %rsi, %r12
movq %r8, %r14
xorl %ebx, %ebx
movq %r15, -0x18(%rsp)
movq %r15, %r10
movq %r14, %r15
xorl %edi, %edi
cmpq %rdi, %rbx
je 0x1aca0
movsd (%r15), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1acad
jp 0x1acad
decq %rdi
addq %r11, %r15
cmpq %rdi, %r13
jne 0x1ac8e
jmp 0x1accb
incq %r10
decq %rbx
addq $0x8, %r14
addq $0x8, %r12
addl -0x58(%rsp), %ecx
cmpq -0x30(%rsp), %r10
jne 0x1ac89
jmp 0x1adc2
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
movq -0x48(%rsp), %rdi
movq -0x18(%rsp), %r15
movsd %xmm1, (%rdi,%r15,8)
movl %r10d, %edi
cmpq %r15, %rdi
movq -0x8(%rsp), %rbx
je 0x1ad4e
shlq $0x1d, %r12
sarq $0x1d, %r12
movq -0x30(%rsp), %rdi
movq -0x60(%rsp), %r10
movsd (%r10,%r12), %xmm1
movq (%r10,%rdx), %xmm2
movq %xmm2, (%r10,%r12)
movsd %xmm1, (%r10,%rdx)
addq %r11, %r10
decq %rdi
jne 0x1ad02
cmpq %r9, %r15
jae 0x1ad4e
movslq %ecx, %rcx
leaq (%rbx,%rcx,8), %rcx
xorl %edi, %edi
movsd (%rcx,%rdi,8), %xmm1
movq (%r8,%rdi,8), %xmm2
movq %xmm2, (%rcx,%rdi,8)
movsd %xmm1, (%r8,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x1ad30
incq %r15
addq -0x10(%rsp), %r8
incq %r13
addq $0x8, %rdx
addq $0x8, %rsi
addq $0x8, %rbx
addl -0x58(%rsp), %ebp
decq %rax
cmpq -0x30(%rsp), %r15
jne 0x1ac72
movq -0x40(%rsp), %rax
movq -0x28(%rsp), %rcx
movl %ecx, (%rax)
movq -0x38(%rsp), %rax
movq -0x20(%rsp), %rbp
movl %ebp, (%rax)
movl %ebp, %r14d
movq -0x58(%rsp), %r13
movq -0x60(%rsp), %rdi
jmp 0x1aeaf
movl $0x0, -0x4c(%rsp)
xorl %r14d, %r14d
movq -0x58(%rsp), %r13
movq -0x60(%rsp), %rdi
movq -0x38(%rsp), %rdx
movq -0x40(%rsp), %rcx
jmp 0x1ade5
movq -0x58(%rsp), %r13
movq -0x60(%rsp), %rdi
movq -0x18(%rsp), %r14
movq -0x38(%rsp), %rdx
movq -0x40(%rsp), %rcx
movq -0x20(%rsp), %rbp
movq -0x28(%rsp), %rsi
movl %esi, (%rcx)
movl %r14d, (%rdx)
cmpl %ebp, %r14d
setl %al
jge 0x1aeaf
movq %rdi, %r11
movl %r14d, %edx
movl %ebp, %esi
subq %rdx, %rsi
leaq 0x1(%rsi), %rcx
andq $-0x2, %rcx
decq %rsi
movq %rsi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movq -0x48(%rsp), %rsi
leaq (%rsi,%rdx,8), %rsi
addq $0x8, %rsi
xorl %edi, %edi
movdqa 0x8233(%rip), %xmm1     # 0x23060
movdqa 0x823b(%rip), %xmm2     # 0x23070
pxor %xmm2, %xmm0
movabsq $0x3ff0000000000000, %r8 # imm = 0x3FF0000000000000
pcmpeqd %xmm3, %xmm3
movq %rdi, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
por %xmm1, %xmm4
pxor %xmm2, %xmm4
movdqa %xmm4, %xmm5
pcmpgtd %xmm0, %xmm5
pcmpeqd %xmm0, %xmm4
pshufd $0xf5, %xmm4, %xmm6     # xmm6 = xmm4[1,1,3,3]
pand %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm4     # xmm4 = xmm5[1,1,3,3]
por %xmm6, %xmm4
movd %xmm4, %r10d
notl %r10d
testb $0x1, %r10b
je 0x1ae8a
movq %r8, -0x8(%rsi,%rdi,8)
pxor %xmm3, %xmm4
pextrw $0x4, %xmm4, %r10d
testb $0x1, %r10b
je 0x1ae9e
movq %r8, (%rsi,%rdi,8)
addq $0x2, %rdi
cmpq %rdi, %rcx
jne 0x1ae47
movq %r14, %r10
movq %r11, %rdi
jmp 0x1aeb7
movq %r14, %r10
movl %r14d, %edx
xorl %eax, %eax
testb %al, %al
je 0x1b05e
movslq %r13d, %r11
movl %ebp, %ebx
movq %rdx, %rcx
imulq %r11, %rcx
leaq (%rdi,%rcx,8), %r14
leaq (,%r11,8), %r15
movl $0x1, %ebp
xorpd %xmm0, %xmm0
movsd 0x8230(%rip), %xmm1     # 0x23118
movapd 0x10020(%rip), %xmm2    # 0x2af10
movsd 0xffe8(%rip), %xmm3     # 0x2aee0
movsd 0x8200(%rip), %xmm4     # 0x23100
movapd 0x10018(%rip), %xmm5    # 0x2af20
movapd 0xfff0(%rip), %xmm6     # 0x2af00
movq %rdx, %r12
movq %r12, %rcx
imulq %r11, %rcx
leaq (%rdi,%rcx,8), %r8
leaq (%r14,%r12,8), %rcx
xorpd %xmm8, %xmm8
movq %rdx, %rsi
cmpq %rsi, %r12
je 0x1af42
movsd (%rcx), %xmm7
movhpd (%r8,%rsi,8), %xmm7     # xmm7 = xmm7[0],mem[0]
andpd %xmm6, %xmm7
addpd %xmm7, %xmm8
incq %rsi
addq %r15, %rcx
cmpq %rsi, %rbx
jne 0x1af2a
ucomisd %xmm0, %xmm8
jne 0x1af5a
jnp 0x1b03d
movapd %xmm8, %xmm9
unpckhpd %xmm8, %xmm9            # xmm9 = xmm9[1],xmm8[1]
ucomisd %xmm0, %xmm9
jne 0x1af71
jnp 0x1b03d
movapd %xmm9, %xmm10
mulsd %xmm1, %xmm10
ucomisd %xmm8, %xmm10
movapd %xmm8, %xmm7
movhpd 0x8173(%rip), %xmm7     # xmm7 = xmm7[0],mem[0]
jbe 0x1af9a
mulpd %xmm2, %xmm7
ucomisd %xmm7, %xmm10
ja 0x1af8f
movapd %xmm9, %xmm10
addsd %xmm9, %xmm10
ucomisd %xmm10, %xmm7
jb 0x1afb1
mulpd %xmm5, %xmm7
jmp 0x1afa4
movapd %xmm9, %xmm10
addsd %xmm8, %xmm10
addsd %xmm7, %xmm9
unpckhpd %xmm7, %xmm7            # xmm7 = xmm7[1,1]
divsd %xmm7, %xmm9
mulsd %xmm3, %xmm10
ucomisd %xmm9, %xmm10
jbe 0x1b03d
movq -0x48(%rsp), %rcx
movsd (%rcx,%r12,8), %xmm8
mulsd %xmm7, %xmm8
movsd %xmm8, (%rcx,%r12,8)
cmpl %r13d, %r10d
jge 0x1b016
movapd %xmm4, %xmm8
divsd %xmm7, %xmm8
movq %rdx, %rcx
movsd (%r8,%rcx,8), %xmm9
mulsd %xmm8, %xmm9
movsd %xmm9, (%r8,%rcx,8)
incq %rcx
cmpq %rcx, %r9
jne 0x1affd
xorl %ebp, %ebp
cmpb $0x0, -0x4c(%rsp)
je 0x1b03d
leaq (%rdi,%r12,8), %rcx
movq %rbx, %rsi
movsd (%rcx), %xmm8
mulsd %xmm7, %xmm8
movsd %xmm8, (%rcx)
addq %r15, %rcx
decq %rsi
jne 0x1b026
incq %r12
cmpq %rbx, %r12
jne 0x1af13
testl %ebp, %ebp
sete %cl
movq %rdx, %r12
movl $0x1, %ebp
testb %al, %cl
jne 0x1af13
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq