// File: /workspace/github_c_makefile_star2_O1/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 0x9330e(%rip), %rsi     # 0xa32d7
movl $0x20, %edi
movl $0x4, %edx
callq 0x390f5
movq %rax, %r14
movq %rbx, %rdi
testl %ebp, %ebp
je 0xffe9
callq 0xf45b
jmp 0xffee
callq 0xf639
movl %eax, %r15d
cmpl $-0x2, %eax
je 0x100b7
cmpl $-0x1, %r15d
je 0x100b0
movslq 0x8(%rbx), %rax
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rsi
movslq %r15d, %r13
testq %rax, %rax
jle 0x1006e
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rdi, %rcx
sarq $0x20, %rcx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %edx, %edx
movsd 0x924df(%rip), %xmm0    # 0xa2518
xorpd %xmm3, %xmm3
movq (%rsi,%rdx,8), %r8
movsd (%r8,%r13,8), %xmm2
ucomisd %xmm3, %xmm2
jbe 0x10064
movsd (%r8,%rcx,8), %xmm1
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x10064
movl %edx, %r12d
movapd %xmm1, %xmm0
incq %rdx
cmpq %rdx, %rax
jne 0x1003d
jmp 0x10074
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r12d
je 0x100bb
movq 0x38(%rbx), %rdx
movl %r12d, %ecx
movl %r15d, %r8d
callq 0xf774
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 0xffdb
movl $0x3, %ebp
jmp 0x100c0
xorl %ebp, %ebp
jmp 0x100c0
movl $0x2, %ebp
movq 0x38(%rbx), %rax
movslq 0xc(%rbx), %rcx
movslq 0x8(%rbx), %rdx
addq %rcx, %rdx
movsd (%rax,%rdx,8), %xmm0
movsd %xmm0, 0x8(%r14)
leaq 0x9320d(%rip), %rdi     # 0xa32ee
movb $0x1, %al
callq 0x4030
movslq (%rbx), %rdi
movl %edi, 0x18(%r14)
movl %ebp, (%r14)
leaq 0x931de(%rip), %rdx     # 0xa32d7
movl $0x8, %esi
movl $0x17, %ecx
callq 0x39210
movq %rax, 0x10(%r14)
movslq 0x8(%rbx), %rcx
testq %rcx, %rcx
jle 0x10149
movq 0x48(%rbx), %rdx
movl (%rbx), %esi
xorl %edi, %edi
movslq (%rdx,%rdi,4), %r8
cmpl %esi, %r8d
jge 0x10141
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 0x1011d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop