// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x11c30
movq %rax, -0x28(%rbp)
movq 0x3870(%rip), %rax      # 0x15270
movq %rax, -0x40(%rbp)
movq 0x386d(%rip), %rax      # 0x15278
movq %rax, -0x38(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x1c(%rbp), %edi
callq 0x11c80
movb %al, %cl
movl -0x6c(%rbp), %eax
movzbl %cl, %ecx
imull %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
imull -0x18(%rbp), %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x11850
testb $0x1, %al
jne 0x11a4d
jmp 0x11b8a
movl $0x58, %edi
callq 0x9590
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x11a66
jmp 0x11b8a
leaq -0x40(%rbp), %rdi
movl $0x80000, %esi          # imm = 0x80000
callq 0x9340
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jge 0x11a82
jmp 0x11b81
leaq -0x40(%rbp), %rdi
callq 0x90c0
movl -0x54(%rbp), %edi
movq -0x50(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x9520
cmpl $0x0, %eax
je 0x11ab6
movl -0x54(%rbp), %edi
movq -0x50(%rbp), %rsi
callq 0x9330
cmpl $0x0, %eax
je 0x11ab6
jmp 0x11b79
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rdi
movl -0x54(%rbp), %esi
movq -0x50(%rbp), %rax
movl %eax, %edx
callq 0x11cc0
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
jne 0x11adb
jmp 0x11b79
movq -0x60(%rbp), %rax
movq %rax, -0x80(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x1c(%rbp), %edi
callq 0x11db0
movq -0x80(%rbp), %rdi
movl -0x78(%rbp), %edx
movl -0x74(%rbp), %ecx
movl -0x70(%rbp), %r8d
movl %eax, %r9d
xorl %esi, %esi
callq 0x11d20
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
callq 0x11df0
cmpq $0x0, -0x68(%rbp)
jne 0x11b2b
jmp 0x11b79
movq -0x30(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl -0x1c(%rbp), %r8d
movl -0x44(%rbp), %r9d
leaq 0xa0b4(%rip), %rsi      # 0x1bbf8
callq 0x99b0
movl -0x54(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x30(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x112a0
testb $0x1, %al
jne 0x11b66
jmp 0x11b70
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x11b92
movq -0x68(%rbp), %rdi
callq 0x11e30
movl -0x54(%rbp), %edi
callq 0x93e0
movq -0x30(%rbp), %rdi
callq 0x9060
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nop