// File: /workspace/github_cpp_makefile_star2_O1/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 $0x2c8, %rsp            # imm = 0x2C8
movq %rdx, %r14
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
callq 0x5670
movq %r15, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x51d0
callq 0xf5f0
movq %rax, %r13
xorl %edi, %edi
callq 0xf974
movq %rax, %r14
movq %r13, %rdi
movq %rax, %rsi
callq 0xf62c
movq %r14, 0x48(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0xa0(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %rdi
callq 0x7622
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x10e2c
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x21c2f
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x53e0
movq 0x38(%rsp), %r14
subq 0x30(%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, 0x50(%rsp)
testl %r14d, %r14d
jle 0x21cbb
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movl $0x1, %r15d
xorl %r12d, %r12d
movq 0x30(%rsp), %rax
movq (%rax,%r15,8), %rsi
subq -0x8(%rax,%r15,8), %rsi
sarq $0x5, %rsi
movq 0x48(%rsp), %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0xfa21
movq 0x50(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
addq $0x3, %r15
cmpq %r12, %r14
jne 0x21c86
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x3, %rax
imulq %rbx, %rax
movq %rax, 0x28(%rsp)
testl %eax, %eax
jle 0x21ecc
movq 0x28(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x28(%rsp)
xorl %ecx, %ecx
leaq 0x6012(%rip), %rbp      # 0x27d04
movq %r13, 0x78(%rsp)
movq 0x10(%rsp), %rax
movq %rcx, 0x80(%rsp)
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdi
movq %rcx, (%rsp)
movq 0x8(%rax,%rcx,8), %rax
movq %rax, %rbx
subq %rdi, %rbx
shrq $0x5, %rbx
cmpq %rdi, %rax
je 0x21d60
xorl %r14d, %r14d
xorl %r15d, %r15d
movq (%rsp), %r12
addq %r14, %rdi
movq %rbp, %rsi
callq 0x5120
cmpl $0x1, %eax
sbbl $0x0, %ebx
incq %r15
movq 0x10(%rsp), %rax
movq (%rax,%r12,8), %rdi
movq 0x8(%rax,%r12,8), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r14
cmpq %r15, %rax
ja 0x21d2e
movslq %ebx, %rax
movq %rax, %rdi
shlq $0x4, %rdi
movq %rax, 0x88(%rsp)
testl %eax, %eax
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x5030
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq (%rsp), %r14
movq (%rax,%r14,8), %rdi
cmpq %rdi, 0x8(%rax,%r14,8)
je 0x21e95
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r13d, %r13d
addq %rbp, %rdi
leaq 0x5f51(%rip), %rsi      # 0x27d04
callq 0x5120
testl %eax, %eax
je 0x21e6c
movq 0x50(%rsp), %rax
movq (%rax,%r13,8), %rax
movslq %ebx, %r14
decq %r14
shlq $0x4, %r14
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r14)
movq 0x30(%rsp), %rsi
addq %r15, %rsi
leaq 0xb0(%rsp), %rdi
callq 0x183be
movq 0x10(%rsp), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rax
leaq 0x68(%rsp), %rcx
movq %rcx, 0x58(%rsp)
movq (%rax,%rbp), %rsi
movq 0x8(%rax,%rbp), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %r12
movq %r12, %rdi
callq 0x7622
leaq 0xb0(%rsp), %rdi
movq %r12, %rsi
callq 0x108dd
cltq
movq 0x8(%rsp), %rcx
movq %rax, 0x8(%rcx,%r14)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x21e59
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x53e0
decl %ebx
leaq 0xb0(%rsp), %rdi
callq 0x10982
movq (%rsp), %r14
incq %r13
movq 0x10(%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 0x21da9
movq 0x78(%rsp), %r13
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq 0x88(%rsp), %rdx
callq 0xf63d
movq 0x80(%rsp), %rcx
incq %rcx
cmpq 0x28(%rsp), %rcx
leaq 0x5e3e(%rip), %rbp      # 0x27d04
jne 0x21cf7
movq %r13, %rdi
callq 0xf7e7
movq %r13, %rdi
callq 0xf8d8
movq %rax, %r15
movq %r13, %rdi
callq 0xfc5c
movq %rax, (%rsp)
movq %r13, %rdi
callq 0xf8ed
movq %r13, %rdi
movq %r15, %rsi
callq 0xf8f2
movq %r13, %rbp
testq %rax, %rax
je 0x21ffc
movq (%rsp), %r13
decq %r13
leaq (,%r13,2), %rax
addq %r13, %rax
movq %rax, 0x8(%rsp)
leaq 0x5cb2(%rip), %rbx      # 0x27bda
testq %r13, %r13
je 0x21f76
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x30(%rsp), %rax
movq (%r15,%r12,8), %rcx
movq (%rax,%r14), %rax
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
leaq 0xc8(%rsp), %rdi
callq 0x5490
movl $0x1, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5490
incq %r12
addq $0x18, %r14
cmpq %r12, %r13
jne 0x21f33
movq 0x30(%rsp), %rax
movq (%rsp), %rcx
movq -0x8(%r15,%rcx,8), %rcx
movq 0x8(%rsp), %rdx
movq (%rax,%rdx,8), %rax
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
leaq 0xc8(%rsp), %rdi
callq 0x5490
movq %rbp, %rdi
movq %r15, %rsi
callq 0xf8f2
movq %rax, %r14
testq %rax, %rax
je 0x21ffc
movq 0xc8(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0xc8(%rsp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
leaq 0xc8(%rsp), %rdi
callq 0x5040
movq %rax, %rdi
callq 0x52d0
testq %r14, %r14
jne 0x21f28
movq %r15, %rdi
callq 0xf8e8
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x22013
callq 0xfcc6
testq %rbp, %rbp
je 0x22020
movq %rbp, %rdi
callq 0xf957
leaq 0xc8(%rsp), %rdi
callq 0x5590
leaq 0x10(%rsp), %rdi
callq 0x2212a
leaq 0x30(%rsp), %rdi
callq 0x2212a
movq 0x12f40(%rip), %rax     # 0x34f88
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0xd0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0xc8(%rsp,%rcx)
callq 0x5340
leaq 0x1c0(%rsp), %rdi
callq 0x5150
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x220fd
jmp 0x220fd
jmp 0x220fd
movq %rax, %r14
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x22100
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x53e0
jmp 0x22100
jmp 0x220fd
jmp 0x220bb
jmp 0x220bb
jmp 0x220fd
movq %rax, %r14
jmp 0x22114
jmp 0x220fd
jmp 0x220fd
jmp 0x220fd
jmp 0x220fd
movq %rax, %r14
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x220ee
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x53e0
jmp 0x220ee
jmp 0x220fd
movq %rax, %r14
leaq 0xb0(%rsp), %rdi
callq 0x10982
jmp 0x22100
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x2212a
leaq 0x30(%rsp), %rdi
callq 0x2212a
leaq 0xc8(%rsp), %rdi
callq 0x55d0
movq %r14, %rdi
callq 0x56a0
nop