// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
movl %esi, %r15d
leal -0x6(%r15), %eax
cmpl $-0x3, %eax
jb 0x3769
movq %rdx, %r14
cmpl $0x2, %r15d
jl 0x3699
movq %rdi, %r12
movq %r14, 0x10(%rsp)
movl $0x1, %r13d
xorl %ebx, %ebx
movq $0x0, 0x8(%rsp)
movslq %r13d, %rax
movq (%r12,%rax,8), %r14
movq %r14, %rdi
leaq 0x1d3b(%rip), %rsi      # 0x52d6
callq 0x2190
testl %eax, %eax
je 0x3618
movq %r14, %rdi
leaq 0x1d52(%rip), %rsi      # 0x5300
callq 0x2190
testl %eax, %eax
jne 0x3734
incl %r13d
cmpl %r15d, %r13d
je 0x3724
movslq %r13d, %rax
movq (%r12,%rax,8), %rbp
movq %rbp, %rdi
callq 0x2050
testq %rax, %rax
sete %cl
je 0x3608
movsbl (%rbp), %edx
addl $-0x30, %edx
cmpl $0x9, %edx
ja 0x3608
movl $0x1, %edx
movl %edx, %edx
cmpq %rdx, %rax
setbe %cl
jbe 0x3608
movsbl (%rbp,%rdx), %esi
addl $-0x30, %esi
incl %edx
cmpl $0xa, %esi
jb 0x35ef
testb %cl, %cl
je 0x3632
movq %rbp, %rdi
callq 0x21e0
movl %eax, %ebp
jmp 0x3679
incl %r13d
cmpl %r15d, %r13d
je 0x3744
movslq %r13d, %rax
movq (%r12,%rax,8), %rax
movq %rax, 0x8(%rsp)
jmp 0x367b
movl $0x4b, %edx
movq 0x4992(%rip), %rbx      # 0x7fd0
movq %rbx, %rdi
leaq 0x1cdd(%rip), %rsi      # 0x5325
callq 0x2120
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %ebp
movl $0xa, %esi
callq 0x20d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movb $0x1, %bl
incl %r13d
cmpl %r15d, %r13d
jl 0x358a
testb $0x1, %bl
sete %al
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r15
jmp 0x369e
movb $0x1, %al
xorl %r15d, %r15d
testq %r15, %r15
je 0x3779
testb %al, %al
je 0x36c0
movq 0x491e(%rip), %rdi      # 0x7fd0
leaq 0x1d0e(%rip), %rsi      # 0x53c7
movl $0x4c, %edx
jmp 0x36d7
testl %ebp, %ebp
jg 0x370f
movq 0x4905(%rip), %rdi      # 0x7fd0
leaq 0x1d42(%rip), %rsi      # 0x5414
movl $0x4a, %edx
callq 0x2120
movq 0x48ed(%rip), %rbx      # 0x7fd0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %ebp
movl $0xa, %esi
callq 0x20d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movl %ebp, (%r14)
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48a5(%rip), %rdi      # 0x7fd0
leaq 0x1bd1(%rip), %rsi      # 0x5303
jmp 0x3752
movq 0x4895(%rip), %rdi      # 0x7fd0
leaq 0x1c2f(%rip), %rsi      # 0x5371
jmp 0x3752
movq 0x4885(%rip), %rdi      # 0x7fd0
leaq 0x1b87(%rip), %rsi      # 0x52d9
callq 0x20e0
movq %rax, %rdi
callq 0x2060
movl $0x1, %edi
callq 0x2150
movq 0x4860(%rip), %rdi      # 0x7fd0
leaq 0x1b2e(%rip), %rsi      # 0x52a5
jmp 0x3752
movq 0x4850(%rip), %rdi      # 0x7fd0
leaq 0x1c11(%rip), %rsi      # 0x5398
jmp 0x3752