// File: /workspace/github_c_makefile_star2_O3/michaelforney[P]wld/wayland-shm.c
// Function: context_create_buffer
struct buffer *
context_create_buffer(struct wld_context *base,
                      uint32_t width, uint32_t height,
                      uint32_t format, uint32_t flags)
{
	struct shm_context *context = shm_context(base);
	struct shm_buffer *buffer;
	char name[] = "/tmp/wld-XXXXXX";
	uint32_t pitch = width * format_bytes_per_pixel(format);
	size_t size = pitch * height;
	int fd;
	struct wl_shm_pool *pool;
	struct wl_buffer *wl;

	if (!wayland_has_format(base, format))
		goto error0;

	if (!(buffer = malloc(sizeof *buffer)))
		goto error0;

	fd = mkostemp(name, O_CLOEXEC);

	if (fd < 0)
		goto error1;

	unlink(name);

	if (posix_fallocate(fd, 0, size) != 0 && ftruncate(fd, size) != 0)
		goto error2;

	if (!(pool = wl_shm_create_pool(context->wl, fd, size)))
		goto error2;

	wl = wl_shm_pool_create_buffer(pool, 0, width, height, pitch,
	                               format_wld_to_shm(format));
	wl_shm_pool_destroy(pool);

	if (!wl)
		goto error2;

	buffer_initialize(&buffer->base, &wld_buffer_impl,
	                  width, height, format, pitch);
	buffer->fd = fd;

	if (!(wayland_buffer_add_exporter(&buffer->base, wl)))
		goto error3;

	return &buffer->base;

error3:
	wl_buffer_destroy(wl);
error2:
	close(fd);
error1:
	free(buffer);
error0:
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leaq 0x98c5(%rip), %rax      # 0x17bb8
cmpq %rax, (%rdi)
jne 0xe4e3
movl %ecx, %ebp
movl %edx, %ebx
movl %esi, %r15d
movq %rdi, %r12
movaps 0x3443(%rip), %xmm0     # 0x11750
movaps %xmm0, 0x20(%rsp)
cmpl $0x34325241, %ecx       # imm = 0x34325241
sete %r14b
cmpl $0x34325258, %ecx       # imm = 0x34325258
sete %r13b
movl %ecx, %esi
callq 0xe268
testb %al, %al
je 0xe4cf
movq %rbx, 0x10(%rsp)
movl $0x58, %edi
callq 0x9570
testq %rax, %rax
je 0xe4cf
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
movl $0x80000, %esi          # imm = 0x80000
callq 0x9330
testl %eax, %eax
js 0xe4c7
orb %r13b, %r14b
movzbl %r14b, %r14d
movq %r15, 0x18(%rsp)
imull %r15d, %r14d
shll $0x2, %r14d
movl %r14d, %r13d
imull 0x10(%rsp), %r13d
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0x90c0
movq %r15, 0x8(%rsp)
movl %r15d, %edi
xorl %esi, %esi
movq %r13, %rdx
callq 0x9500
testl %eax, %eax
je 0xe3bc
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x9320
testl %eax, %eax
jne 0xe4bd
movq 0x28(%r12), %r12
movq %r12, %rdi
callq 0x9170
movq 0x9bd8(%rip), %rdx      # 0x17fa8
movq %r12, %rdi
xorl %esi, %esi
movl %eax, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %r13
pushq 0x10(%rsp)
callq 0x9400
addq $0x10, %rsp
testq %rax, %rax
je 0xe4bd
movq %rax, %r12
xorl %r13d, %r13d
cmpl $0x34325258, %ebp       # imm = 0x34325258
sete %r13b
movq %rax, %rdi
callq 0x9170
subq $0x8, %rsp
movq 0x9bb6(%rip), %rdx      # 0x17fd0
movq %r12, %rdi
xorl %esi, %esi
movl %eax, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %r13
pushq %r14
pushq 0x28(%rsp)
pushq 0x38(%rsp)
pushq $0x0
callq 0x9400
addq $0x30, %rsp
movq %rax, %r13
movq %r12, %rdi
callq 0x9170
movq %r12, %rdi
movl $0x1, %esi
xorl %edx, %edx
movl %eax, %ecx
movl $0x1, %r8d
xorl %eax, %eax
callq 0x9400
testq %r13, %r13
je 0xe4bd
leaq 0x9788(%rip), %rsi      # 0x17bf8
movq %rbx, %rdi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movl %ebp, %r8d
movl %r14d, %r9d
callq 0x9bbc
movq 0x8(%rsp), %rax
movl %eax, 0x50(%rbx)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xdf14
testb %al, %al
jne 0xe4d1
movq %r13, %rdi
callq 0x9170
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl %eax, %ecx
movl $0x1, %r8d
xorl %eax, %eax
callq 0x9400
movq 0x8(%rsp), %rdi
callq 0x93c0
movq %rbx, %rdi
callq 0x9060
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x27d9(%rip), %rdi      # 0x10cc3
leaq 0x31d5(%rip), %rsi      # 0x116c6
leaq 0x31dc(%rip), %rcx      # 0x116d4
movl $0x36, %edx
callq 0x9380