// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/convex.c
// Function: solve_qp_using_simplex
Convexsolutionptr solve_qp_using_simplex(Quadraticprogramptr program, BOOLEAN random)
{
 Convexsolutionptr solution;
 SOLUTION_TYPE solutiontype = NO_SOLUTION;
 int i, newbasic, newnonbasic;
 solution = safemalloc(sizeof(Convexsolution), "solve_qp_using_simplex", 4);
 while (BOOLEAN_TRUE)
  {
   /*print_simplex_tableau(program->constraints, program->basic, program->objectives);*/
   if (random)
     newbasic = find_variable_to_bring_into_basis_qp_random(program);
   else
     newbasic = find_variable_to_bring_into_basis_qp(program);
   if (newbasic == -1)
    {
     solutiontype = INFINITE_SOLUTION;
     break;
    }
   if (newbasic == -2)
    {
     solutiontype = SINGLE_SOLUTION;
     break;
    }
   newnonbasic = find_variable_to_remove_from_basis(program->constraints, program->constraintcount, newbasic);
   if (newnonbasic == -1)
    {
     solutiontype = UNBOUNDED_SOLUTION;
     break;
    }
   pivot_on_the_new_variables(program->constraints, program->objectives, newnonbasic, newbasic);
   program->isbasic[newbasic] = BOOLEAN_TRUE;
   program->isbasic[program->basic[newnonbasic]] = BOOLEAN_FALSE;
   program->basic[newnonbasic] = newbasic;
  }
 solution->optimalvalue = program->objectives[program->variablecount + program->constraintcount];
 printf("Optimal:%f\n", solution->optimalvalue);
 solution->variablecount = program->n;
 solution->solutiontype = solutiontype;
 solution->variables = safecalloc(solution->variablecount, sizeof(double), "solve_qp_using_simplex", 23);
 for (i = 0; i < program->constraintcount; i++)
   if (program->basic[i] < program->n)
     solution->variables[program->basic[i]] = program->constraints.values[i][program->variablecount + program->constraintcount];
 return solution;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x962e7(%rip), %rsi     # 0xa62d7
movl $0x20, %edi
movl $0x4, %edx
callq 0x3a0e1
movq %rax, (%rsp)
movl $0x2, %r14d
movq %rbx, %rdi
testl %ebp, %ebp
je 0x10017
callq 0xf473
jmp 0x1001c
callq 0xf65c
movl %eax, %r15d
cmpl $-0x2, %eax
je 0x100e2
cmpl $-0x1, %r15d
je 0x100da
movslq 0x8(%rbx), %rax
testq %rax, %rax
jle 0x100e5
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rsi
movslq %r15d, %r13
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rdi, %rcx
sarq $0x20, %rcx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %edx, %edx
movsd 0x954ad(%rip), %xmm0    # 0xa5518
xorpd %xmm3, %xmm3
movq (%rsi,%rdx,8), %r8
movsd (%r8,%r13,8), %xmm2
ucomisd %xmm3, %xmm2
jbe 0x10096
movsd (%r8,%rcx,8), %xmm1
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x10096
movl %edx, %r12d
movapd %xmm1, %xmm0
incq %rdx
cmpq %rdx, %rax
jne 0x1006f
cmpl $-0x1, %r12d
je 0x100e5
movq 0x38(%rbx), %rdx
movl %r12d, %ecx
movl %r15d, %r8d
callq 0xf797
movq 0x40(%rbx), %rax
movl $0x1, (%rax,%r13,4)
movq 0x48(%rbx), %rcx
movslq %r12d, %rdx
movslq (%rcx,%rdx,4), %rsi
movl $0x0, (%rax,%rsi,4)
movl %r15d, (%rcx,%rdx,4)
jmp 0x10009
movl $0x3, %r14d
jmp 0x100e5
xorl %r14d, %r14d
movq 0x38(%rbx), %rax
movslq 0xc(%rbx), %rcx
movslq 0x8(%rbx), %rdx
addq %rcx, %rdx
movsd (%rax,%rdx,8), %xmm0
movq (%rsp), %r15
movsd %xmm0, 0x8(%r15)
leaq 0x961e4(%rip), %rdi     # 0xa62ee
movb $0x1, %al
callq 0x4030
movslq (%rbx), %rdi
movl %edi, 0x18(%r15)
movl %r14d, (%r15)
leaq 0x961b5(%rip), %rdx     # 0xa62d7
movl $0x8, %esi
movl $0x17, %ecx
callq 0x3a1fc
movq %rax, 0x10(%r15)
movslq 0x8(%rbx), %rcx
testq %rcx, %rcx
jle 0x10172
movq 0x48(%rbx), %rdx
movl (%rbx), %esi
xorl %edi, %edi
movslq (%rdx,%rdi,4), %r8
cmpl %esi, %r8d
jge 0x1016a
movq 0x18(%rbx), %r9
movq (%r9,%rdi,8), %r9
movslq 0xc(%rbx), %r10
addq %rcx, %r10
movsd (%r9,%r10,8), %xmm0
movsd %xmm0, (%rax,%r8,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x10146
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq