// File: /workspace/github_cpp_makefile_star2_O2/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 0x66b0
pushq $0x10
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x6200
callq 0x10100
movq %rax, %r14
xorl %edi, %edi
callq 0x103f6
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
callq 0x10138
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
leaq 0x98(%rsp), %rdi
movq %rbx, %rsi
callq 0x65b0
leaq 0x98(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x115a0
movq %r14, 0x8(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x61e0
movq 0x48(%rsp), %rax
subq 0x40(%rsp), %rax
pushq $0x18
popq %r14
cqto
idivq %r14
movq %rax, %rbx
shlq $0x20, %rax
movq %rax, %rdi
sarq $0x1d, %rdi
testq %rax, %rax
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x6030
xorl %r15d, %r15d
testl %ebx, %ebx
cmovlel %r15d, %ebx
leaq (%rbx,%rbx,2), %rbx
movq %rax, 0x78(%rsp)
movq %rax, %r12
cmpq %r15, %rbx
je 0x1f2bc
movq 0x40(%rsp), %rax
movq 0x8(%rax,%r15,8), %rsi
subq (%rax,%r15,8), %rsi
sarq $0x5, %rsi
movq %r13, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x10474
movq %rax, (%r12)
addq $0x3, %r15
addq $0x8, %r12
jmp 0x1f28b
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
cqto
idivq %r14
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq %rax, 0x60(%rsp)
leaq 0xb8(%rsp), %r15
movq %r13, 0x58(%rsp)
cmpq 0x60(%rsp), %rcx
je 0x1f475
movq 0x20(%rsp), %r12
movq %rcx, 0x68(%rsp)
imulq $0x18, %rcx, %rbx
movq (%r12,%rbx), %rdi
movq 0x8(%r12,%rbx), %rax
movq %rax, %rcx
subq %rdi, %rcx
shrq $0x5, %rcx
movq %rcx, (%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
subq %rdi, %rax
sarq $0x5, %rax
cmpq %r13, %rax
jbe 0x1f35a
addq %r14, %rdi
leaq 0x49d4(%rip), %rsi      # 0x23d04
callq 0x6140
cmpl $0x1, %eax
movq (%rsp), %rax
sbbl $0x0, %eax
movq %rax, (%rsp)
incq %r13
movq 0x20(%rsp), %r12
movq (%r12,%rbx), %rdi
movq 0x8(%r12,%rbx), %rax
addq $0x20, %r14
jmp 0x1f31a
movslq (%rsp), %rax
movq %rax, %rdi
shlq $0x4, %rdi
movq %rax, 0x70(%rsp)
testl %eax, %eax
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x6030
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
movq (%r12,%rbx), %rdi
movq 0x8(%r12,%rbx), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %r13, %rax
jbe 0x1f454
addq %r14, %rdi
leaq 0x4955(%rip), %rsi      # 0x23d04
callq 0x6140
testl %eax, %eax
je 0x1f43d
movq 0x78(%rsp), %rax
movq (%rax,%r13,8), %rax
movslq (%rsp), %r12
decq %r12
shlq $0x4, %r12
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r12)
movq 0x40(%rsp), %rsi
addq 0x10(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x178b6
movq 0x20(%rsp), %rax
movq (%rax,%rbx), %rsi
addq %r14, %rsi
movq %r15, %rdi
callq 0x65b0
leaq 0x80(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x111cc
movq (%rsp), %rcx
decl %ecx
movq %rcx, (%rsp)
cltq
movq 0x18(%rsp), %rcx
movq %rax, 0x8(%rcx,%r12)
movq %r15, %rdi
callq 0x61e0
movq %rbp, %rdi
callq 0x11254
incq %r13
movq 0x20(%rsp), %r12
addq $0x20, %r14
addq $0x18, 0x10(%rsp)
jmp 0x1f38c
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x1013d
movq 0x68(%rsp), %rcx
incq %rcx
jmp 0x1f2e4
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x102b4
movq %rbx, %rdi
callq 0x10369
movq %rax, %r14
movq %rbx, %rdi
callq 0x105c8
movq %rax, (%rsp)
movq %rbx, %rdi
callq 0x1037e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10383
testq %rax, %rax
setne %bl
movq (%rsp), %r13
decq %r13
imulq $0x18, %r13, %rax
movq %rax, 0x10(%rsp)
leaq 0xd8(%rsp), %r15
leaq 0x4709(%rip), %r12      # 0x23bda
testb $0x1, %bl
je 0x1f549
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x40(%rsp), %rax
cmpq %rbp, %r13
je 0x1f50c
movq (%r14,%rbp,8), %rsi
shlq $0x5, %rsi
addq (%rax,%rbx), %rsi
movq %r15, %rdi
callq 0x63d0
movq %rax, %rdi
movq %r12, %rsi
callq 0x6430
incq %rbp
addq $0x18, %rbx
jmp 0x1f4da
movq (%rsp), %rcx
movq -0x8(%r14,%rcx,8), %rsi
shlq $0x5, %rsi
movq 0x10(%rsp), %rcx
addq (%rax,%rcx), %rsi
movq %r15, %rdi
callq 0x63d0
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x10383
testq %rax, %rax
setne %bl
je 0x1f4d1
movq %r15, %rdi
callq 0x6210
jmp 0x1f4d1
movq %r14, %rdi
callq 0x10379
movq 0x8(%rsp), %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x1f565
callq 0x1060c
testq %rbx, %rbx
je 0x1f572
movq %rbx, %rdi
callq 0x103d9
leaq 0xd8(%rsp), %rdi
callq 0x65e0
leaq 0x20(%rsp), %rdi
callq 0x1f632
leaq 0x40(%rsp), %rdi
callq 0x1f632
leaq 0xd8(%rsp), %rdi
callq 0x6610
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1f605
jmp 0x1f605
jmp 0x1f605
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x61e0
jmp 0x1f608
jmp 0x1f605
jmp 0x1f5d2
jmp 0x1f5d2
jmp 0x1f605
movq %rax, %rbx
jmp 0x1f61c
jmp 0x1f605
jmp 0x1f605
jmp 0x1f605
jmp 0x1f605
jmp 0x1f605
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x61e0
jmp 0x1f5f6
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x11254
jmp 0x1f608
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x1f632
leaq 0x40(%rsp), %rdi
callq 0x1f632
leaq 0xd8(%rsp), %rdi
callq 0x6610
movq %rbx, %rdi
callq 0x66e0
nop