// File: /workspace/github_cpp_makefile_star2_O3/JohnPapad[P]Mini-Search-Engine/minisearch.cpp
// Function: check_program_args(char**, int, unsigned int&)
char * check_program_args(char ** argv, int argc, unsigned int & K)
{
    if ((argc < 3) || (argc > 5))
    {
        cout<<"-! ERROR - Wrong number of arguments is given !-"<<endl;
        exit(1);
    }

    char * docfile = NULL;
    int kappa;
    bool k_found = 0;

    for(int i = 1; i < argc; i++)
    {
        if(strcmp(argv[i], "-i") == 0)
        {// if -i parameter found the next argument must be docfile's name
            if((i + 1) == argc)
            {
                cout<<"-! ERROR - Docfile's name not found !-"<<endl;
                exit(1);
            }
            else
            {
                docfile = argv[i + 1];
                i++;
            }
        }
        else if(strcmp(argv[i], "-k") == 0)
        {
            if((i + 1) == argc)
            {
                cout<<"-! ERROR - K's value not found !-"<<endl;
                exit(1);
            }
            else
            {
                if(!is_number(argv[i + 1]))
                {
                    cout<<"-> WARNING - K's value is not a number. K will be set by default with 10 <-"<<endl;
                    kappa = 10;
                }
                else
                {
                    kappa = atoi(argv[i + 1]);
                }

                k_found = 1;
                i++;
            }
        }
        else
        {
            cout<<"-! ERROR - invalid parameters given !-"<<endl;
            exit(1);
        }
    }

    if(docfile == NULL)
    {
        cout<<"-! ERROR - Docfile's -i parameter not found !-"<<endl;
        exit(1);
    }

    if(k_found == 0)
    {
        cout<<"-> WARNING - K's -k parameter not found. K will be set by default with 10 <-"<<endl;
        K = 10;
    }
    else
    {
        if (kappa < 1)
        {
            cout<<"-> WARNING - K's value is less than 1. K will be set by default with 10 <-"<<endl;
            K = 10;
        }
        else
        {
            K = kappa;
        }
    }

    return docfile;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, (%rsp)
movl %esi, %r12d
leal -0x6(%r12), %eax
cmpl $-0x3, %eax
jb 0x3716
movq %rdi, %r13
movl $0x1, %ebp
xorl %eax, %eax
movq 0x4a65(%rip), %r14      # 0x7fd0
xorl %r15d, %r15d
movslq %ebp, %rcx
movq (%r13,%rcx,8), %rcx
cmpb $0x2d, (%rcx)
jne 0x36d1
cmpb $0x69, 0x1(%rcx)
jne 0x358f
cmpb $0x0, 0x2(%rcx)
je 0x363a
cmpb $0x6b, 0x1(%rcx)
jne 0x36d1
cmpb $0x0, 0x2(%rcx)
jne 0x36d1
incl %ebp
cmpl %r12d, %ebp
je 0x36e1
movslq %ebp, %rax
movq (%r13,%rax,8), %rbx
movq %rbx, %rdi
callq 0x2050
testq %rax, %rax
je 0x35df
movl $0x1, %ecx
xorl %edx, %edx
movsbl (%rbx,%rdx), %edx
addl $-0x30, %edx
cmpl $0xa, %edx
jae 0x35eb
movl %ecx, %edx
incl %ecx
cmpq %rdx, %rax
ja 0x35ca
movq %rbx, %rdi
callq 0x21e0
movl %eax, %ebx
jmp 0x362b
movl $0x4b, %edx
movq %r14, %rdi
leaq 0x1d25(%rip), %rsi      # 0x531f
callq 0x2120
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %ebx
movl $0xa, %esi
callq 0x20d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movb $0x1, %al
incl %ebp
cmpl %r12d, %ebp
jl 0x356e
jmp 0x364f
incl %ebp
cmpl %r12d, %ebp
je 0x3706
movslq %ebp, %rcx
movq (%r13,%rcx,8), %r15
jmp 0x362d
testq %r15, %r15
je 0x3726
testb $0x1, %al
jne 0x3671
movq 0x496d(%rip), %rdi      # 0x7fd0
leaq 0x1d57(%rip), %rsi      # 0x53c1
movl $0x4c, %edx
jmp 0x3688
testl %ebx, %ebx
jg 0x36b9
movq 0x4954(%rip), %rdi      # 0x7fd0
leaq 0x1d8b(%rip), %rsi      # 0x540e
movl $0x4a, %edx
callq 0x2120
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %ebx
movl $0xa, %esi
callq 0x20d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq (%rsp), %rax
movl %ebx, (%rax)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48f8(%rip), %rdi      # 0x7fd0
leaq 0x1c8c(%rip), %rsi      # 0x536b
jmp 0x36ef
movq 0x48e8(%rip), %rdi      # 0x7fd0
leaq 0x1c0e(%rip), %rsi      # 0x52fd
callq 0x20e0
movq %rax, %rdi
callq 0x2060
movl $0x1, %edi
callq 0x2150
movq 0x48c3(%rip), %rdi      # 0x7fd0
leaq 0x1bc2(%rip), %rsi      # 0x52d6
jmp 0x36ef
movq 0x48b3(%rip), %rdi      # 0x7fd0
leaq 0x1b81(%rip), %rsi      # 0x52a5
jmp 0x36ef
movq 0x48a3(%rip), %rdi      # 0x7fd0
leaq 0x1c5e(%rip), %rsi      # 0x5392
jmp 0x36ef