// File: /workspace/github_c_makefile_star2_O3/vlenhart[P]q3bsp/patch.cpp
// Function: PatchSurface::FindSize(int, int, LightMapVertex const*, int&, int&) const
bool PatchSurface::FindSize(int controlx,int controly,const LightMapVertex *cp,int &sizex,int &sizey) const
{
  /* Find non-coincident pairs in u direction */

  bool found=false;

  const LightMapVertex *a=0;
  const LightMapVertex *b=0;

  for (int v=0; v <controly; v++)
  {
	  for (int u=0; u < controlx; u+=2)
  	{

	    a = &cp[v * controlx + u];
	    b = &cp[v * controlx + u + 2];

      if ( a->mPos.x != b->mPos.x ||
           a->mPos.y != b->mPos.y ||
           a->mPos.z != b->mPos.z )
	    {
    		found = true;
	    	break;
	    }
   	}
  	if (found) break;
  }

  if (!found)
  {
    printf("Bad mesh control points\n");
    return false;
  }

  /* Find subdivision level in u */
  int levelx = FindLevel(a[0].mPos,a[1].mPos,b[0].mPos);
  sizex = (LEVEL_WIDTH(levelx) - 1) * ((controlx-1) / 2) + 1;


  for (int u=0; u <controlx; u++)
  {
	  for (int v=0; v < controly; v+=2)
  	{

	    a = &cp[v * controlx + u];
	    b = &cp[ ((v+2) * controlx) + u ];

      if ( a->mPos.x != b->mPos.x ||
           a->mPos.y != b->mPos.y ||
           a->mPos.z != b->mPos.z )
	    {
    		found = true;
	    	break;
	    }
   	}
  	if (found) break;
  }

  if (!found)
  {
    printf("Bad mesh control points\n");
    return false;
  }

  /* Find subdivision level in u */
  int levely = FindLevel(a[0].mPos,a[1].mPos,b[0].mPos);
  sizey = (LEVEL_WIDTH(levely) - 1) * ((controly-1) / 2) + 1;

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, -0x38(%rbp)
testl %edx, %edx
jle 0x7f7f
movq %rcx, %r15
movl %edx, %r14d
movl %esi, %r13d
movl %esi, %r12d
movl %edx, %ebx
leaq (,%r12,8), %rax
leaq (%rax,%rax,4), %rax
xorl %ecx, %ecx
movq %r15, %rdx
testl %r13d, %r13d
jle 0x7f74
xorl %edi, %edi
movq %rdx, %rsi
movss (%rsi), %xmm0
ucomiss 0x50(%rsi), %xmm0
jne 0x7f92
jp 0x7f92
movss 0x4(%rsi), %xmm0
ucomiss 0x54(%rsi), %xmm0
jne 0x7f92
jp 0x7f92
movss 0x8(%rsi), %xmm0
ucomiss 0x58(%rsi), %xmm0
jne 0x7f92
jp 0x7f92
addq $0x50, %rsi
addl $0x2, %edi
cmpl %r13d, %edi
jl 0x7f42
incq %rcx
addq %rax, %rdx
cmpq %rbx, %rcx
jne 0x7f38
leaq 0xac3a(%rip), %rdi      # 0x12bc0
callq 0x2350
xorl %eax, %eax
jmp 0x8035
movq %r9, -0x30(%rbp)
leaq 0x50(%rsi), %rcx
leaq 0x28(%rsi), %rdx
callq 0x8138
movl %r13d, %ecx
decl %ecx
shrl $0x1f, %ecx
leal (%rcx,%r13), %edx
decl %edx
sarl %edx
leal 0x1(%rax), %ecx
shll %cl, %edx
incl %edx
movq -0x38(%rbp), %rax
movl %edx, (%rax)
shlq $0x4, %r12
leaq (%r12,%r12,4), %rcx
movl $0x2, %eax
movq %r15, %rsi
movss (%r15), %xmm0
ucomiss (%r15,%rcx), %xmm0
jne 0x800a
jp 0x800a
movss 0x4(%rsi), %xmm0
ucomiss 0x4(%rsi,%rcx), %xmm0
jne 0x800a
jp 0x800a
movss 0x8(%rsi), %xmm0
ucomiss 0x8(%rsi,%rcx), %xmm0
jne 0x800a
jp 0x800a
leaq (%rsi,%rcx), %r15
leaq 0x2(%rax), %rdx
cmpq %rbx, %rax
movq %rdx, %rax
jb 0x7fcd
leaq 0x28(%rsi), %rdx
addq %rsi, %rcx
callq 0x8138
movl %r14d, %ecx
decl %ecx
shrl $0x1f, %ecx
leal (%r14,%rcx), %edx
decl %edx
sarl %edx
leal 0x1(%rax), %ecx
shll %cl, %edx
incl %edx
movq -0x30(%rbp), %rax
movl %edx, (%rax)
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq