// File: /workspace/github_c_makefile_star2_O1/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, -0x40(%rbp)
movq %rcx, %r15
movl %esi, %ebx
testl %edx, %edx
jle 0x7fd6
movslq %ebx, %rax
movl %edx, %ecx
leaq (,%rax,8), %rsi
leaq (%rsi,%rsi,4), %r11
xorl %esi, %esi
movq %r15, %rdi
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
testl %ebx, %ebx
jle 0x7fc3
movq %rdi, %r10
xorl %r8d, %r8d
movq %r10, %r12
movss (%r10), %xmm0
movb $0x1, %r10b
ucomiss 0x50(%r12), %xmm0
jne 0x7fbb
jp 0x7fbb
movss 0x4(%r12), %xmm0
ucomiss 0x54(%r12), %xmm0
jne 0x7fbb
jp 0x7fbb
movss 0x8(%r12), %xmm0
ucomiss 0x58(%r12), %xmm0
jne 0x7fbb
jp 0x7fbb
addq $0x2, %r8
leaq 0x50(%r12), %r10
cmpq %rax, %r8
jl 0x7f73
movl %r14d, %r10d
leaq 0x50(%r12), %r13
movl %r10d, %r14d
testb $0x1, %r14b
jne 0x7fdf
incq %rsi
addq %r11, %rdi
cmpq %rcx, %rsi
jne 0x7f69
jmp 0x7fdf
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r14d, %r14d
testb $0x1, %r14b
je 0x80dc
movq %rdx, -0x30(%rbp)
movq %r9, -0x38(%rbp)
leaq 0x28(%r12), %rdx
movq %r12, %rsi
movq %r13, %rcx
callq 0x81fe
leal -0x1(%rbx), %ecx
shrl $0x1f, %ecx
leal (%rbx,%rcx), %edx
decl %edx
sarl %edx
leal 0x1(%rax), %ecx
shll %cl, %edx
incl %edx
movq -0x40(%rbp), %rax
movl %edx, (%rax)
testl %ebx, %ebx
jle 0x80a3
movl %ebx, %eax
movq -0x30(%rbp), %rbx
movslq %ebx, %rcx
movq %rax, %rdx
shlq $0x4, %rdx
leaq (%rdx,%rdx,4), %rdx
xorl %esi, %esi
testl %ebx, %ebx
jle 0x808f
movq %r15, %r8
xorl %edi, %edi
movq %r8, %r12
movss (%r8), %xmm0
movb $0x1, %r8b
ucomiss (%r12,%rdx), %xmm0
jne 0x8088
jp 0x8088
movss 0x4(%r12), %xmm0
ucomiss 0x4(%r12,%rdx), %xmm0
jne 0x8088
jp 0x8088
movss 0x8(%r12), %xmm0
ucomiss 0x8(%r12,%rdx), %xmm0
jne 0x8088
jp 0x8088
addq $0x2, %rdi
leaq (%r12,%rdx), %r8
cmpq %rcx, %rdi
jl 0x8042
movl %r14d, %r8d
leaq (%r12,%rdx), %r13
movl %r8d, %r14d
testb $0x1, %r14b
jne 0x80a7
incq %rsi
addq $0x28, %r15
cmpq %rax, %rsi
jne 0x8039
jmp 0x80a7
movq -0x30(%rbp), %rbx
testb $0x1, %r14b
je 0x80dc
leaq 0x28(%r12), %rdx
movq %r12, %rsi
movq %r13, %rcx
callq 0x81fe
movl %ebx, %ecx
decl %ecx
shrl $0x1f, %ecx
leal (%rbx,%rcx), %edx
decl %edx
sarl %edx
leal 0x1(%rax), %ecx
shll %cl, %edx
incl %edx
movq -0x38(%rbp), %rax
movl %edx, (%rax)
movb $0x1, %al
jmp 0x80ea
leaq 0xaadd(%rip), %rdi      # 0x12bc0
callq 0x2350
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop