// File: /workspace/github_c_makefile_star2_O3/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, %r14d
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, -0x38(%rbp)
movl %r8d, %edi
movq %rcx, %rsi
callq 0x44e4
testb %al, %al
je 0x4fd3
movq %r13, -0x30(%rbp)
leaq 0x2420(%rip), %rsi      # 0x7389
xorl %r15d, %r15d
movl $0x1, %edi
xorl %eax, %eax
callq 0x3fa4
callq 0x49a3
movq %rax, %r13
movq %rax, %rdi
movl %r14d, %esi
movq %r12, %rdx
callq 0x4170
movl (%r13), %edx
testl %edx, %edx
je 0x5109
cmpl $0x1, %edx
je 0x509f
cmpl $0x2, %edx
jne 0x5118
testq %r15, %r15
je 0x4fbd
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x334a
movq %r13, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x49b7
leaq 0x23d3(%rip), %rsi      # 0x73ad
movl $0x1, %edi
xorl %eax, %eax
callq 0x3fa4
movl %r14d, %edi
movq %r12, %rsi
callq 0x44c0
testq %rax, %rax
je 0x507e
movq %rax, %r15
movq %r13, -0x30(%rbp)
movq %r13, %rdi
movq %rax, %rsi
callq 0x3229
movq %rax, %r13
testq %rax, %rax
jne 0x503c
callq 0x49a3
movq %rax, %r13
leaq 0x18(%rax), %rdi
callq 0x2290
movups (%rbx), %xmm0
movups %xmm0, 0x8(%r13)
movq -0x30(%rbp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x3295
movdqu 0x8(%r13), %xmm0
movdqu (%rbx), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x5139
movq 0x20(%r13), %rdx
leaq 0x2391(%rip), %rsi      # 0x73f5
movl $0x3, %edi
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3fa4
leaq 0x2340(%rip), %rsi      # 0x73c5
movl $0x1, %edi
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3fa4
leaq 0x23b8(%rip), %rsi      # 0x745e
movl $0x1, %edi
xorl %eax, %eax
callq 0x3fa4
movl $0x18, %edi
callq 0x23c0
movq %rax, %rbx
movq -0x38(%rbp), %rax
movq %rax, (%rbx)
movq %r13, 0x8(%rbx)
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rbx)
leaq -0x78(%rbp), %r14
movq %r14, %rdi
callq 0x2360
movq %r14, %rdi
movl $0x1, %esi
callq 0x23a0
leaq 0x4f(%rip), %rdx        # 0x5141
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
movq %rbx, %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 0x2363(%rip), %rsi      # 0x7482
movl $0x4, %edi
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3fa4
movq %r13, %rdi
jmp 0x4f83