// File: /workspace/github_c_makefile_star2_O1/TimeToogo[P]ff-proxy/src/config.c
// Function: ff_parse_arguments
enum ff_action ff_parse_arguments(struct ff_config *config, int argc, char **argv)
{
    // Default values
    char *port = NULL;
    char *listen_address = default_listen_address;
    enum ff_action action = FF_ACTION_START_PROXY;
    int state = FF_PARSE_ARG_STATE_DEFAULT;
    enum ff_log_type logging_level = FF_ERROR;
    struct ff_encryption_config encryption_config = {
        .key = NULL,
        .pbkdf2_iterations = 1000};
    uint16_t timestamp_fudge_factor = 30;

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

        switch (state)
        {
        case FF_PARSE_ARG_STATE_DEFAULT:
            if (strcasecmp(arg, "--help") == 0)
            {
                action = FF_ACTION_PRINT_USAGE;
                goto done;
            }
            else if (strcasecmp(arg, "--version") == 0)
            {
                action = FF_ACTION_PRINT_VERSION;
                goto done;
            }
            else if (strcasecmp(arg, "--port") == 0)
            {
                state = FF_PARSE_ARG_PARSE_PORT;
            }
            else if (strcasecmp(arg, "--ip-address") == 0)
            {
                state = FF_PARSE_ARG_PARSE_IP;
            }
            else if (strcasecmp(arg, "--ipv6-v6only") == 0)
            {
                config->ipv6_v6only = true;
            }
            else if (strcasecmp(arg, "--pre-shared-key") == 0)
            {
                state = FF_PARSE_ARG_PARSE_PSK;
            }
            else if (strcasecmp(arg, "--pbkdf2-iterations") == 0)
            {
                state = FF_PARSE_ARG_PARSE_PBKDF2_ITERATIONS;
            }
            else if (strcasecmp(arg, "--timestamp-fudge-factor") == 0)
            {
                state = FF_PARSE_ARG_PARSE_TIMESTAMP_FUDGE_FACTOR;
            }
            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_ACTION_INVALID_ARGS;
                goto done;
            }
            break;

        case FF_PARSE_ARG_PARSE_PORT:
        {
            int parsed_port = atoi(arg);

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

            port = arg;
            state = FF_PARSE_ARG_STATE_DEFAULT;
            break;
        }

        case FF_PARSE_ARG_PARSE_IP:
        {
            int ret;
            unsigned char buf[sizeof(struct in6_addr)];

            if (strchr(arg, ':'))
            {
                ret = inet_pton(AF_INET6, arg, buf);
            }
            else
            {
                ret = inet_pton(AF_INET, arg, buf);
            }

            if (ret < 1)
            {
                fprintf(stderr, "Invalid --ip-address argument: %s\n\n", arg);
                action = FF_ACTION_INVALID_ARGS;
                goto done;
            }

            listen_address = arg;
            state = FF_PARSE_ARG_STATE_DEFAULT;
            break;
        }

        case FF_PARSE_ARG_PARSE_PSK:
            encryption_config.key = (uint8_t *)arg;
            state = FF_PARSE_ARG_STATE_DEFAULT;
            break;

        case FF_PARSE_ARG_PARSE_PBKDF2_ITERATIONS:
            encryption_config.pbkdf2_iterations = atoi(arg);

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

            state = FF_PARSE_ARG_STATE_DEFAULT;
            break;

        case FF_PARSE_ARG_PARSE_TIMESTAMP_FUDGE_FACTOR:
        {
            int parsed = atoi(arg);

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

            timestamp_fudge_factor = (uint16_t)parsed;

            state = FF_PARSE_ARG_STATE_DEFAULT;
            break;
        }

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

    if (action == FF_ACTION_START_PROXY)
    {
        if (!port)
        {
            fputs("--port is required\n\n", stderr);
            action = FF_ACTION_INVALID_ARGS;
            goto done;
        }

        config->ip_address = listen_address;
        config->port = port;
        config->encryption = encryption_config;
        config->logging_level = logging_level;
        config->timestamp_fudge_factor = timestamp_fudge_factor;
    }

done:
    return action;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorl %ebx, %ebx
cmpl $0x2, %esi
setl %cl
jge 0x265b
leaq 0x3b22(%rip), %rdx      # 0x6160
movw $0x1e, %r10w
movl $0x3e8, %r8d            # imm = 0x3E8
movl $0x1, %eax
movl $0x4, %esi
xorl %r9d, %r9d
jmp 0x2a10
movb %cl, -0x29(%rbp)
movq %rdi, -0x48(%rbp)
movl %esi, %eax
movl $0x1, %ecx
movq %rax, -0x70(%rbp)
subq %rax, %rcx
movq %rcx, -0x68(%rbp)
movl $0x4, -0x38(%rbp)
movl $0x1, -0x30(%rbp)
movl $0x3e8, -0x3c(%rbp)     # imm = 0x3E8
movw $0x1e, -0x32(%rbp)
leaq 0x3aca(%rip), %rax      # 0x6160
movq %rax, -0x58(%rbp)
movl $0x2, %r15d
movq %rdx, -0x60(%rbp)
movq -0x8(%rdx,%r15,8), %r13
movl %ebx, %eax
leaq 0x3952(%rip), %rcx      # 0x6004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq $0x0, -0x50(%rbp)
xorl %r12d, %r12d
jmpq *%rax
cmpq -0x70(%rbp), %r15
setae %cl
movq -0x68(%rbp), %rax
addq %r15, %rax
incq %rax
cmpq $0x2, %rax
je 0x29f5
movb %cl, -0x29(%rbp)
incq %r15
movq -0x60(%rbp), %rax
movq -0x8(%rax,%r15,8), %r13
movl %r12d, %eax
leaq 0x390a(%rip), %rcx      # 0x6004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
xorl %r12d, %r12d
jmpq *%rax
leaq 0x390f(%rip), %rsi      # 0x601c
movq %r13, %rdi
callq 0x22c0
xorl %r12d, %r12d
testl %eax, %eax
je 0x2836
leaq 0x38fc(%rip), %rsi      # 0x6023
movq %r13, %rdi
callq 0x22c0
xorl %r12d, %r12d
testl %eax, %eax
je 0x2842
leaq 0x38ec(%rip), %rsi      # 0x602d
movq %r13, %rdi
callq 0x22c0
movl $0x1, %r12d
testl %eax, %eax
je 0x29d7
leaq 0x38d6(%rip), %rsi      # 0x6034
movq %r13, %rdi
callq 0x22c0
movl $0x2, %r12d
testl %eax, %eax
je 0x29d7
leaq 0x38c6(%rip), %rsi      # 0x6041
movq %r13, %rdi
callq 0x22c0
testl %eax, %eax
je 0x29cc
leaq 0x38bd(%rip), %rsi      # 0x604f
movq %r13, %rdi
callq 0x22c0
movl $0x3, %r12d
testl %eax, %eax
je 0x29d7
leaq 0x38b1(%rip), %rsi      # 0x6060
movq %r13, %rdi
callq 0x22c0
movl $0x4, %r12d
testl %eax, %eax
je 0x29d7
leaq 0x38a8(%rip), %rsi      # 0x6074
movq %r13, %rdi
callq 0x22c0
movl $0x5, %r12d
testl %eax, %eax
je 0x29d7
leaq 0x38a4(%rip), %rsi      # 0x608d
movq %r13, %rdi
callq 0x22c0
xorl %r12d, %r12d
testl %eax, %eax
je 0x2a51
leaq 0x388f(%rip), %rsi      # 0x6092
movq %r13, %rdi
callq 0x22c0
testl %eax, %eax
je 0x2a5d
leaq 0x387c(%rip), %rsi      # 0x6096
movq %r13, %rdi
callq 0x22c0
testl %eax, %eax
jne 0x2a75
movl $0x3, -0x38(%rbp)
jmp 0x29d7
movl $0x3, -0x30(%rbp)
jmp 0x2941
movl $0x2, -0x30(%rbp)
jmp 0x2941
movq %r13, %rdi
movl $0x3a, %esi
callq 0x20f0
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
leal 0x2(,%rcx,8), %edi
leaq -0x80(%rbp), %rdx
movq %r13, %rsi
callq 0x24c0
movl %eax, %r14d
xorl %r12d, %r12d
testl %eax, %eax
jle 0x2972
movq %r13, -0x58(%rbp)
xorl %eax, %eax
movq %rbx, %r13
testl %r14d, %r14d
jg 0x29da
jmp 0x29df
movq %r13, %rdi
callq 0x2420
movl %eax, -0x3c(%rbp)
testl %eax, %eax
jne 0x29d4
movq 0x772b(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
leaq 0x3831(%rip), %rsi      # 0x60f0
movl $0x0, -0x3c(%rbp)
movq %r13, %rdx
xorl %eax, %eax
callq 0x23e0
movl $0x4, %r12d
movl $0x4, -0x30(%rbp)
jmp 0x2941
movq %r13, %rdi
callq 0x2420
movl %eax, %r14d
decl %r14d
xorl %r12d, %r12d
cmpl $0xffff, %r14d          # imm = 0xFFFF
jae 0x299f
movq %r13, -0x50(%rbp)
xorl %eax, %eax
movq %rbx, %r13
cmpl $0xffff, %r14d          # imm = 0xFFFF
jb 0x29da
jmp 0x29df
movq %r13, %rdi
callq 0x2420
leal -0x1(%rax), %r14d
cmpl $0xffff, %r14d          # imm = 0xFFFF
jae 0x2948
xorl %r12d, %r12d
movw %ax, -0x32(%rbp)
cmpl $0xffff, %r14d          # imm = 0xFFFF
jb 0x29d7
xorl %eax, %eax
jmp 0x29df
movq 0x7691(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
leaq 0x37c2(%rip), %rsi      # 0x611b
movq %r13, %rdx
xorl %eax, %eax
callq 0x23e0
movl $0x4, -0x30(%rbp)
movl $0x5, %r12d
jmp 0x2934
movq 0x7667(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
leaq 0x3749(%rip), %rsi      # 0x60cc
movq %r13, %rdx
xorl %eax, %eax
callq 0x23e0
movl $0x4, -0x30(%rbp)
movl $0x2, %r12d
jmp 0x2888
movq 0x763a(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
leaq 0x36fe(%rip), %rsi      # 0x60ae
movq %r13, %rdx
xorl %eax, %eax
callq 0x23e0
movl $0x4, -0x30(%rbp)
movl $0x1, %r12d
jmp 0x2901
movq -0x48(%rbp), %rax
movb $0x1, 0x2c(%rax)
xorl %r12d, %r12d
movq %rbx, %r13
movb $0x1, %al
movq %r13, %rbx
testb %al, %al
jne 0x26c6
movq -0x48(%rbp), %rdi
movzwl -0x32(%rbp), %r10d
movb -0x29(%rbp), %cl
jmp 0x29fe
movq -0x48(%rbp), %rdi
movzwl -0x32(%rbp), %r10d
movq -0x58(%rbp), %rdx
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %r8d
movq -0x50(%rbp), %r9
movl -0x30(%rbp), %eax
testb $0x1, %cl
je 0x2a42
cmpl $0x1, %eax
jne 0x2a42
testq %r9, %r9
je 0x2a69
movq %rdx, 0x8(%rdi)
movq %r9, (%rdi)
movq %rbx, 0x18(%rdi)
movl %r8d, 0x20(%rdi)
movl $0x0, 0x24(%rdi)
movl %esi, 0x28(%rdi)
movw %r10w, 0x10(%rdi)
movl $0x1, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, -0x38(%rbp)
jmp 0x29d7
movl $0x2, -0x38(%rbp)
jmp 0x29d7
callq 0x2510
movl $0x4, %eax
jmp 0x2a42
movq 0x7564(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
leaq 0x3613(%rip), %rsi      # 0x6099
xorl %r12d, %r12d
movq %r13, %rdx
xorl %eax, %eax
callq 0x23e0
jmp 0x28d6