// File: 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 %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movl $0x0, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x401098
leaq 0xc62cb(%rip), %rdi     # 0x4c8004
leaq 0xe3047(%rip), %rsi     # 0x4e4d87
callq 0x430a20
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
leaq 0xcbbdd(%rip), %rsi     # 0x4cd931
leaq -0x8(%rbp), %rdx
movb $0x0, %al
callq 0x422390
movq -0x38(%rbp), %rdi
leaq 0xcbbc7(%rip), %rsi     # 0x4cd931
leaq -0xc(%rbp), %rdx
movb $0x0, %al
callq 0x422390
movq -0x38(%rbp), %rdi
leaq 0xcbbb1(%rip), %rsi     # 0x4cd931
leaq -0x10(%rbp), %rdx
movb $0x0, %al
callq 0x422390
movq -0x38(%rbp), %rdi
leaq 0xcbb9b(%rip), %rsi     # 0x4cd931
leaq -0x14(%rbp), %rdx
movb $0x0, %al
callq 0x422390
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x401ddc
movq -0x38(%rbp), %rdi
movslq -0x3c(%rbp), %rax
leaq -0x30(%rbp), %rdx
shlq $0x2, %rax
addq %rax, %rdx
leaq 0xe355a(%rip), %rsi     # 0x4e5324
movb $0x0, %al
callq 0x422390
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x401da8
movq -0x38(%rbp), %rdi
callq 0x4305e0
leaq -0xa0(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x4021de
movq -0xc0(%rbp), %rdi
movl -0x8(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0x40227e
jmp 0x401e0c
movl -0x10(%rbp), %eax
movl %eax, -0xc4(%rbp)
testl %eax, %eax
je 0x401e5b
jmp 0x401e1b
movl -0xc4(%rbp), %eax
subl $0x1, %eax
je 0x401e75
jmp 0x401e28
movl -0xc4(%rbp), %eax
subl $0x2, %eax
je 0x401e99
jmp 0x401ec7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x402230
jmp 0x402046
movss -0x30(%rbp), %xmm0
movss -0x2c(%rbp), %xmm1
leaq -0xa0(%rbp), %rdi
callq 0x404818
jmp 0x401e73
jmp 0x401ec9
movss -0x30(%rbp), %xmm0
movss -0x2c(%rbp), %xmm1
movss -0x28(%rbp), %xmm2
movss -0x24(%rbp), %xmm3
leaq -0xa0(%rbp), %rdi
callq 0x4039f4
jmp 0x401e97
jmp 0x401ec9
movss -0x30(%rbp), %xmm0
movss -0x2c(%rbp), %xmm1
movss -0x28(%rbp), %xmm2
movss -0x24(%rbp), %xmm3
movss -0x20(%rbp), %xmm4
movss -0x1c(%rbp), %xmm5
leaq -0xa0(%rbp), %rdi
callq 0x402346
jmp 0x401ec5
jmp 0x401ec9
jmp 0x401ec9
leaq 0xc6141(%rip), %rdi     # 0x4c8011
leaq 0xc6d44(%rip), %rsi     # 0x4c8c1b
callq 0x430a20
movq %rax, -0xd0(%rbp)
jmp 0x401ee5
movq -0xd0(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, -0xd8(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x404d58
movl %eax, -0xd4(%rbp)
jmp 0x401f1a
movl -0xd8(%rbp), %eax
movl -0xd4(%rbp), %ecx
cmpl %ecx, %eax
jge 0x401f7f
movq -0x38(%rbp), %rdi
movq -0x88(%rbp), %rax
movslq -0xb0(%rbp), %rcx
movss (%rax,%rcx,8), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x88(%rbp), %rax
movslq -0xb0(%rbp), %rcx
movss 0x4(%rax,%rcx,8), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0xc60b8(%rip), %rsi     # 0x4c801c
movb $0x2, %al
callq 0x422210
movl -0xb0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb0(%rbp)
jmp 0x401efa
movq -0x38(%rbp), %rdi
callq 0x4305e0
jmp 0x401f8a
leaq 0xc6098(%rip), %rdi     # 0x4c8029
leaq 0xc6c83(%rip), %rsi     # 0x4c8c1b
callq 0x430a20
movq %rax, -0xe0(%rbp)
jmp 0x401fa6
movq -0xe0(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, -0xe8(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x404d6a
movl %eax, -0xe4(%rbp)
jmp 0x401fdb
movl -0xe8(%rbp), %eax
movl -0xe4(%rbp), %ecx
cmpl %ecx, %eax
jge 0x40201c
movq -0x38(%rbp), %rdi
movq -0x80(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0xc6031(%rip), %rsi     # 0x4c8035
movb $0x0, %al
callq 0x422210
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x401fbb
movq -0x38(%rbp), %rdi
callq 0x4305e0
jmp 0x402027
movl $0x0, -0x4(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x402230
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
movq -0xa8(%rbp), %rdi
callq 0x415db0
nopw %cs:(%rax,%rax)
nopl (%rax)