// File: /workspace/github_cpp_makefile_star2_O3/YiweiMao[P]tessDX/src/tess_exp.cpp
// Function: main
int main(void) { //int argc, char** argv) {

    int partitionScheme;
    int outputPrimitive;
    int domain;
    int numTFs;
    float tfs[6] = {0};

    FILE *fp;
    fp = fopen("settings.txt", "r");
    fscanf(fp, "%d", &partitionScheme);
    fscanf(fp, "%d", &outputPrimitive);
    fscanf(fp, "%d", &domain);
    fscanf(fp, "%d", &numTFs);

    for (int i=0; i <numTFs; i++) {
        fscanf(fp, "%f", &tfs[i]);
    }
    fclose(fp);

    CHWTessellator hwTess;
    hwTess.Init((D3D11_TESSELLATOR_PARTITIONING)partitionScheme,(D3D11_TESSELLATOR_OUTPUT_PRIMITIVE)outputPrimitive);

    switch (domain)
    {
    case 0:
        hwTess.TessellateIsoLineDomain(tfs[0],tfs[1]);
        break;
    case 1:
        hwTess.TessellateTriDomain(tfs[0],tfs[1],tfs[2],tfs[3]);
        break;
    case 2:
        hwTess.TessellateQuadDomain(tfs[0],tfs[1],tfs[2],tfs[3],tfs[4],tfs[5]);
        break;
    default:
        break;
    }

    fp = fopen("points.csv", "w");
    //printf("get point count is %d\n",hwTess.GetPointCount());
    for(int i=0;i<hwTess.GetPointCount();i++){
        //printf("%.2f,%.2f\t",hwTess.m_Point[i].u,hwTess.m_Point[i].v);
        fprintf(fp,"%.16f,%.16f\n",hwTess.m_Point[i].u,hwTess.m_Point[i].v);
    }
    fclose(fp);

    fp = fopen("indexes.csv", "w");
    //printf("\nget index count is %d\n",hwTess.GetIndexCount());
    for(int i=0;i<hwTess.GetIndexCount();i++){
        //printf("%d\t",hwTess.m_Index[i]);
        fprintf(fp,"%d\n",hwTess.m_Index[i]);
    }
    fclose(fp);

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x88, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0xc62d7(%rip), %rdi     # 0x4c8004
leaq 0xe3053(%rip), %rsi     # 0x4e4d87
callq 0x430920
movq %rax, %rbx
leaq 0xcbbee(%rip), %r14     # 0x4cd931
leaq 0x24(%rsp), %rdx
movq %rax, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x422290
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x422290
leaq 0x1c(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x422290
leaq 0x18(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x422290
cmpl $0x0, (%r15)
jle 0x401dc2
movq %rsp, %r14
leaq 0xe3586(%rip), %r15     # 0x4e5324
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x422290
incq %r12
movslq 0x18(%rsp), %rax
addq $0x4, %r14
cmpq %rax, %r12
jl 0x401da1
movq %rbx, %rdi
callq 0x4304e0
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x4020de
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
movq %rbx, %rdi
callq 0x40217e
movl 0x1c(%rsp), %eax
testl %eax, %eax
je 0x401e4b
cmpl $0x1, %eax
je 0x401e28
cmpl $0x2, %eax
jne 0x401e60
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm2
movss 0xc(%rsp), %xmm3
movss 0x10(%rsp), %xmm4
movss 0x14(%rsp), %xmm5
leaq 0x28(%rsp), %rdi
callq 0x402246
jmp 0x401e60
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm2
movss 0xc(%rsp), %xmm3
leaq 0x28(%rsp), %rdi
callq 0x4038f4
jmp 0x401e60
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
leaq 0x28(%rsp), %rdi
callq 0x404718
leaq 0xc61aa(%rip), %rdi     # 0x4c8011
leaq 0xc6dad(%rip), %rsi     # 0x4c8c1b
callq 0x430920
movq %rax, %rbx
xorl %r12d, %r12d
leaq 0x28(%rsp), %r14
leaq 0xc6197(%rip), %r15     # 0x4c801c
movq %r14, %rdi
callq 0x404c58
cltq
cmpq %rax, %r12
jge 0x401ebe
movq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,8), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rax,%r12,8), %xmm1
movq %rbx, %rdi
movq %r15, %rsi
movb $0x2, %al
callq 0x422110
incq %r12
jmp 0x401e85
movq %rbx, %rdi
callq 0x4304e0
leaq 0xc615c(%rip), %rdi     # 0x4c8029
leaq 0xc6d47(%rip), %rsi     # 0x4c8c1b
callq 0x430920
movq %rax, %rbx
leaq 0x28(%rsp), %r14
leaq 0xc614d(%rip), %r15     # 0x4c8035
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x404c6a
cltq
cmpq %rax, %r12
jge 0x401f15
movq 0x48(%rsp), %rax
movl (%rax,%r12,4), %edx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x422110
incq %r12
jmp 0x401eeb
movq %rbx, %rdi
callq 0x4304e0
leaq 0x28(%rsp), %rdi
callq 0x402130
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x401f3c
jmp 0x401f3c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x402130
movq %rbx, %rdi
callq 0x415cb0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)