// File: Cristian-Castillo[P]Multithreaded-HTTP-Server/./httpserver_definitions.cpp
// Function: f_getopt(int, char**, command_line_inputs*)
void f_getopt(int argc, char *argv[], struct command_line_inputs *configs){

    int option;
    /* Make sure the -N flag followed by a number is utitlized correctly and only once */
    int Nflag = 0; 
    /* Make sure the -r flag is utlizied correctly and only once */
    int Rflag = 0; 

    configs->N_threads = 4;
    configs->Redundancy = 0;
    while((option = getopt(argc, argv, "rN:")) != -1){

        switch(option){
            case 'N':
                if(Nflag == 1){
                    fprintf(stderr, "Error: same flag used twice.\n");
                    exit(EXIT_FAILURE);
                }
                else{
                    if(atoi(optarg) == 0){
                        fprintf(stderr, "Usage: (-N <integer>).\n");
                        exit(EXIT_FAILURE);
                    }
                    configs->N_threads = atoi(optarg);
                    Nflag += 1;
                }
                continue;
            case 'r':
                if(Rflag == 1){
                    fprintf(stderr, "Error: same flag used twice.\n");
                    exit(EXIT_FAILURE);
                }
                else{
                    configs->Redundancy = 1;
                    Rflag += 1;
                }
                
                continue;
            default: /* '?' */
                fprintf(stderr, "Options:(-r) or (-N <integer>). \n");
                exit(EXIT_FAILURE);
        }
    }
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl $0x4, (%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x4(%rax)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x2f6d4(%rip), %rdx     # 0x35178
callq 0x50d0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
je 0x5bb9
movl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
subl $0x4e, %eax
je 0x5ad3
jmp 0x5ac2
movl -0x28(%rbp), %eax
subl $0x72, %eax
je 0x5b56
jmp 0x5b97
cmpl $0x1, -0x20(%rbp)
jne 0x5afb
movq 0x494e8(%rip), %rax     # 0x4efc8
movq (%rax), %rdi
leaq 0x2f692(%rip), %rsi     # 0x3517c
movb $0x0, %al
callq 0x56a0
movl $0x1, %edi
callq 0x5580
movq 0x4949e(%rip), %rax     # 0x4efa0
movq (%rax), %rdi
callq 0x5730
cmpl $0x0, %eax
jne 0x5b31
movq 0x494b2(%rip), %rax     # 0x4efc8
movq (%rax), %rdi
leaq 0x2f67a(%rip), %rsi     # 0x3519a
movb $0x0, %al
callq 0x56a0
movl $0x1, %edi
callq 0x5580
movq 0x49468(%rip), %rax     # 0x4efa0
movq (%rax), %rdi
callq 0x5730
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x5a96
cmpl $0x1, -0x24(%rbp)
jne 0x5b7e
movq 0x49465(%rip), %rax     # 0x4efc8
movq (%rax), %rdi
leaq 0x2f60f(%rip), %rsi     # 0x3517c
movb $0x0, %al
callq 0x56a0
movl $0x1, %edi
callq 0x5580
movq -0x18(%rbp), %rax
movl $0x1, 0x4(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x5a96
movq 0x4942a(%rip), %rax     # 0x4efc8
movq (%rax), %rdi
leaq 0x2f60a(%rip), %rsi     # 0x351b2
movb $0x0, %al
callq 0x56a0
movl $0x1, %edi
callq 0x5580
addq $0x30, %rsp
popq %rbp
retq
nop