// File: /workspace/github_c_makefile_star2_O1/vlenhart[P]q3bsp/patch.cpp
// Function: PatchSurface::PatchSurface(LightMapVertex const*, int, int, int)
PatchSurface::PatchSurface(const LightMapVertex *cp,
                           int npoints,
                           int controlx,
                           int controly)
{
  int sizex,sizey;
  FindSize(controlx,controly,cp,sizex,sizey);

  int size = sizex*sizey;
  mPoints = new LightMapVertex[size];

  int stepx = (sizex-1) / (controlx-1);
  int stepy = (sizey-1) / (controly-1);
  const LightMapVertex *control = cp;

  for (int y=0; y<sizey; y+=stepy)
  {
    for (int x=0; x<sizex; x+=stepx)
    {
      int p = y*sizex+x;
      mPoints[p] = *control++;
    }
  }


  FillPatch(controlx,controly,sizex,sizey,mPoints);

  mCount = (sizex-1)*(sizey-1)*6;

  if ( 1 )
  {
    mIndices = new unsigned short[mCount];
    unsigned short *foo = mIndices;
    for (int y=0; y < sizey-1; ++y)
    {
    	for (int x = 0; x < sizex-1; ++x)
    	{
        *foo++ = y*sizex+x;
        *foo++ = (y+1)*sizex+x;
        *foo++ = y*sizex+x+1;

        *foo++ = y*sizex+x+1;
        *foo++ = (y+1)*sizex+x;
        *foo++ = (y+1)*sizex+x+1;
    	}
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %edx
movq %rsi, %r15
movq %rdi, %r12
leaq -0x50(%rbp), %rbx
leaq -0x4c(%rbp), %r14
movq %rcx, -0x38(%rbp)
movl %ecx, %esi
movq %rdx, -0x40(%rbp)
movq %r15, %rcx
movq %rbx, %r8
movq %r14, %r9
callq 0x7f28
movl (%rbx), %ebx
movslq (%r14), %r13
movl %r13d, %eax
imull %ebx, %eax
cltq
movl $0x28, %ecx
mulq %rcx
movq $-0x1, %rcx
cmovoq %rcx, %rax
movq %rax, %rdi
callq 0x2040
leal -0x1(%rbx), %r14d
leal -0x1(%r13), %ecx
movl %ecx, -0x2c(%rbp)
movq %rax, 0x8(%r12)
movq %r13, -0x48(%rbp)
testq %r13, %r13
jle 0x7e6d
movslq %ebx, %rsi
movq -0x40(%rbp), %rax
leal -0x1(%rax), %ecx
movl -0x2c(%rbp), %eax
cltd
idivl %ecx
movl %eax, %ecx
movq -0x38(%rbp), %rax
leal -0x1(%rax), %edi
movl %r14d, %eax
cltd
idivl %edi
cltq
movslq %ecx, %rcx
movq %rsi, %rdx
imulq %rcx, %rdx
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %rdx
leaq (,%rax,8), %rdi
leaq (%rdi,%rdi,4), %rdi
movl $0x24, %r8d
xorl %r9d, %r9d
testl %ebx, %ebx
jle 0x7e5d
movq %r8, %r10
xorl %r11d, %r11d
movq 0x8(%r12), %r13
movss (%r15), %xmm0
movss %xmm0, -0x24(%r13,%r10)
movss 0x4(%r15), %xmm0
movss %xmm0, -0x20(%r13,%r10)
movss 0x8(%r15), %xmm0
movss %xmm0, -0x1c(%r13,%r10)
movups 0xc(%r15), %xmm0
movups %xmm0, -0x18(%r13,%r10)
movss 0x1c(%r15), %xmm0
movss %xmm0, -0x8(%r13,%r10)
movss 0x20(%r15), %xmm0
movss %xmm0, -0x4(%r13,%r10)
movss 0x24(%r15), %xmm0
addq $0x28, %r15
movss %xmm0, (%r13,%r10)
addq %rax, %r11
addq %rdi, %r10
cmpq %rsi, %r11
jl 0x7df1
addq %rcx, %r9
addq %rdx, %r8
cmpq -0x48(%rbp), %r9
jl 0x7de7
movq 0x8(%r12), %r9
movq %r12, %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl %ebx, %ecx
movq -0x48(%rbp), %r13
movl %r13d, %r8d
callq 0x80fa
movl -0x2c(%rbp), %r15d
movl %r15d, %eax
imull %r14d, %eax
leal (%rax,%rax), %ecx
leal (%rcx,%rcx,2), %ecx
movl %ecx, (%r12)
movslq %ecx, %rdi
addq %rdi, %rdi
testl %eax, %eax
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x2040
movq %rax, 0x10(%r12)
cmpl $0x2, %r13d
jl 0x7f19
xorl %ecx, %ecx
movl %ebx, %edx
xorl %esi, %esi
cmpl $0x2, %ebx
jl 0x7f0e
xorl %edi, %edi
leal (%rcx,%rdi), %r8d
movw %r8w, (%rax)
leal (%rdx,%rdi), %r8d
movw %r8w, 0x2(%rax)
leal (%rcx,%rdi), %r9d
incl %r9d
movw %r9w, 0x4(%rax)
movw %r9w, 0x6(%rax)
movw %r8w, 0x8(%rax)
leal (%rdx,%rdi), %r8d
incl %r8d
movw %r8w, 0xa(%rax)
addq $0xc, %rax
incl %edi
cmpl %edi, %r14d
jne 0x7ed0
incl %esi
addl %ebx, %edx
addl %ebx, %ecx
cmpl %r15d, %esi
jne 0x7ec9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq