// File: /workspace/github_c_makefile_star2_O2/TimeToogo[P]ff-proxy/src/parser.c
// Function: ff_request_parse_options_from_payload
void ff_request_parse_options_from_payload(struct ff_request *request)
{
    assert(request != NULL);
    assert(request->payload != NULL);
    assert(request->payload->next == NULL);

    struct ff_request_payload_node *payload = NULL;
    size_t options_length = 0;

    request->state = FF_REQUEST_STATE_PARSING_OPTIONS;

    if (!request->payload_contains_options)
    {
        goto done;
    }

    payload = request->payload;
    options_length = ff_request_parse_options(request, payload->length, payload->value);

    if (options_length == 0)
    {
        request->state = FF_REQUEST_STATE_PARSING_OPTIONS_FAILED;
        return;
    }

    if (request->payload->length <= options_length)
    {
        ff_log(FF_WARNING, "Request buffer ran out of buffer while parsing options within payload");
        goto error;
    }

    if (request->payload_contains_options)
    {
        ff_log(FF_WARNING, "Request cannot contain multiple FF_REQUEST_OPTION_TYPE_BREAK options");
        goto error;
    }

    struct ff_request_payload_node *new_payload = ff_request_payload_node_alloc();
    new_payload->length = payload->length - options_length;
    ff_request_payload_load_buff(new_payload, new_payload->length, payload->value + options_length);

    request->payload = new_payload;
    request->payload_length = new_payload->length;

    goto done;

done:
    request->state = FF_REQUEST_STATE_PARSED_OPTIONS;
    goto cleanup;

error:
    request->state = FF_REQUEST_STATE_PARSING_OPTIONS_FAILED;
    goto cleanup;

cleanup:
    ff_request_payload_node_free(payload);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x45c8
movq %rdi, %rbx
movq 0x50(%rdi), %r14
testq %r14, %r14
je 0x45e7
cmpq $0x0, 0x10(%r14)
jne 0x4606
movl $0x6, (%rbx)
pushq $0x7
popq %r13
cmpb $0x1, 0x38(%rbx)
jne 0x4548
movzwl 0x2(%r14), %esi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0x4363
testq %rax, %rax
je 0x454d
movq %rax, %r15
movq 0x50(%rbx), %rax
movzwl 0x2(%rax), %eax
cmpq %rax, %r15
jae 0x4562
cmpb $0x1, 0x38(%rbx)
jne 0x4579
leaq 0x1c66(%rip), %rsi      # 0x61ac
jmp 0x4569
xorl %r14d, %r14d
jmp 0x45af
movl $0x8, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bfd(%rip), %rsi      # 0x6166
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x3db4
pushq $0x8
popq %r13
jmp 0x45af
callq 0x46a8
movq %rax, %r12
movzwl 0x2(%r14), %eax
subl %r15d, %eax
movw %ax, 0x2(%r12)
movzwl %ax, %esi
addq 0x8(%r14), %r15
movq %r12, %rdi
movq %r15, %rdx
callq 0x46c0
movq %r12, 0x50(%rbx)
movzwl 0x2(%r12), %eax
movq %rax, 0x40(%rbx)
movl %r13d, (%rbx)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x46ff
leaq 0x1b02(%rip), %rdi      # 0x60d1
leaq 0x1b0b(%rip), %rsi      # 0x60e1
leaq 0x1b11(%rip), %rcx      # 0x60ee
movl $0x171, %edx            # imm = 0x171
callq 0x21e0
leaq 0x1b40(%rip), %rdi      # 0x612e
leaq 0x1aec(%rip), %rsi      # 0x60e1
leaq 0x1af2(%rip), %rcx      # 0x60ee
movl $0x172, %edx            # imm = 0x172
callq 0x21e0
leaq 0x1b3a(%rip), %rdi      # 0x6147
leaq 0x1acd(%rip), %rsi      # 0x60e1
leaq 0x1ad3(%rip), %rcx      # 0x60ee
movl $0x173, %edx            # imm = 0x173
callq 0x21e0
nopl (%rax)