// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movl %r8d, %edx
movq %rdx, -0x38(%rbp)
movl %ecx, %r14d
movq %rsi, %rbx
movq %rdi, %r12
leaq -0x90(%rbp), %r15
leaq -0x8c(%rbp), %r13
movl %ecx, %esi
movq %rbx, %rcx
movq %r15, %r8
movq %r13, %r9
callq 0x6f54
movl (%r15), %r15d
movslq (%r13), %r13
movl %r13d, %eax
imull %r15d, %eax
cltq
pushq $0x28
popq %rcx
mulq %rcx
pushq $-0x1
popq %rcx
cmovoq %rcx, %rax
movq %rax, %rdi
callq 0x2040
movq %r12, -0x48(%rbp)
movq %rax, 0x8(%r12)
leal -0x1(%r15), %eax
movq %r14, -0x50(%rbp)
leal -0x1(%r14), %ecx
movl %eax, -0x30(%rbp)
cltd
idivl %ecx
movl %eax, %ecx
movq %r13, -0x40(%rbp)
leal -0x1(%r13), %eax
movq -0x38(%rbp), %rdx
leal -0x1(%rdx), %esi
movl %eax, -0x2c(%rbp)
cltd
idivl %esi
movslq %ecx, %rcx
movq %r15, -0x58(%rbp)
movslq %r15d, %rdx
movslq %eax, %rsi
movq %rdx, -0x88(%rbp)
movq %rdx, %rax
movq %rsi, -0x68(%rbp)
imulq %rsi, %rax
imulq $0x28, %rax, %rax
movq %rax, -0x60(%rbp)
movq %rcx, %r14
imulq $0x28, %rcx, %rax
movq %rax, -0x80(%rbp)
xorl %r12d, %r12d
xorl %eax, %eax
cmpq -0x40(%rbp), %rax
jge 0x6e90
movq %rax, -0x70(%rbp)
movq %r12, -0x78(%rbp)
xorl %r13d, %r13d
cmpq -0x88(%rbp), %r13
jge 0x6e7e
leaq 0x28(%rbx), %r15
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x750c
addq %r14, %r13
addq -0x80(%rbp), %r12
movq %r15, %rbx
jmp 0x6e52
movq -0x70(%rbp), %rax
addq -0x68(%rbp), %rax
movq -0x78(%rbp), %r12
addq -0x60(%rbp), %r12
jmp 0x6e41
movq -0x48(%rbp), %r12
movq 0x8(%r12), %r9
movq %r12, %rdi
movq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x58(%rbp), %rbx
movl %ebx, %ecx
movq -0x40(%rbp), %r8
callq 0x70f6
movl -0x30(%rbp), %r14d
movl %r14d, %eax
movl -0x2c(%rbp), %r15d
imull %r15d, %eax
imull $0x6, %eax, %ecx
movl %ecx, (%r12)
movslq %ecx, %rdi
addq %rdi, %rdi
testl %eax, %eax
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2040
movq %rax, 0x10(%r12)
xorl %ecx, %ecx
testl %r14d, %r14d
cmovlel %ecx, %r14d
testl %r15d, %r15d
cmovlel %ecx, %r15d
movl %ebx, %edx
xorl %esi, %esi
cmpl %r15d, %esi
je 0x6f45
incl %esi
xorl %edi, %edi
cmpl %edi, %r14d
je 0x6f3f
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
jmp 0x6eff
addl %ebx, %ecx
addl %ebx, %edx
jmp 0x6ef6
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq