// File: /workspace/github_c_makefile_star2_O0/TimeToogo[P]ff-proxy/client/c/config.c
// Function: ff_client_parse_arguments
enum ff_client_action ff_client_parse_arguments(struct ff_client_config *config, int argc, char **argv)
{
    enum ff_client_action action = FF_CLIENT_ACTION_MAKE_REQUEST;
    int state = FF_CLIENT_PARSE_ARG_STATE_DEFAULT;
    enum ff_log_type logging_level = FF_ERROR;
    struct ff_encryption_config encryption_config = {.key = NULL, .pbkdf2_iterations = 1000};

    /*
     * Not strictly necessary as config is declared global static,
     * but the tests repeatedly call this function, so ensure it's
     * cleared each time for them.
     */
    memset(config, 0, sizeof(struct ff_config));

    for (int i = 1; i < argc; i++)
    {
        char *arg = argv[i];

        switch (state)
        {
        case FF_CLIENT_PARSE_ARG_STATE_DEFAULT:
            if (strcasecmp(arg, "--help") == 0)
            {
                action = FF_CLIENT_ACTION_PRINT_USAGE;
                goto done;
            }

            else if (strcasecmp(arg, "--version") == 0)
            {
                action = FF_CLIENT_ACTION_PRINT_VERSION;
                goto done;
            }
            else if (strcasecmp(arg, "--port") == 0)
            {
                state = FF_CLIENT_PARSE_ARG_PARSE_PORT;
            }
            else if (strcasecmp(arg, "--ip-address") == 0)
            {
                state = FF_CLIENT_PARSE_ARG_PARSE_IP;
            }
            else if (strcasecmp(arg, "--pre-shared-key") == 0)
            {
                state = FF_CLIENT_PARSE_ARG_PARSE_PSK;
            }
            else if (strcasecmp(arg, "--pbkdf2-iterations") == 0)
            {
                state = FF_CLIENT_PARSE_ARG_PARSE_PBKDF2_ITERATIONS;
            }
            else if (strcasecmp(arg, "--https") == 0)
            {
                config->https = true;
            }
            else if (strcasecmp(arg, "-vvv") == 0)
            {
                logging_level = FF_DEBUG;
            }
            else if (strcasecmp(arg, "-vv") == 0)
            {
                logging_level = FF_INFO;
            }
            else if (strcasecmp(arg, "-v") == 0)
            {
                logging_level = FF_WARNING;
            }
            else
            {
                fprintf(stderr, "Unkown argument %s\n\n", arg);
                action = FF_CLIENT_ACTION_INVALID_ARGS;
                goto done;
            }
            break;

        case FF_CLIENT_PARSE_ARG_PARSE_PORT:
        {
            int port = atoi(arg);

            if (port <= 0 || port > UINT16_MAX)
            {
                fprintf(stderr, "Invalid --port argument: %s\n\n", arg);
                action = FF_CLIENT_ACTION_INVALID_ARGS;
                goto done;
            }

            config->port = arg;
            state = FF_CLIENT_PARSE_ARG_STATE_DEFAULT;
            break;
       }

        case FF_CLIENT_PARSE_ARG_PARSE_IP:
            config->ip_address = arg;
            state = FF_CLIENT_PARSE_ARG_STATE_DEFAULT;
            break;

        case FF_CLIENT_PARSE_ARG_PARSE_PSK:
            encryption_config.key = (uint8_t *)arg;
            state = FF_CLIENT_PARSE_ARG_STATE_DEFAULT;
            break;

        case FF_CLIENT_PARSE_ARG_PARSE_PBKDF2_ITERATIONS:
            sscanf(arg, "%u", &encryption_config.pbkdf2_iterations);

            if (encryption_config.pbkdf2_iterations == 0)
            {
                fprintf(stderr, "Invalid --pbkdf2-iterations argument: %s\n\n", arg);
                action = FF_CLIENT_ACTION_INVALID_ARGS;
                goto done;
            }

            state = FF_CLIENT_PARSE_ARG_STATE_DEFAULT;
            break;

        default:
            fputs("Unkown parse arg state\n\n", stderr);
            action = FF_CLIENT_ACTION_INVALID_ARGS;
            goto done;
        }
    }

    if (action == FF_CLIENT_ACTION_MAKE_REQUEST)
    {
        if (!config->port)
        {
            fputs("--port is required\n\n", stderr);
            action = FF_CLIENT_ACTION_INVALID_ARGS;
            goto done;
        }

        if (!config->ip_address)
        {
            config->ip_address = default_ip_address;
        }

        config->encryption = encryption_config;
        config->logging_level = logging_level;
    }

done:
    return action;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x4, -0x24(%rbp)
movq 0x2f21(%rip), %rax      # 0x6250
movq %rax, -0x38(%rbp)
movq 0x2f1e(%rip), %rax      # 0x6258
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2100
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x361a
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movl -0x20(%rbp), %eax
movq %rax, -0x58(%rbp)
subq $0x4, %rax
ja 0x35eb
movq -0x58(%rbp), %rax
leaq 0x2eab(%rip), %rcx      # 0x6238
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x48(%rbp), %rdi
leaq 0x2ebf(%rip), %rsi      # 0x6260
callq 0x21d0
cmpl $0x0, %eax
jne 0x33b7
movl $0x3, -0x1c(%rbp)
jmp 0x3683
movq -0x48(%rbp), %rdi
leaq 0x2ea5(%rip), %rsi      # 0x6267
callq 0x21d0
cmpl $0x0, %eax
jne 0x33d8
movl $0x2, -0x1c(%rbp)
jmp 0x3683
movq -0x48(%rbp), %rdi
leaq 0x2e8e(%rip), %rsi      # 0x6271
callq 0x21d0
cmpl $0x0, %eax
jne 0x33f9
movl $0x1, -0x20(%rbp)
jmp 0x350e
movq -0x48(%rbp), %rdi
leaq 0x2e74(%rip), %rsi      # 0x6278
callq 0x21d0
cmpl $0x0, %eax
jne 0x341a
movl $0x2, -0x20(%rbp)
jmp 0x350c
movq -0x48(%rbp), %rdi
leaq 0x2e60(%rip), %rsi      # 0x6285
callq 0x21d0
cmpl $0x0, %eax
jne 0x343b
movl $0x3, -0x20(%rbp)
jmp 0x350a
movq -0x48(%rbp), %rdi
leaq 0x2e50(%rip), %rsi      # 0x6296
callq 0x21d0
cmpl $0x0, %eax
jne 0x345c
movl $0x4, -0x20(%rbp)
jmp 0x3508
movq -0x48(%rbp), %rdi
leaq 0x2e43(%rip), %rsi      # 0x62aa
callq 0x21d0
cmpl $0x0, %eax
jne 0x347e
movq -0x8(%rbp), %rax
movb $0x1, 0x10(%rax)
jmp 0x3506
movq -0x48(%rbp), %rdi
leaq 0x2e29(%rip), %rsi      # 0x62b2
callq 0x21d0
cmpl $0x0, %eax
jne 0x349c
movl $0x1, -0x24(%rbp)
jmp 0x3504
movq -0x48(%rbp), %rdi
leaq 0x2e10(%rip), %rsi      # 0x62b7
callq 0x21d0
cmpl $0x0, %eax
jne 0x34ba
movl $0x2, -0x24(%rbp)
jmp 0x3502
movq -0x48(%rbp), %rdi
leaq 0x2df6(%rip), %rsi      # 0x62bb
callq 0x21d0
cmpl $0x0, %eax
jne 0x34d8
movl $0x3, -0x24(%rbp)
jmp 0x3500
movq 0x5b01(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
movq -0x48(%rbp), %rdx
leaq 0x2dd1(%rip), %rsi      # 0x62be
movb $0x0, %al
callq 0x2260
movl $0x4, -0x1c(%rbp)
jmp 0x3683
jmp 0x3502
jmp 0x3504
jmp 0x3506
jmp 0x3508
jmp 0x350a
jmp 0x350c
jmp 0x350e
jmp 0x3510
jmp 0x3512
jmp 0x360a
movq -0x48(%rbp), %rdi
callq 0x22a0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jle 0x3532
cmpl $0xffff, -0x4c(%rbp)    # imm = 0xFFFF
jle 0x355a
movq 0x5aa7(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
movq -0x48(%rbp), %rdx
leaq 0x2d8c(%rip), %rsi      # 0x62d3
movb $0x0, %al
callq 0x2260
movl $0x4, -0x1c(%rbp)
jmp 0x3683
movq -0x48(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x20(%rbp)
jmp 0x360a
movq -0x48(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x20(%rbp)
jmp 0x360a
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x20(%rbp)
jmp 0x360a
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rdx
addq $0x8, %rdx
leaq 0x3624(%rip), %rsi      # 0x6bd1
movb $0x0, %al
callq 0x21b0
cmpl $0x0, -0x30(%rbp)
jne 0x35e2
movq 0x5a1f(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
movq -0x48(%rbp), %rdx
leaq 0x2d22(%rip), %rsi      # 0x62f1
movb $0x0, %al
callq 0x2260
movl $0x4, -0x1c(%rbp)
jmp 0x3683
movl $0x0, -0x20(%rbp)
jmp 0x360a
movq 0x59ee(%rip), %rax      # 0x8fe0
movq (%rax), %rsi
leaq 0x2d20(%rip), %rdi      # 0x631c
callq 0x21f0
movl $0x4, -0x1c(%rbp)
jmp 0x3683
jmp 0x360c
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3355
cmpl $0x1, -0x1c(%rbp)
jne 0x3681
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x3649
movq 0x59af(%rip), %rax      # 0x8fe0
movq (%rax), %rsi
leaq 0x2cfa(%rip), %rdi      # 0x6335
callq 0x21f0
movl $0x4, -0x1c(%rbp)
jmp 0x3683
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x3663
movq 0x5b55(%rip), %rcx      # 0x91b0
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x20(%rax)
movl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
jmp 0x3683
movl -0x1c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)