// File: /workspace/github_cpp_makefile_star2_O2/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, %r15d
leal -0x6(%r15), %eax
cmpl $-0x3, %eax
jb 0x31c0
movq %rdi, %r12
pushq $0x1
popq %r13
xorl %r14d, %r14d
pushq $0xa
popq %rbp
xorl %ecx, %ecx
cmpl %r15d, %r13d
jge 0x312c
movslq %r13d, %rdx
movq (%r12,%rdx,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x317d
cmpb $0x69, 0x1(%rdx)
jne 0x30b1
cmpb $0x0, 0x2(%rdx)
je 0x3111
cmpb $0x6b, 0x1(%rdx)
jne 0x317d
cmpb $0x0, 0x2(%rdx)
jne 0x317d
incl %r13d
cmpl %r15d, %r13d
je 0x318d
movslq %r13d, %rax
movq (%r12,%rax,8), %rbx
movq %rbx, %rdi
callq 0x298b
testb %al, %al
je 0x30f0
movq %rbx, %rdi
callq 0x21a0
movb $0x1, %cl
jmp 0x3124
movq 0x3ed9(%rip), %rdi      # 0x6fd0
leaq 0x1221(%rip), %rsi      # 0x431f
callq 0x20a0
movq %rax, %rdi
callq 0x2050
movb $0x1, %cl
movl %ebp, %eax
jmp 0x3124
incl %r13d
cmpl %r15d, %r13d
je 0x31b0
movslq %r13d, %rdx
movq (%r12,%rdx,8), %r14
incl %r13d
jmp 0x308c
testq %r14, %r14
je 0x31d0
testb $0x1, %cl
jne 0x3143
leaq 0x1280(%rip), %rsi      # 0x43c1
jmp 0x314e
testl %eax, %eax
jg 0x3165
leaq 0x12c0(%rip), %rsi      # 0x440e
movq 0x3e7b(%rip), %rdi      # 0x6fd0
callq 0x20a0
movq %rax, %rdi
callq 0x2050
pushq $0xa
popq %rax
movq (%rsp), %rcx
movl %eax, (%rcx)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3e4c(%rip), %rdi      # 0x6fd0
leaq 0x11e0(%rip), %rsi      # 0x436b
jmp 0x319b
movq 0x3e3c(%rip), %rdi      # 0x6fd0
leaq 0x1162(%rip), %rsi      # 0x42fd
callq 0x20a0
movq %rax, %rdi
callq 0x2050
pushq $0x1
popq %rdi
callq 0x2110
movq 0x3e19(%rip), %rdi      # 0x6fd0
leaq 0x1118(%rip), %rsi      # 0x42d6
jmp 0x319b
movq 0x3e09(%rip), %rdi      # 0x6fd0
leaq 0x10d7(%rip), %rsi      # 0x42a5
jmp 0x319b
movq 0x3df9(%rip), %rdi      # 0x6fd0
leaq 0x11b4(%rip), %rsi      # 0x4392
jmp 0x319b