// File: /workspace/github_cpp_makefile_star2_O2/Hybryd[P]HyRoadGenerator/Polygon.cpp
// Function: Polygon::split()
std::pair< Polygon,Polygon > Polygon::split()
{
  std::pair<int,Point> pair = randPoint();
  int ed=pair.first; // indice de l'arete contenant le point aleatoire
  Point p=pair.second; // le point aleatoire
  Point v(poly[ed].second.x()-poly[ed].first.x(), poly[ed].second.y()-poly[ed].first.y()); // vecteur arete
  double c=-(v.x()*p.x() + v.y()*p.y()); // le c de l'equation de la droite ax + bx + c =0
  int i=0;
  bool bb=true;
  while (i<size() && bb)
  {
    if(i!=ed)
    {
      // on regarde si pour chaque arete les deux points sont du meme coté de la droite, ie meme signe
      bb = (poly[i].first.x()*v.x() + poly[i].first.y()*v.y() + c)*(poly[i].second.x()*v.x() + poly[i].second.y()*v.y() + c) > 0;
    }
    if(bb)
    {
      ++i;
    }
  }
  double denom=(v.x()*(poly[i].second.x()-poly[i].first.x()) + v.y()*(poly[i].second.y()-poly[i].first.y()));
  double t=0;
  if(denom != 0)
  {
    t=-(v.x()*poly[i].first.x() + v.y()*poly[i].first.y() + c)/denom;
  }
  else
  {
    std::cerr << " PROBLEME DENOMINATEUR NUL " << std::endl; // impossible to get here
  }
  
  
  Point intersec(poly[i].first.x() + t*(poly[i].second.x() - poly[i].first.x() ), poly[i].first.y() + t*(poly[i].second.y() - poly[i].first.y() )  );
  
  
  Polygon p1,p2;
  
  // split de l'arete de depart
  std::pair< Point,Point > ed1(p,poly[ed].second);
  std::pair< Point,Point > ed2(poly[ed].first,p);
  
  // split de l'arete d'intersection
  std::pair< Point,Point > edd1(poly[i].first,intersec);
  std::pair< Point,Point > edd2(intersec,poly[i].second);
  
  // creation du segment [intersec,p] (a inverser pour p2)
  std::pair< Point,Point > pont(intersec,p);
  
  p1.push_back(ed1);
  
  int k=ed;
  if(k==size()-1)
    k=0;
  else
    ++k;
  
  while(k<size() && k != i)
  {
    p1.push_back(poly[k]);
    ++k;
  }
  if(k==size())
  {
    k=0;
    while(k<size() && k != i)
    {
      p1.push_back(poly[k]);
      ++k;
    }
  }
  // on est arrivé en i
  p1.push_back(edd1);
  p1.push_back(pont); // p1 est defini
  

  // on commence p2
  if(k==size()-1)
    k=0;
  else
    ++k;
  
  p2.push_back(edd2);
  while(k<size() && k != ed)
  {
    p2.push_back(poly[k]);
    ++k;
  }
  if(k==size())
  {
    k=0;
    while(k<size() && k != ed)
    {
      p2.push_back(poly[k]);
      ++k;
    }
  }
  // on arrive en ed
  p2.push_back(ed2);
  // on inverse pont
  std::pair< Point,Point > tnop(pont.second,pont.first);
  p2.push_back(tnop);
  
  return std::pair< Polygon,Polygon >(p1,p2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq -0xc4(%rbp), %r15
movq %r15, %rdi
callq 0x1700
movslq (%r15), %r12
movss 0x4(%r15), %xmm9
movss 0x8(%r15), %xmm10
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %r12, %r15
shlq $0x4, %r15
movss 0x8(%rax,%r15), %xmm1
subss (%rax,%r15), %xmm1
movss 0xc(%rax,%r15), %xmm2
subss 0x4(%rax,%r15), %xmm2
movaps %xmm10, %xmm0
mulss %xmm2, %xmm0
movaps %xmm1, %xmm3
mulss %xmm9, %xmm3
addss %xmm0, %xmm3
xorps 0x27fe(%rip), %xmm3     # 0x4020
cvtss2sd %xmm3, %xmm0
subq %rax, %rcx
shrq $0x4, %rcx
xorl %edx, %edx
movb $0x1, %sil
xorps %xmm3, %xmm3
movl %edx, %r13d
cmpl %ecx, %edx
jge 0x18a8
testb $0x1, %sil
je 0x18a8
cmpl %r12d, %edx
je 0x189a
shlq $0x4, %r13
movss 0x4(%rax,%r13), %xmm4
mulss %xmm2, %xmm4
movss (%rax,%r13), %xmm5
mulss %xmm1, %xmm5
addss %xmm4, %xmm5
cvtss2sd %xmm5, %xmm4
addsd %xmm0, %xmm4
movss 0xc(%rax,%r13), %xmm5
mulss %xmm2, %xmm5
movss 0x8(%rax,%r13), %xmm6
mulss %xmm1, %xmm6
addss %xmm5, %xmm6
cvtss2sd %xmm6, %xmm5
addsd %xmm0, %xmm5
mulsd %xmm4, %xmm5
ucomisd %xmm3, %xmm5
seta %sil
movl %esi, %edi
andb $0x1, %dil
movzbl %dil, %edi
addl %edi, %edx
jmp 0x1835
movq %rbx, -0xb8(%rbp)
movq %r13, %rbx
shlq $0x4, %rbx
movss 0x8(%rax,%rbx), %xmm5
movss (%rax,%rbx), %xmm6
movss 0x4(%rax,%rbx), %xmm3
subss %xmm6, %xmm5
movss 0xc(%rax,%rbx), %xmm4
subss %xmm3, %xmm4
movaps %xmm2, %xmm8
mulss %xmm4, %xmm8
movaps %xmm1, %xmm7
mulss %xmm5, %xmm7
addss %xmm8, %xmm7
xorps %xmm8, %xmm8
ucomiss %xmm8, %xmm7
jne 0x18f6
jnp 0x191c
cvtss2sd %xmm7, %xmm7
mulss %xmm3, %xmm2
mulss %xmm6, %xmm1
addss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
xorpd 0x271a(%rip), %xmm0     # 0x4030
divsd %xmm7, %xmm0
jmp 0x1974
movq 0x56cd(%rip), %rdi      # 0x6ff0
leaq 0x272e(%rip), %rsi      # 0x4058
movss %xmm9, -0x30(%rbp)
movss %xmm10, -0x34(%rbp)
callq 0x10e0
movq %rax, %rdi
callq 0x1070
movss -0x34(%rbp), %xmm10
movss -0x30(%rbp), %xmm9
movq (%r14), %rax
movss (%rax,%rbx), %xmm6
movss 0x4(%rax,%rbx), %xmm3
movss 0x8(%rax,%rbx), %xmm5
movss 0xc(%rax,%rbx), %xmm4
subss %xmm6, %xmm5
subss %xmm3, %xmm4
xorps %xmm0, %xmm0
cvtss2sd %xmm6, %xmm1
cvtss2sd %xmm5, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvtsd2ss %xmm2, %xmm1
cvtss2sd %xmm3, %xmm2
cvtss2sd %xmm4, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
cvtsd2ss %xmm3, %xmm0
xorps %xmm2, %xmm2
leaq -0x80(%rbp), %rdi
movaps %xmm2, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm2, -0x60(%rbp)
andq $0x0, -0x50(%rbp)
leaq -0xe4(%rbp), %rsi
movss %xmm9, (%rsi)
movss %xmm10, 0x4(%rsi)
movss 0x8(%rax,%r15), %xmm2
movss %xmm2, 0x8(%rsi)
movss 0xc(%rax,%r15), %xmm2
movss %xmm2, 0xc(%rsi)
movss (%rax,%r15), %xmm2
movss %xmm2, -0xb0(%rbp)
movss 0x4(%rax,%r15), %xmm2
movss %xmm2, -0xac(%rbp)
movss %xmm9, -0xa8(%rbp)
movss %xmm10, -0xa4(%rbp)
movss (%rax,%rbx), %xmm2
movss %xmm2, -0xa0(%rbp)
movss 0x4(%rax,%rbx), %xmm2
movss %xmm2, -0x9c(%rbp)
movss %xmm1, -0x98(%rbp)
movss %xmm0, -0x94(%rbp)
movss %xmm1, -0x90(%rbp)
movss %xmm0, -0x8c(%rbp)
movss 0x8(%rax,%rbx), %xmm2
movss %xmm2, -0x88(%rbp)
movss 0xc(%rax,%rbx), %xmm2
movss %xmm2, -0x84(%rbp)
movss %xmm1, -0x44(%rbp)
movss %xmm0, -0x40(%rbp)
movss %xmm9, -0x3c(%rbp)
movss %xmm10, -0x38(%rbp)
callq 0x1d52
movq (%r14), %rsi
movq 0x8(%r14), %rax
movq %rax, %rcx
subq %rsi, %rcx
shrq $0x4, %rcx
decl %ecx
leal 0x1(%r12), %edx
xorl %edi, %edi
movq %r12, -0x30(%rbp)
cmpl %ecx, %r12d
cmovnel %edx, %edi
movslq %edi, %r12
movq %r12, %rbx
shlq $0x4, %rbx
leaq -0x80(%rbp), %r15
movq %rax, %rcx
subq %rsi, %rcx
shrq $0x4, %rcx
cmpq %r12, %r13
je 0x1ae3
movslq %ecx, %rdx
cmpq %rdx, %r12
jge 0x1ae3
addq %rbx, %rsi
movq %r15, %rdi
callq 0x1d52
incq %r12
movq (%r14), %rsi
movq 0x8(%r14), %rax
addq $0x10, %rbx
jmp 0x1ab1
cmpl %ecx, %r12d
jne 0x1b23
shlq $0x4, %r13
xorl %ebx, %ebx
leaq -0x80(%rbp), %r15
xorl %r12d, %r12d
cmpq %rbx, %r13
je 0x1b23
subq %rsi, %rax
shrq $0x4, %rax
cltq
cmpq %rax, %r12
jge 0x1b23
addq %rbx, %rsi
movq %r15, %rdi
callq 0x1d52
incq %r12
movq (%r14), %rsi
movq 0x8(%r14), %rax
addq $0x10, %rbx
jmp 0x1af5
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x1d52
leaq -0x80(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x1d52
movq (%r14), %r15
movq 0x8(%r14), %rbx
leaq -0x60(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x1d52
subq %r15, %rbx
shrq $0x4, %rbx
decl %ebx
leal 0x1(%r12), %eax
xorl %ecx, %ecx
cmpl %ebx, %r12d
cmovnel %eax, %ecx
movslq %ecx, %rbx
movq %rbx, %r12
shlq $0x4, %r12
leaq -0x60(%rbp), %r15
movq (%r14), %rsi
movq 0x8(%r14), %rax
movq %rax, %rcx
subq %rsi, %rcx
shrq $0x4, %rcx
cmpq %rbx, -0x30(%rbp)
je 0x1bae
movslq %ecx, %rdx
cmpq %rdx, %rbx
jge 0x1bae
addq %r12, %rsi
movq %r15, %rdi
callq 0x1d52
incq %rbx
addq $0x10, %r12
jmp 0x1b7b
cmpl %ecx, %ebx
jne 0x1bf1
movl -0x30(%rbp), %ebx
shlq $0x4, %rbx
xorl %r12d, %r12d
leaq -0x60(%rbp), %r15
xorl %r13d, %r13d
cmpq %r12, %rbx
je 0x1bf1
subq %rsi, %rax
shrq $0x4, %rax
cltq
cmpq %rax, %r13
jge 0x1bf1
addq %r12, %rsi
movq %r15, %rdi
callq 0x1d52
incq %r13
movq (%r14), %rsi
movq 0x8(%r14), %rax
addq $0x10, %r12
jmp 0x1bc3
leaq -0x60(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1d52
movq -0x44(%rbp), %rax
movq -0x3c(%rbp), %rcx
leaq -0xd4(%rbp), %rsi
movq %rcx, (%rsi)
movq %rax, 0x8(%rsi)
leaq -0x60(%rbp), %rdi
callq 0x1d52
movq -0xb8(%rbp), %rbx
leaq -0x80(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movq %rbx, %rdi
callq 0x1d1c
leaq -0x60(%rbp), %rdi
callq 0x1fa8
leaq -0x80(%rbp), %rdi
callq 0x1fa8
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c6a
jmp 0x1c6a
jmp 0x1c6a
jmp 0x1c6a
jmp 0x1c6a
jmp 0x1c6a
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x1fa8
leaq -0x80(%rbp), %rdi
callq 0x1fa8
movq %rbx, %rdi
callq 0x1150