// File: /workspace/github_c_makefile_star2_O0/videolan[P]bitstream/examples/./bitstream/mpeg/psi/psi.h
// Function: psi_assemble_payload
static inline uint8_t *psi_assemble_payload(uint8_t **pp_psi_buffer,
                                            uint16_t *pi_psi_buffer_used,
                                            const uint8_t **pp_payload,
                                            uint8_t *pi_length)
{
    uint16_t i_remaining_size = PSI_PRIVATE_MAX_SIZE + PSI_HEADER_SIZE
                                 - *pi_psi_buffer_used;
    uint16_t i_copy_size = *pi_length < i_remaining_size ? *pi_length :
                           i_remaining_size;
    uint8_t *p_section = NULL;

    if (*pp_psi_buffer == NULL) {
        if (**pp_payload == 0xff) {
            /* padding table to the end of buffer */
            *pi_length = 0;
            return NULL;
        }
        *pp_psi_buffer = psi_private_allocate();
    }

    memcpy(*pp_psi_buffer + *pi_psi_buffer_used, *pp_payload, i_copy_size);
    *pi_psi_buffer_used += i_copy_size;

    if (*pi_psi_buffer_used >= PSI_HEADER_SIZE) {
        uint16_t i_section_size = psi_get_length(*pp_psi_buffer)
                                   + PSI_HEADER_SIZE;

        if (i_section_size > PSI_PRIVATE_MAX_SIZE) {
            /* invalid section */
            psi_assemble_reset(pp_psi_buffer, pi_psi_buffer_used);
            *pi_length = 0;
            return NULL;
        }
        if (i_section_size <= *pi_psi_buffer_used) {
            p_section = *pp_psi_buffer;
            i_copy_size -= (*pi_psi_buffer_used - i_section_size);
            *pp_psi_buffer = NULL;
            *pi_psi_buffer_used = 0;
        }
    }

    *pp_payload += i_copy_size;
    *pi_length -= i_copy_size;
    return p_section;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rax
movzwl (%rax), %ecx
movl $0x1000, %eax           # imm = 0x1000
subl %ecx, %eax
movw %ax, -0x2a(%rbp)
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
movzwl -0x2a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x17f5
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0x17fc
movzwl -0x2a(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movw %ax, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1849
movq -0x20(%rbp), %rax
movq (%rax), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
jne 0x183a
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x193f
callq 0x1b60
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cltq
addq %rax, %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movzwl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x10c0
movzwl -0x2c(%rbp), %edx
movq -0x18(%rbp), %rax
movzwl (%rax), %ecx
addl %edx, %ecx
movw %cx, (%rax)
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x3, %eax
jl 0x1914
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x1b70
movzwl %ax, %eax
addl $0x3, %eax
movw %ax, -0x3a(%rbp)
movzwl -0x3a(%rbp), %eax
cmpl $0xffd, %eax            # imm = 0xFFD
jle 0x18cd
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1710
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x193f
movzwl -0x3a(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jg 0x1912
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movzwl (%rax), %ecx
movzwl -0x3a(%rbp), %eax
subl %eax, %ecx
movzwl -0x2c(%rbp), %eax
subl %ecx, %eax
movw %ax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movw $0x0, (%rax)
jmp 0x1914
movzwl -0x2c(%rbp), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, (%rax)
movzwl -0x2c(%rbp), %edx
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
subl %edx, %ecx
movb %cl, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)