// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/matrix.c
// Function: balance
double* balance(matrix a)
{
 int i, j;
 BOOLEAN done = BOOLEAN_FALSE; 
 double sqrdx = 4, r, c, g, f, s, *scale;
 scale = safemalloc(a.row * sizeof(double), "balance", 3);
 for (i = 0; i < a.row; i++)
   scale[i] = 1.0;
 while (!done) 
  {
   done = BOOLEAN_TRUE; 
   for (i = 0; i < a.row; i++) 
    {
     r = 0.0;
     c = 0.0; 
     for (j = 0; j < a.col; j++)
       if (j != i) 
        { 
         c += fabs(a.values[j][i]); 
         r += fabs(a.values[i][j]);
        } 
     if (c != 0.0 && r != 0.0) 
      {
       g = r / 2; 
       f = 1.0; 
       s = c + r; 
       while (c < g) 
        {
         f *= 2; 
         c *= sqrdx;
        } 
       g = r * 2; 
       while (c > g) 
        {
         f /= 2; 
         c /= sqrdx;
        } 
       if ((c + r) / f < 0.95 * s) 
        {
         done = BOOLEAN_FALSE; 
         g = 1.0 / f; 
         scale[i] *= f; 
         for (j = 0; j < a.row; j++) 
           a.values[i][j] *= g; 
         for (j = 0; j < a.row; j++) 
           a.values[j][i] *= f;
        }
      }
    }
  }
 return scale;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movslq %r14d, %r15
leaq (,%r15,8), %rdi
leaq 0x68b39(%rip), %rsi     # 0xaa026
movl $0x3, %edx
callq 0x3a0e1
testl %r15d, %r15d
jle 0x415a0
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%r14), %ecx
andl $-0x2, %ecx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x64f1b(%rip), %xmm1    # 0xa6440
xorl %edx, %edx
movdqa 0x64f21(%rip), %xmm2    # 0xa6450
pxor %xmm2, %xmm0
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
pcmpeqd %xmm3, %xmm3
movdqa 0x64f47(%rip), %xmm4    # 0xa6490
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edi
notl %edi
testb $0x1, %dil
je 0x4157f
movq %rsi, (%rax,%rdx,8)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edi
testb $0x1, %dil
je 0x41593
movq %rsi, 0x8(%rax,%rdx,8)
addq $0x2, %rdx
paddq %xmm4, %xmm1
cmpq %rdx, %rcx
jne 0x41549
testl %r14d, %r14d
jle 0x41735
movq %r14, %rcx
shrq $0x20, %rcx
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x1, %edi
xorl %esi, %esi
pxor %xmm0, %xmm0
movsd 0x6474c(%rip), %xmm1    # 0xa5d18
movapd 0x6893c(%rip), %xmm2    # 0xa9f10
movapd 0x68944(%rip), %xmm3    # 0xa9f20
movsd 0x68904(%rip), %xmm4    # 0xa9ee8
movsd 0x63f34(%rip), %xmm5    # 0xa5520
movapd 0x64bec(%rip), %xmm6    # 0xa61e0
testl %ecx, %ecx
jle 0x41712
xorpd %xmm8, %xmm8
xorl %r8d, %r8d
cmpq %r8, %rsi
je 0x41626
movq (%rbx,%r8,8), %r9
movq (%rbx,%rsi,8), %r10
movsd (%r9,%rsi,8), %xmm7
movhpd (%r10,%r8,8), %xmm7     # xmm7 = xmm7[0],mem[0]
andpd %xmm6, %xmm7
addpd %xmm7, %xmm8
incq %r8
cmpq %r8, %rcx
jne 0x41604
ucomisd %xmm0, %xmm8
jne 0x4163b
jnp 0x41712
movapd %xmm8, %xmm9
unpckhpd %xmm8, %xmm9            # xmm9 = xmm9[1],xmm8[1]
ucomisd %xmm0, %xmm9
jne 0x41652
jnp 0x41712
movapd %xmm9, %xmm10
mulsd %xmm1, %xmm10
ucomisd %xmm8, %xmm10
movapd %xmm8, %xmm7
movhpd 0x63eb2(%rip), %xmm7    # xmm7 = xmm7[0],mem[0]
jbe 0x4167b
mulpd %xmm2, %xmm7
ucomisd %xmm7, %xmm10
ja 0x41670
movapd %xmm9, %xmm10
addsd %xmm9, %xmm10
ucomisd %xmm10, %xmm7
jbe 0x41692
mulpd %xmm3, %xmm7
jmp 0x41685
movapd %xmm9, %xmm10
addsd %xmm8, %xmm10
addsd %xmm7, %xmm9
unpckhpd %xmm7, %xmm7            # xmm7 = xmm7[1,1]
divsd %xmm7, %xmm9
mulsd %xmm4, %xmm10
ucomisd %xmm9, %xmm10
jbe 0x41712
movapd %xmm5, %xmm8
divsd %xmm7, %xmm8
movsd (%rax,%rsi,8), %xmm9
mulsd %xmm7, %xmm9
movsd %xmm9, (%rax,%rsi,8)
movq (%rbx,%rsi,8), %rdi
xorl %r8d, %r8d
movsd (%rdi,%r8,8), %xmm9
mulsd %xmm8, %xmm9
movsd %xmm9, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rdx
jne 0x416d8
xorl %edi, %edi
movq (%rbx,%rdi,8), %r8
movsd (%r8,%rsi,8), %xmm8
mulsd %xmm7, %xmm8
movsd %xmm8, (%r8,%rsi,8)
incq %rdi
cmpq %rdi, %rdx
jne 0x416f3
xorl %edi, %edi
incq %rsi
cmpq %rdx, %rsi
jne 0x415f4
testl %edi, %edi
jne 0x41735
movl $0x0, %esi
movl $0x1, %edi
testl %r14d, %r14d
jg 0x415f4
popq %rbx
popq %r14
popq %r15
retq