// File: /workspace/github_c_makefile_star2_O0/cgaebel[P]pipe/pipe.c
// Function: trim_buffer
static inline void trim_buffer(pipe_t* p, snapshot_t s)
{
    size_t cap = capacity(s);

    // We have a sane size. We're done here.
    if(likely(bytes_in_use(s) > cap / 4))
    {
        mutex_unlock(&p->begin_lock);
        return;
    }

    // Okay, we need to resize now. Upgrade our lock so we can check again. The
    // weird lock/unlock order is to make sure we always acquire the end_lock
    // before begin_lock. Deadlock can arise otherwise.
    mutex_unlock(&p->begin_lock);
    mutex_lock(&p->end_lock);
    mutex_lock(&p->begin_lock);

    s   = make_snapshot(p);
    cap = capacity(s);

    // To conserve space like the good computizens we are, we'll shrink
    // our buffer if our memory usage efficiency drops below 25%. However,
    // since shrinking/growing the buffer is the most expensive part of a push
    // or pop, we only shrink it to bring us up to a 50% efficiency. A common
    // pipe usage pattern is sudden bursts of pushes and pops. This ensures it
    // doesn't get too time-inefficient.
    if(likely(bytes_in_use(s) <= cap / 4))
        resize_buffer(p, cap / 2);

    // All done. Unlock the pipe. The reason we don't let the calling function
    // unlock begin_lock is so that we can do it BEFORE end_lock. This prevents
    // the lock order from being fudged.
    mutex_unlock(&p->begin_lock);
    mutex_unlock(&p->end_lock);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
leaq 0x10(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movq %rdi, -0x8(%rbp)
movq 0x20(%rcx), %rdx
movq %rsp, %rax
movq %rdx, 0x20(%rax)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x2490
movq -0x68(%rbp), %rcx
movq %rax, -0x10(%rbp)
movq 0x20(%rcx), %rdx
movq %rsp, %rax
movq %rdx, 0x20(%rax)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x24b0
movq -0x10(%rbp), %rcx
shrq $0x2, %rcx
cmpq %rcx, %rax
seta %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x304c
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x10e0
jmp 0x3127
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x10e0
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
callq 0x1160
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x1160
movq -0x8(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x29a0
movq -0x68(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movl $0x28, %edx
callq 0x10c0
movq -0x68(%rbp), %rcx
movq 0x20(%rcx), %rdx
movq %rsp, %rax
movq %rdx, 0x20(%rax)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x2490
movq -0x68(%rbp), %rcx
movq %rax, -0x10(%rbp)
movq 0x20(%rcx), %rdx
movq %rsp, %rax
movq %rdx, 0x20(%rax)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x24b0
movq -0x10(%rbp), %rcx
shrq $0x2, %rcx
cmpq %rcx, %rax
setbe %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x310d
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
shrq %rdx
leaq -0x60(%rbp), %rdi
callq 0x2a10
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x10e0
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
callq 0x10e0
addq $0x90, %rsp
popq %rbp
retq