// File: /workspace/github_c_makefile_star2_O2/TimeToogo[P]ff-proxy/src/server.c
// Function: ff_proxy_process_incoming_packet
void ff_proxy_process_incoming_packet(struct ff_config *config, struct ff_hash_table *requests, struct sockaddr *src_address, void *packet_buff, int buff_len)
{
    bool is_raw_http = ff_request_is_raw_http(buff_len, packet_buff);
    uint64_t request_id = 0;
    struct ff_request *request;
    pthread_t thread;
    pthread_attr_t thread_attrs;
    struct ff_process_request_args *thread_args;

    if (is_raw_http)
    {
        ff_log(FF_DEBUG, "Incoming packet is raw HTTP request");
        request = ff_request_alloc();
        ff_request_parse_chunk(request, buff_len, packet_buff);
    }
    else
    {
        ff_log(FF_DEBUG, "Parsing incoming packet");
        request_id = ff_request_parse_id(buff_len, packet_buff);

        if (request_id == 0)
        {
            ff_log(FF_DEBUG, "Could not parse request ID from incoming packet");
            goto done;
        }

        request = (struct ff_request *)ff_hash_table_get_item(requests, request_id);

        if (request == NULL)
        {
            request = ff_request_alloc();
            time(&request->received_at);
            memcpy(&request->source, src_address, sizeof(struct sockaddr));
            ff_hash_table_put_item(requests, request_id, (void *)request);
        }

        if (memcmp(&request->source, src_address, sizeof(struct sockaddr)) != 0)
        {
            ff_log(FF_WARNING, "Incoming packet IP address does not match original source IP address/port for request %lu (will discard)", request->request_id);
            goto done;
        }

        ff_request_parse_chunk(request, buff_len, packet_buff);
    }

    switch (request->state)
    {
    case FF_REQUEST_STATE_RECEIVING:
        break;

    case FF_REQUEST_STATE_RECEIVING_FAIL:
        if (request_id != 0)
        {
            ff_hash_table_remove_item(requests, request_id);
        }
        ff_request_free(request);
        break;

    case FF_REQUEST_STATE_RECEIVED:
        ff_log(FF_DEBUG, "Finished receiving incoming request");

        thread_args = malloc(sizeof(struct ff_process_request_args));
        thread_args->config = config;
        thread_args->request = request;
        thread_args->requests = requests;

        pthread_attr_init(&thread_attrs);
        pthread_attr_setdetachstate(&thread_attrs, PTHREAD_CREATE_DETACHED);

        pthread_create(&thread, &thread_attrs, (void *)ff_proxy_process_request, (void *)thread_args);

        pthread_attr_destroy(&thread_attrs);
        break;
    default:
        ff_log(FF_ERROR, "Encountered invalid request state: %d", request->state);
        break;
    }

done:
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, %r13d
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, -0x38(%rbp)
movl %r8d, %edi
movq %rcx, %rsi
callq 0x42ac
testb %al, %al
je 0x4cc6
movq %r14, -0x30(%rbp)
leaq 0x172a(%rip), %rsi      # 0x6389
xorl %r15d, %r15d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x3db4
callq 0x4725
movq %rax, %r14
movq %rax, %rdi
movl %r13d, %esi
movq %r12, %rdx
callq 0x3f78
movl (%r14), %edx
testl %edx, %edx
je 0x4df1
cmpl $0x1, %edx
je 0x4d8c
cmpl $0x2, %edx
jne 0x4e00
testq %r15, %r15
je 0x4cb0
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x3231
movq %r14, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4743
leaq 0x16e0(%rip), %rsi      # 0x63ad
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x3db4
movl %r13d, %edi
movq %r12, %rsi
callq 0x4288
testq %rax, %rax
je 0x4d6d
movq %rax, %r15
movq %r14, -0x30(%rbp)
movq %r14, %rdi
movq %rax, %rsi
callq 0x3116
movq %rax, %r14
testq %rax, %rax
jne 0x4d2d
callq 0x4725
movq %rax, %r14
leaq 0x18(%rax), %rdi
callq 0x2290
movups (%rbx), %xmm0
movups %xmm0, 0x8(%r14)
movq -0x30(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3182
movdqu (%rbx), %xmm0
movdqu 0x8(%r14), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x4e1f
movq 0x20(%r14), %rdx
leaq 0x16a0(%rip), %rsi      # 0x63f5
pushq $0x3
popq %rdi
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3db4
leaq 0x1651(%rip), %rsi      # 0x63c5
pushq $0x1
popq %rdi
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3db4
leaq 0x16cb(%rip), %rsi      # 0x645e
pushq $0x1
popq %rbx
movl %ebx, %edi
xorl %eax, %eax
callq 0x3db4
pushq $0x18
popq %rdi
callq 0x23c0
movq %rax, %r15
movq -0x38(%rbp), %rax
movq %rax, (%r15)
movq %r14, 0x8(%r15)
movq -0x30(%rbp), %rax
movq %rax, 0x10(%r15)
leaq -0x78(%rbp), %r14
movq %r14, %rdi
callq 0x2360
movq %r14, %rdi
movl %ebx, %esi
callq 0x23a0
leaq 0x4d(%rip), %rdx        # 0x4e27
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rcx
callq 0x24a0
movq %r14, %rdi
callq 0x2450
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x167b(%rip), %rsi      # 0x6482
pushq $0x4
popq %rdi
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3db4
movq %r14, %rdi
jmp 0x4c77