#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct v4l2_buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ VIDIOC_QBUF;
int /*<<< orphan*/ errno;
int xioctl(int, int /*<<< orphan*/, struct v4l2_buffer *);
int enqueue_frame(int fd, struct v4l2_buffer *buf) {
  if (fd < 0 || buf == NULL) {
    errno = EINVAL;
    return -1;
  }
  return xioctl(fd, VIDIOC_QBUF, buf);
}


x86 assembly (clang, -O0):
<enqueue_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1134 <enqueue_frame+0x24>
cmpq   $0x0,-0x10(%rbp)
jne    1152 <enqueue_frame+0x42>
mov    0x2e9d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e9c(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    116a <enqueue_frame+0x5a>
mov    -0x8(%rbp),%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <xioctl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enqueue_frame>:
test   %edi,%edi
js     112a <enqueue_frame+0x1a>
mov    %rsi,%rdx
test   %rsi,%rsi
je     112a <enqueue_frame+0x1a>
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
jmp    1030 <xioctl@plt>
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    0x2ea6(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.v4l2_buffer = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@VIDIOC_QBUF = global i32 0
define i32 @enqueue_frame(i32 %0, %struct.v4l2_buffer* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.v4l2_buffer*
store i32 %0, i32* %4
store %struct.v4l2_buffer* %1, %struct.v4l2_buffer** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load %struct.v4l2_buffer*, %struct.v4l2_buffer** %5
%10 = icmp eq %struct.v4l2_buffer* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = load i32, i32* @EINVAL
store i32 %12, i32* @errno
store i32 -1, i32* %3
br label %18
13: ; preds = %8
%14 = load i32, i32* %4
%15 = load i32, i32* @VIDIOC_QBUF
%16 = load %struct.v4l2_buffer*, %struct.v4l2_buffer** %5
%17 = call i32 @xioctl(i32 %14, i32 %15, %struct.v4l2_buffer* %16)
store i32 %17, i32* %3
br label %18
18: ; preds = %13, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.v4l2_buffer = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@VIDIOC_QBUF = global i32 0
define i32 @enqueue_frame(i32 %0, %struct.v4l2_buffer* %1) {
%3 = icmp slt i32 %0, 0
%4 = icmp eq %struct.v4l2_buffer* %1, null
%5 = or i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %11
8: ; preds = %2
%9 = load i32, i32* @VIDIOC_QBUF
%10 = tail call i32 @xioctl(i32 %0, i32 %9, %struct.v4l2_buffer* %1)
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ -1, %6 ], [ %10, %8 ]
ret i32 %12
}