// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movl %ecx, %ebp
movl %edx, %ebx
movl %esi, %r15d
movq %rdi, %r12
callq 0xdb3c
movaps 0x3e31(%rip), %xmm0     # 0x11760
movaps %xmm0, 0x40(%rsp)
cmpl $0x34325241, %ebp       # imm = 0x34325241
sete %r14b
cmpl $0x34325258, %ebp       # imm = 0x34325258
sete %r13b
movq %r12, %rdi
movl %ebp, %esi
callq 0xd8ba
testb %al, %al
je 0xdaef
movl %ebx, 0x38(%rsp)
pushq $0x58
popq %rdi
callq 0x9570
testq %rax, %rax
je 0xdaef
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
movl $0x80000, %esi          # imm = 0x80000
callq 0x9330
testl %eax, %eax
js 0xdae7
orb %r13b, %r14b
movzbl %r14b, %r13d
movl %r15d, 0x3c(%rsp)
imull %r15d, %r13d
shll $0x2, %r13d
movl %r13d, %r14d
imull 0x38(%rsp), %r14d
movl %eax, %r15d
leaq 0x40(%rsp), %rdi
callq 0x90c0
movl %r15d, 0x34(%rsp)
movl %r15d, %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0x9500
testl %eax, %eax
je 0xd9dd
movl 0x34(%rsp), %edi
movq %r14, %rsi
callq 0x9320
testl %eax, %eax
jne 0xdade
movq 0x28(%r12), %r12
movq %r12, %rdi
callq 0x9170
movl %r14d, 0x8(%rsp)
movl 0x34(%rsp), %ecx
movl %ecx, (%rsp)
movq 0xb5ab(%rip), %rdx      # 0x18fa8
movq %r12, %rdi
xorl %esi, %esi
movl %eax, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x9400
testq %rax, %rax
je 0xdade
movq %rax, %r12
xorl %r14d, %r14d
cmpl $0x34325258, %ebp       # imm = 0x34325258
sete %r14b
movq %rax, %rdi
callq 0x9170
movl %r14d, 0x20(%rsp)
movl %r13d, 0x18(%rsp)
movl 0x38(%rsp), %ecx
movl %ecx, 0x10(%rsp)
movl 0x3c(%rsp), %ecx
movl %ecx, 0x8(%rsp)
andl $0x0, (%rsp)
movq 0xb579(%rip), %rdx      # 0x18fd0
movq %r12, %rdi
xorl %esi, %esi
movl %eax, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x9400
movq %rax, %r14
movq %r12, %rdi
callq 0x9170
pushq $0x1
popq %rsi
movq %r12, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl %esi, %r8d
xorl %eax, %eax
callq 0x9400
testq %r14, %r14
je 0xdade
leaq 0xb162(%rip), %rsi      # 0x18bf8
movq %rbx, %rdi
movl 0x3c(%rsp), %edx
movl 0x38(%rsp), %ecx
movl %ebp, %r8d
movl %r13d, %r9d
callq 0x998c
movl 0x34(%rsp), %eax
movl %eax, 0x50(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd55f
testb %al, %al
jne 0xdaf1
movq %r14, %rdi
callq 0x9170
pushq $0x1
popq %r8
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x9400
movl 0x34(%rsp), %edi
callq 0x93c0
movq %rbx, %rdi
callq 0x9060
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq