// File: /workspace/github_cpp_makefile_star2_O3/Hybryd[P]HyRoadGenerator/main.cpp
// Function: main
int main()
{
  srand(time(NULL));
  double Amin=0.05;
  double Amax=0.7;
  int iterMax=20;
  
  
  std::stack<Polygon> mustBeEmpty;
  std::vector<Polygon> mustBeFull;
  
  
  Polygon pInit;

  // DO NOT PUT NEGATIVE VALUES (for the algorithm for areas)  
  std::pair < Point,Point > e1 (Point(0,0), Point(10,0));
  std::pair < Point,Point > e2 (Point(10,0), Point(10,10));
  std::pair < Point,Point > e3 (Point(10,10), Point(0,10));
  std::pair < Point,Point > e4 (Point(0,10),Point(0,0));

  
  pInit.push_back(e1);
  pInit.push_back(e2);
  pInit.push_back(e3);
  pInit.push_back(e4);

//  std::pair < Point,Point > e1 (Point(0,0), Point(10,0));
//  std::pair < Point,Point > e2 (Point(10,0), Point(0,10));
//  std::pair < Point,Point > e3 (Point(0,10), Point(0,0));

//  
//  pInit.push_back(e1);
//  pInit.push_back(e2);
//  pInit.push_back(e3);


  mustBeEmpty.push(pInit);


  Polygon p;
  std::pair< Polygon,Polygon> pair;
  bool ok=true;
  int j=0;
  double xbar1=0;
  double ybar1=0;
  double xbar2=0;
  double ybar2=0;


  while(mustBeEmpty.size()!=0)
  {
    p=mustBeEmpty.top();
    mustBeEmpty.pop();
    if(p.area() > (1-density(p.getBary().x(),p.getBary().y()))*Amax)
    {
      ok=true;
      j=0;
      xbar1=0;
      ybar1=0;
      xbar2=0;
      ybar2=0;
      while(ok && j<iterMax)
      {
        pair = p.split();
        xbar1=pair.first.getBary().x();
        ybar1=pair.first.getBary().y();
        xbar2=pair.second.getBary().x();
        ybar2=pair.second.getBary().y();
        
        // constraints on the resulting polygons
        ok = !(pair.first.area() > (1-density(xbar1,ybar1))*Amin && pair.second.area() > (1-density(xbar2,ybar2))*Amin && pair.first.isClosed() && pair.second.isClosed() && (pair.first.isAcceptable(10)  && pair.second.isAcceptable(10)  ));
        ++j;
      }
      mustBeEmpty.push(pair.first);
      mustBeEmpty.push(pair.second);
    }
    else
    {
      mustBeFull.push_back(p);
    }
//    std::cerr << mustBeFull.size() << std::endl;
  }



  // display all the polygons
  for(int i=0;i<mustBeFull.size();++i)
    std::cout << mustBeFull[i] << std::endl << std::endl;

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
xorl %edi, %edi
callq 0x10c0
movl %eax, %edi
callq 0x10d0
xorpd %xmm0, %xmm0
leaq -0x160(%rbp), %rdi
movapd %xmm0, 0x40(%rdi)
movapd %xmm0, 0x30(%rdi)
movapd %xmm0, 0x20(%rdi)
movapd %xmm0, 0x10(%rdi)
movapd %xmm0, (%rdi)
xorl %esi, %esi
callq 0x2efa
xorpd %xmm0, %xmm0
movapd %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x13cc
movaps 0x1c4c(%rip), %xmm0     # 0x40d0
leaq -0x1a0(%rbp), %rsi
movups %xmm0, (%rsi)
movaps 0x1c4b(%rip), %xmm0     # 0x40e0
movups %xmm0, -0x190(%rbp)
movaps 0x1c4d(%rip), %xmm0     # 0x40f0
movups %xmm0, -0x180(%rbp)
movsd 0x1c4e(%rip), %xmm0     # 0x4100
movupd %xmm0, -0x170(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1ff4
leaq -0x50(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x1ff4
leaq -0x50(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x1ff4
leaq -0x50(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x1ff4
leaq -0x160(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x30de
leaq -0xd0(%rbp), %rdi
callq 0x13cc
leaq -0x108(%rbp), %rdi
callq 0x2a54
leaq -0xf0(%rbp), %r14
leaq -0xd0(%rbp), %r15
leaq -0xb8(%rbp), %r13
leaq -0x108(%rbp), %r12
movq -0x118(%rbp), %rax
movq %rax, %rcx
subq -0x138(%rbp), %rcx
sarq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
leaq (%rcx,%rcx,4), %rdx
leaq (%rcx,%rdx,4), %rdx
movq -0x140(%rbp), %rdi
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rcx
movq %rsi, %r8
subq %rcx, %r8
sarq $0x3, %r8
movabsq $-0x5555555555555555, %r9 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r9, %r8
subq -0x150(%rbp), %rdi
addq %rdx, %r8
sarq $0x3, %rdi
movabsq $0x5555555555555555, %rdx # imm = 0x5555555555555555
imulq %rdx, %rdi
cmpq %rdi, %r8
je 0x288d
cmpq %rcx, %rsi
jne 0x25bf
movq -0x8(%rax), %rsi
movl $0x1f8, %eax            # imm = 0x1F8
addq %rax, %rsi
addq $-0x18, %rsi
movq %r15, %rdi
callq 0x2b7c
leaq -0x160(%rbp), %rdi
callq 0x337a
movq %r15, %rdi
callq 0x1574
movsd %xmm0, -0x30(%rbp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x1782
movss -0xb8(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
leaq -0xd8(%rbp), %rdi
movq %r15, %rsi
callq 0x1782
xorps %xmm0, %xmm0
cvtss2sd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd -0xd4(%rbp), %xmm1
movsd 0x1a6a(%rip), %xmm2     # 0x4090
addsd %xmm2, %xmm0
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
divsd 0x1a56(%rip), %xmm0     # 0x4098
callq 0x1180
mulsd 0x1a59(%rip), %xmm0     # 0x40a8
addsd 0x1a59(%rip), %xmm0     # 0x40b0
mulsd 0x1a59(%rip), %xmm0     # 0x40b8
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x287c
xorl %ebx, %ebx
movq %r13, %rdi
movq %r15, %rsi
callq 0x1894
movq %r12, %rdi
movq %r13, %rsi
callq 0x2b7c
movq %r14, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2b7c
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0x26b0
movq -0x90(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x26cb
movq -0xa8(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %r13, %rdi
movq %r12, %rsi
callq 0x1782
xorps %xmm0, %xmm0
cvtss2sd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x1782
xorps %xmm0, %xmm0
cvtss2sd -0xb4(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x1782
xorps %xmm0, %xmm0
cvtss2sd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x1782
xorps %xmm0, %xmm0
cvtss2sd -0xb4(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movq %r12, %rdi
callq 0x1574
movsd %xmm0, -0x88(%rbp)
movsd 0x1941(%rip), %xmm1     # 0x4090
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm2
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
divsd 0x1923(%rip), %xmm0     # 0x4098
callq 0x1180
mulsd 0x1926(%rip), %xmm0     # 0x40a8
addsd 0x1926(%rip), %xmm0     # 0x40b0
mulsd 0x192e(%rip), %xmm0     # 0x40c0
movsd -0x88(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x2845
movq %r14, %rdi
callq 0x1574
movsd %xmm0, -0x30(%rbp)
movsd 0x18d7(%rip), %xmm1     # 0x4090
movsd -0x80(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd -0x78(%rbp), %xmm2
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
divsd 0x18b9(%rip), %xmm0     # 0x4098
callq 0x1180
mulsd 0x18bc(%rip), %xmm0     # 0x40a8
addsd 0x18bc(%rip), %xmm0     # 0x40b0
mulsd 0x18c4(%rip), %xmm0     # 0x40c0
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x2845
movq %r12, %rdi
callq 0x16b4
testb %al, %al
je 0x2845
movq %r14, %rdi
callq 0x16b4
testb %al, %al
je 0x2845
movq %r12, %rdi
movsd 0x189e(%rip), %xmm0     # 0x40c8
callq 0x1736
testb %al, %al
je 0x2845
movq %r14, %rdi
movsd 0x188a(%rip), %xmm0     # 0x40c8
callq 0x1736
jmp 0x2847
xorl %eax, %eax
testb %al, %al
jne 0x2859
leal 0x1(%rbx), %eax
cmpl $0x12, %ebx
movl %eax, %ebx
jbe 0x2670
leaq -0x160(%rbp), %rdi
movq %r12, %rsi
callq 0x30de
leaq -0x160(%rbp), %rdi
movq %r14, %rsi
callq 0x30de
jmp 0x2537
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0x2ad0
jmp 0x2537
movq -0x70(%rbp), %rsi
cmpq %rsi, -0x68(%rbp)
je 0x2934
xorl %r15d, %r15d
movq 0x372b(%rip), %rbx      # 0x5fd0
xorl %r12d, %r12d
addq %r15, %rsi
movq %rbx, %rdi
callq 0x1ea1
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
incq %r12
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rax
subq %rsi, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %r15
cmpq %r12, %rax
ja 0x28a8
movq -0xf0(%rbp), %rdi
testq %rdi, %rdi
je 0x294f
movq -0xe0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq -0x108(%rbp), %rdi
testq %rdi, %rdi
je 0x296a
movq -0xf8(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x2985
movq -0xc0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x299a
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq -0x70(%rbp), %rdi
callq 0x2b0c
leaq -0x160(%rbp), %rdi
callq 0x2d30
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2a06
jmp 0x29cf
movq %rax, %rbx
jmp 0x2a36
movq %rax, %rbx
jmp 0x2a21
jmp 0x29e6
jmp 0x29e6
jmp 0x29e6
jmp 0x29e6
jmp 0x29e6
jmp 0x29e6
jmp 0x29e6
jmp 0x29e6
jmp 0x29e6
movq %rax, %rbx
jmp 0x29fa
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x2a90
leaq -0x108(%rbp), %rdi
callq 0x2a90
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x2a21
movq -0xc0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x2a36
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq -0x70(%rbp), %rdi
callq 0x2b0c
leaq -0x160(%rbp), %rdi
callq 0x2d30
movq %rbx, %rdi
callq 0x1170
nop