// File: /workspace/github_c_makefile_star2_O0/cgaebel[P]pipe/pipe.c
// Function: pipe_new
pipe_t* pipe_new(size_t elem_size, size_t original_limit)
{
    assertume(elem_size != 0);

    if(elem_size == 0)
        return NULL;

    pipe_t* p = malloc(sizeof *p);

    assert(DEFAULT_MINCAP >= 1);

    size_t cap = DEFAULT_MINCAP * elem_size;
    char*  buf = malloc(cap);

    // Change the limit from being in "elements" to being in "bytes", and make
    // room for the sentinel element.
    size_t limit = (original_limit + 1) * elem_size;

    if(unlikely(p == NULL || buf == NULL))
        return free(p), free(buf), NULL;

    *p = (pipe_t) {
        .elem_size  = elem_size,
        .min_cap = cap,
        .max_cap = original_limit ? next_pow2(max(limit, cap)) : ~(size_t)0,

        .buffer = buf,
        .bufend = buf + cap,
        .begin  = buf,
        .end    = buf + elem_size,

        // Since we're issuing a pipe_t, it counts as both a producer and a
        // consumer since it can issue new instances of both. Therefore, the
        // refcounts both start at 1; not the intuitive 0.
        .producer_refcount = 1,
        .consumer_refcount = 1,
    };

    mutex_init(&p->begin_lock);
    mutex_init(&p->end_lock);

    cond_init(&p->just_pushed);
    cond_init(&p->just_popped);

    check_invariants(p);

    return p;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x12cc
jmp 0x12eb
leaq 0x3ef3(%rip), %rdi      # 0x51c6
leaq 0x3d85(%rip), %rsi      # 0x505f
movl $0x223, %edx            # imm = 0x223
leaq 0x3d80(%rip), %rcx      # 0x5066
callq 0x1080
cmpq $0x0, -0x10(%rbp)
jne 0x12ff
movq $0x0, -0x8(%rbp)
jmp 0x1537
movl $0xf8, %edi
callq 0x10f0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
shlq $0x5, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10f0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
imulq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movb $0x1, %al
cmpq $0x0, -0x20(%rbp)
movb %al, -0x131(%rbp)
je 0x1354
cmpq $0x0, -0x30(%rbp)
sete %al
movb %al, -0x131(%rbp)
movb -0x131(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x1386
movq -0x20(%rbp), %rdi
callq 0x1030
movq -0x30(%rbp), %rdi
callq 0x1030
movq $0x0, -0x8(%rbp)
jmp 0x1537
movq -0x20(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x130(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x140(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x13f7
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jb 0x13d7
movq -0x38(%rbp), %rax
movq %rax, -0x150(%rbp)
jmp 0x13e2
movq -0x28(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rdi
callq 0x1550
movq %rax, -0x158(%rbp)
jmp 0x1407
movq $-0x1, %rax
movq %rax, -0x158(%rbp)
jmp 0x1407
movq -0x140(%rbp), %rax
movq -0x158(%rbp), %rcx
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x30(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x30(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
movq $0x1, -0xf8(%rbp)
movq $0x1, -0xf0(%rbp)
leaq -0x130(%rbp), %rdi
addq $0x48, %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x1090
leaq -0x130(%rbp), %rdi
addq $0x70, %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x1090
leaq -0x130(%rbp), %rdi
addq $0x98, %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x1090
leaq -0x130(%rbp), %rdi
addq $0xc8, %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x1090
movq -0x148(%rbp), %rdi
leaq -0x130(%rbp), %rsi
movl $0xf8, %edx
callq 0x10c0
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1150
movq -0x20(%rbp), %rdi
addq $0x70, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1150
movq -0x20(%rbp), %rdi
addq $0x98, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10d0
movq -0x20(%rbp), %rdi
addq $0xc8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10d0
movq -0x20(%rbp), %rdi
callq 0x1610
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopw %cs:(%rax,%rax)