// File: /workspace/github_cpp_makefile_star2_O3/WShabti-Team[P]WShabtiPict/wshabtilib/case-test-generator/case-test-generator.cpp
// Function: test_generator(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void test_generator(int k_degree, string input_file, string output_file)
{
//----------------------------------------------------------------------------------------------------------------------------------------------------
  	
  	//FILE CONFIGURATION

  	std::ofstream test_case_output_file;

  	test_case_output_file.open(output_file, std::ios_base::out);

//----------------------------------------------------------------------------------------------------------------------------------------------------
  	
  	//PICT CONFIGURATION

    PICT_RET_CODE ret = PICT_SUCCESS;
    PICT_HANDLE task = PictCreateTask();
    PICT_HANDLE model = PictCreateModel();
    PictSetRootModel( task, model );

//----------------------------------------------------------------------------------------------------------------------------------------------------

    //CREATE MODEL

    vector<vector<string>> params_matrix;
    vector<vector<string>> constraints_matrix;
    
    input_parser(input_file, params_matrix, constraints_matrix);

    int number_of_parameters = params_matrix.size();
    PICT_HANDLE* parameters = new PICT_HANDLE[number_of_parameters];

    //Iterate on number of lines to get parameters 
    for(int index = 0; index<number_of_parameters; index++)
    {
        parameters[index] = PictAddParameter( model, params_matrix[index].size(), k_degree );
    }

//----------------------------------------------------------------------------------------------------------------------------------------------------
    
    //ADD CONSTRAINTS

    int number_of_constraints = constraints_matrix.size();
    PICT_EXCLUSION_ITEM** constraints = new PICT_EXCLUSION_ITEM*[number_of_constraints];

    int exclusions_count;
    int number_of_exclusion;
    for(int i = 0; i<number_of_constraints; i++)
    {
        exclusions_count = constraints_matrix[i].size();
    
        for(int j = 0; j < constraints_matrix[i].size(); j++)
        {
            if(constraints_matrix[i][j].compare("*") == 0 )
            {
                exclusions_count--;
            }
        }
        constraints[i] = new PICT_EXCLUSION_ITEM[exclusions_count];

        number_of_exclusion = exclusions_count;        

        for(int j = 0; j < constraints_matrix[i].size(); j++)
        {
            if( constraints_matrix[i][j].compare("*") != 0 )
            {
                constraints[i][exclusions_count-1].Parameter = parameters[j]; 
                constraints[i][exclusions_count-1].ValueIndex = position_in_vector(params_matrix[j], constraints_matrix[i][j]);                //params_matrix[j] -> vettore
                exclusions_count--; 
            }
        }
    
        PictAddExclusion( task, constraints[i], number_of_exclusion);
    }

//----------------------------------------------------------------------------------------------------------------------------------------------------

    //GENERATE RESULTS
    ret = PictGenerate( task );
    PICT_RESULT_ROW row = PictAllocateResultBuffer( task );
    size_t paramCount = PictGetTotalParameterCount( task );
    PictResetResultFetching( task );

//----------------------------------------------------------------------------------------------------------------------------------------------------

    //SAVE RESULTS 
    bool keep_reading = PictGetNextResultRow( task, row );
    while(keep_reading)
    {   
        for( size_t index = 0; index < paramCount-1; ++index )
        {
        	test_case_output_file << params_matrix[index][row[index]] << ",";
        }
        test_case_output_file << params_matrix[paramCount-1][row[paramCount-1]];

        keep_reading = PictGetNextResultRow( task, row );

        if(keep_reading == true)
        {
            test_case_output_file << endl;
        }
    }

//----------------------------------------------------------------------------------------------------------------------------------------------------

    //PICT DELETE 

    PictFreeResultBuffer( row );
    if( model != NULL )    {    PictDeleteModel( model ); }
    if( task != NULL )     {    PictDeleteTask( task );   }

//----------------------------------------------------------------------------------------------------------------------------------------------------

    //FILE CLOSING
    test_case_output_file.close();

//----------------------------------------------------------------------------------------------------------------------------------------------------
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdx, %r14
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xd8(%rsp), %r15
movq %r15, %rdi
callq 0x5670
movq %r15, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x51d0
callq 0xf41c
movq %rax, %r14
xorl %edi, %edi
callq 0xf7a2
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
callq 0xf458
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movq %rax, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
leaq 0xb0(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %rdi
callq 0x757e
leaq 0xa0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x10c1c
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x21a3a
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x53e0
movq %r14, 0x10(%rsp)
movq 0x48(%rsp), %r14
subq 0x40(%rsp), %r14
sarq $0x3, %r14
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rbx, %r14
movq %r14, %rax
shlq $0x20, %rax
movq %rax, %rcx
sarq $0x1d, %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x5030
movq %rax, 0x60(%rsp)
testl %r14d, %r14d
jle 0x21ac9
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movl $0x1, %r15d
xorl %r12d, %r12d
movq 0x40(%rsp), %rax
movq (%rax,%r15,8), %rsi
subq -0x8(%rax,%r15,8), %rsi
sarq $0x5, %rsi
movq %r13, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0xf84f
movq 0x60(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
addq $0x3, %r15
cmpq %r12, %r14
jne 0x21a96
movq %r13, 0x88(%rsp)
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
sarq $0x3, %rax
imulq %rbx, %rax
movq %rax, 0x8(%rsp)
testl %eax, %eax
jle 0x21cd5
movq 0x8(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x8(%rsp)
xorl %eax, %eax
leaq 0x61fc(%rip), %rbp      # 0x27d04
movq 0x20(%rsp), %r15
movq %rax, 0x90(%rsp)
leaq (%rax,%rax,2), %rax
movq (%r15,%rax,8), %rdi
movq %rax, (%rsp)
movq 0x8(%r15,%rax,8), %rax
movq %rax, %rbx
subq %rdi, %rbx
shrq $0x5, %rbx
cmpq %rdi, %rax
je 0x21b71
xorl %r14d, %r14d
xorl %r13d, %r13d
movq (%rsp), %r12
addq %r14, %rdi
movq %rbp, %rsi
callq 0x5120
cmpl $0x1, %eax
sbbl $0x0, %ebx
incq %r13
movq 0x20(%rsp), %r15
movq (%r15,%r12,8), %rdi
movq 0x8(%r15,%r12,8), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r14
cmpq %r13, %rax
ja 0x21b3f
movslq %ebx, %rax
movq %rax, %rdi
shlq $0x4, %rdi
movq %rax, 0x98(%rsp)
testl %eax, %eax
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x5030
movq %rax, 0x18(%rsp)
movq (%rsp), %r14
movq (%r15,%r14,8), %rdi
cmpq %rdi, 0x8(%r15,%r14,8)
je 0x21ca1
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r13d, %r13d
addq %rbp, %rdi
leaq 0x6145(%rip), %rsi      # 0x27d04
callq 0x5120
testl %eax, %eax
je 0x21c78
movq 0x60(%rsp), %rax
movq (%rax,%r13,8), %rax
movslq %ebx, %r14
decq %r14
shlq $0x4, %r14
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r14)
movq 0x40(%rsp), %rsi
addq %r15, %rsi
leaq 0xc0(%rsp), %rdi
callq 0x18134
movq 0x20(%rsp), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rax
leaq 0x78(%rsp), %rcx
movq %rcx, 0x68(%rsp)
movq (%rax,%rbp), %rsi
movq 0x8(%rax,%rbp), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x757e
leaq 0xc0(%rsp), %rdi
movq %r12, %rsi
callq 0x106fd
cltq
movq 0x18(%rsp), %rcx
movq %rax, 0x8(%rcx,%r14)
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x21c65
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x53e0
decl %ebx
leaq 0xc0(%rsp), %rdi
callq 0x107a2
movq (%rsp), %r14
incq %r13
movq 0x20(%rsp), %rax
movq (%rax,%r14,8), %rdi
movq 0x8(%rax,%r14,8), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %rbp
addq $0x18, %r15
cmpq %r13, %rax
ja 0x21bb5
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x98(%rsp), %rdx
callq 0xf469
movq 0x90(%rsp), %rax
incq %rax
cmpq 0x8(%rsp), %rax
leaq 0x6035(%rip), %rbp      # 0x27d04
jne 0x21b08
movq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0xf613
movq %r12, %rdi
callq 0xf704
movq %rax, %r15
movq %r12, %rdi
callq 0xfa8a
movq %rax, (%rsp)
movq %r12, %rdi
callq 0xf719
movq %r12, %rdi
movq %r15, %rsi
callq 0xf71e
testq %rax, %rax
je 0x21df3
movq (%rsp), %r14
decq %r14
leaq (%r14,%r14,2), %r13
leaq 0x5eb3(%rip), %rbx      # 0x27bda
testq %r14, %r14
je 0x21d74
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x40(%rsp), %rax
movq (%r15,%r12,8), %rcx
movq (%rax,%rbp), %rax
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
leaq 0xd8(%rsp), %rdi
callq 0x5490
movl $0x1, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5490
incq %r12
addq $0x18, %rbp
cmpq %r12, %r14
jne 0x21d31
movq 0x40(%rsp), %rax
movq (%rsp), %rcx
movq -0x8(%r15,%rcx,8), %rcx
movq (%rax,%r13,8), %rax
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
leaq 0xd8(%rsp), %rdi
callq 0x5490
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xf71e
testq %rax, %rax
je 0x21df3
movq 0xd8(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0xd8(%rsp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
leaq 0xd8(%rsp), %rdi
callq 0x5040
movq %rax, %rdi
callq 0x52d0
jmp 0x21d27
movq %r15, %rdi
callq 0xf714
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x21e0d
callq 0xfaf4
testq %r12, %r12
je 0x21e1a
movq %r12, %rdi
callq 0xf783
leaq 0xd8(%rsp), %rdi
callq 0x5590
leaq 0x20(%rsp), %rdi
callq 0x21f24
leaq 0x40(%rsp), %rdi
callq 0x21f24
movq 0x13146(%rip), %rax     # 0x34f88
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0xe0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0xd8(%rsp,%rcx)
callq 0x5340
leaq 0x1d0(%rsp), %rdi
callq 0x5150
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x21ef7
jmp 0x21ef7
jmp 0x21ef7
movq %rax, %r14
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x21efa
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x53e0
jmp 0x21efa
jmp 0x21ef7
jmp 0x21eb5
jmp 0x21eb5
jmp 0x21ef7
movq %rax, %r14
jmp 0x21f0e
jmp 0x21ef7
jmp 0x21ef7
jmp 0x21ef7
jmp 0x21ef7
movq %rax, %r14
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x21ee8
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x53e0
jmp 0x21ee8
jmp 0x21ef7
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
callq 0x107a2
jmp 0x21efa
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x21f24
leaq 0x40(%rsp), %rdi
callq 0x21f24
leaq 0xd8(%rsp), %rdi
callq 0x55d0
movq %r14, %rdi
callq 0x56a0
nop