// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq 0x8c5b(%rip), %rax      # 0xb2b0
movq %rax, -0x28(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x4, -0x34(%rbp)
movq 0x49ab(%rip), %rax      # 0x7020
movq %rax, -0x48(%rbp)
movq 0x49a8(%rip), %rax      # 0x7028
movq %rax, -0x40(%rbp)
movw $0x1e, -0x4a(%rbp)
movl $0x1, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2a28
movq -0x18(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movl -0x30(%rbp), %eax
movq %rax, -0x80(%rbp)
subq $0x5, %rax
ja 0x29f9
movq -0x80(%rbp), %rax
leaq 0x493b(%rip), %rcx      # 0x7004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x58(%rbp), %rdi
leaq 0x4953(%rip), %rsi      # 0x7030
callq 0x22d0
cmpl $0x0, %eax
jne 0x26f3
movl $0x3, -0x2c(%rbp)
jmp 0x2a97
movq -0x58(%rbp), %rdi
leaq 0x4939(%rip), %rsi      # 0x7037
callq 0x22d0
cmpl $0x0, %eax
jne 0x2714
movl $0x2, -0x2c(%rbp)
jmp 0x2a97
movq -0x58(%rbp), %rdi
leaq 0x4922(%rip), %rsi      # 0x7041
callq 0x22d0
cmpl $0x0, %eax
jne 0x2735
movl $0x1, -0x30(%rbp)
jmp 0x286d
movq -0x58(%rbp), %rdi
leaq 0x4908(%rip), %rsi      # 0x7048
callq 0x22d0
cmpl $0x0, %eax
jne 0x2756
movl $0x2, -0x30(%rbp)
jmp 0x286b
movq -0x58(%rbp), %rdi
leaq 0x48f4(%rip), %rsi      # 0x7055
callq 0x22d0
cmpl $0x0, %eax
jne 0x2778
movq -0x8(%rbp), %rax
movb $0x1, 0x2c(%rax)
jmp 0x2869
movq -0x58(%rbp), %rdi
leaq 0x48e0(%rip), %rsi      # 0x7063
callq 0x22d0
cmpl $0x0, %eax
jne 0x2799
movl $0x3, -0x30(%rbp)
jmp 0x2867
movq -0x58(%rbp), %rdi
leaq 0x48d0(%rip), %rsi      # 0x7074
callq 0x22d0
cmpl $0x0, %eax
jne 0x27ba
movl $0x4, -0x30(%rbp)
jmp 0x2865
movq -0x58(%rbp), %rdi
leaq 0x48c3(%rip), %rsi      # 0x7088
callq 0x22d0
cmpl $0x0, %eax
jne 0x27db
movl $0x5, -0x30(%rbp)
jmp 0x2863
movq -0x58(%rbp), %rdi
leaq 0x48bb(%rip), %rsi      # 0x70a1
callq 0x22d0
cmpl $0x0, %eax
jne 0x27f9
movl $0x1, -0x34(%rbp)
jmp 0x2861
movq -0x58(%rbp), %rdi
leaq 0x48a2(%rip), %rsi      # 0x70a6
callq 0x22d0
cmpl $0x0, %eax
jne 0x2817
movl $0x2, -0x34(%rbp)
jmp 0x285f
movq -0x58(%rbp), %rdi
leaq 0x4888(%rip), %rsi      # 0x70aa
callq 0x22d0
cmpl $0x0, %eax
jne 0x2835
movl $0x3, -0x34(%rbp)
jmp 0x285d
movq 0x87a4(%rip), %rax      # 0xafe0
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0x4863(%rip), %rsi      # 0x70ad
movb $0x0, %al
callq 0x2400
movl $0x4, -0x2c(%rbp)
jmp 0x2a97
jmp 0x285f
jmp 0x2861
jmp 0x2863
jmp 0x2865
jmp 0x2867
jmp 0x2869
jmp 0x286b
jmp 0x286d
jmp 0x286f
jmp 0x2871
jmp 0x2a18
movq -0x58(%rbp), %rdi
callq 0x2440
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jle 0x2891
cmpl $0xffff, -0x5c(%rbp)    # imm = 0xFFFF
jle 0x28b9
movq 0x8748(%rip), %rax      # 0xafe0
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0x481c(%rip), %rsi      # 0x70c2
movb $0x0, %al
callq 0x2400
movl $0x4, -0x2c(%rbp)
jmp 0x2a97
movq -0x58(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x2a18
movq -0x58(%rbp), %rdi
movl $0x3a, %esi
callq 0x2100
cmpq $0x0, %rax
je 0x28f8
movq -0x58(%rbp), %rsi
leaq -0x70(%rbp), %rdx
movl $0xa, %edi
callq 0x24f0
movl %eax, -0x60(%rbp)
jmp 0x290d
movq -0x58(%rbp), %rsi
leaq -0x70(%rbp), %rdx
movl $0x2, %edi
callq 0x24f0
movl %eax, -0x60(%rbp)
cmpl $0x1, -0x60(%rbp)
jge 0x293b
movq 0x86c6(%rip), %rax      # 0xafe0
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0x47b8(%rip), %rsi      # 0x70e0
movb $0x0, %al
callq 0x2400
movl $0x4, -0x2c(%rbp)
jmp 0x2a97
movq -0x58(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x2a18
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x2a18
movq -0x58(%rbp), %rdi
callq 0x2440
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
ja 0x299d
movq 0x8664(%rip), %rax      # 0xafe0
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0x477a(%rip), %rsi      # 0x7104
movb $0x0, %al
callq 0x2400
movl $0x4, -0x2c(%rbp)
jmp 0x2a97
movl $0x0, -0x30(%rbp)
jmp 0x2a18
movq -0x58(%rbp), %rdi
callq 0x2440
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
jle 0x29c1
cmpl $0xffff, -0x74(%rbp)    # imm = 0xFFFF
jle 0x29e9
movq 0x8618(%rip), %rax      # 0xafe0
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0x4759(%rip), %rsi      # 0x712f
movb $0x0, %al
callq 0x2400
movl $0x4, -0x2c(%rbp)
jmp 0x2a97
movl -0x74(%rbp), %eax
movw %ax, -0x4a(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x2a18
movq 0x85e0(%rip), %rax      # 0xafe0
movq (%rax), %rsi
leaq 0x4755(%rip), %rdi      # 0x715f
callq 0x2320
movl $0x4, -0x2c(%rbp)
jmp 0x2a97
jmp 0x2a1a
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x2691
cmpl $0x1, -0x2c(%rbp)
jne 0x2a95
cmpq $0x0, -0x20(%rbp)
jne 0x2a54
movq 0x85a4(%rip), %rax      # 0xafe0
movq (%rax), %rsi
leaq 0x4732(%rip), %rdi      # 0x7178
callq 0x2320
movl $0x4, -0x2c(%rbp)
jmp 0x2a97
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq %rcx, 0x20(%rax)
movl -0x34(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
movw -0x4a(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x10(%rax)
jmp 0x2a97
movl -0x2c(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)