// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %r8, -0x48(%rbp)
movq %rcx, %r15
movl %esi, %r13d
movslq %edx, %r14
xorl %ebx, %ebx
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %edx, %eax
movslq %esi, %rcx
imulq $0x28, %rcx, %r11
pushq $-0x2
popq %rsi
movq %r15, %rdi
cmpq %rax, %rbx
je 0x70e8
movq %rsi, %r8
movq %rdi, %r10
addq $0x2, %r8
cmpq %rcx, %r8
jge 0x6fde
movq %r10, %r12
movss (%r10), %xmm0
ucomiss 0x50(%r10), %xmm0
jne 0x6fe6
jp 0x6fe6
movss 0x4(%r12), %xmm0
ucomiss 0x54(%r12), %xmm0
jne 0x6fe6
jp 0x6fe6
leaq 0x50(%r12), %r10
movss 0x8(%r12), %xmm0
ucomiss 0x58(%r12), %xmm0
jne 0x6fe6
jnp 0x6f9b
jmp 0x6fe6
incq %rbx
addq %r11, %rdi
jmp 0x6f8c
movl %edx, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movq %rbx, -0x40(%rbp)
leaq 0x50(%r12), %rbx
leaq 0x28(%r12), %rdx
movq %r12, %rsi
movq %rbx, %rcx
callq 0x71c4
movl %eax, %ecx
leal -0x1(%r13), %eax
pushq $0x2
popq %rsi
cltd
idivl %esi
incb %cl
shll %cl, %eax
incl %eax
movq -0x48(%rbp), %rcx
movl %eax, (%rcx)
testl %r13d, %r13d
jle 0x709f
movl %r13d, %edx
imulq $0x50, %rdx, %rax
pushq $-0x2
popq %rdi
xorl %r8d, %r8d
movq %r15, %r10
movq %r12, %rsi
addq $0x2, %rdi
movq %rbx, %rcx
cmpq %r14, %rdi
jge 0x70ad
movq %r10, %r12
movss (%r10), %xmm0
ucomiss (%r10,%rax), %xmm0
jne 0x70a4
jp 0x70a4
leaq 0x2(%r8), %r9
imulq %rdx, %r8
imulq $0x28, %r8, %rsi
addq %r15, %rsi
movq %r9, %rcx
imulq %rdx, %rcx
imulq $0x28, %rcx, %rcx
addq %r15, %rcx
movss 0x4(%r12), %xmm0
ucomiss 0x4(%r12,%rax), %xmm0
jne 0x70ad
jp 0x70ad
leaq (%r12,%rax), %r10
leaq (%r12,%rax), %rbx
movss 0x8(%r12), %xmm0
ucomiss 0x8(%r12,%rax), %xmm0
movq %r9, %r8
jne 0x70ad
jnp 0x7033
jmp 0x70ad
movq %rbx, %rcx
jmp 0x70aa
addq %r12, %rax
movq %rax, %rcx
movq %r12, %rsi
leaq 0x28(%rsi), %rdx
callq 0x71c4
movl %eax, %ecx
movl -0x2c(%rbp), %eax
decl %eax
cltd
pushq $0x2
popq %rsi
idivl %esi
incb %cl
shll %cl, %eax
incl %eax
movq -0x38(%rbp), %rcx
movl %eax, (%rcx)
movq -0x40(%rbp), %rbx
cmpq %r14, %rbx
setl %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9ad1(%rip), %rdi      # 0x10bc0
callq 0x2380
jmp 0x70d3