#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 */

/* Variables and functions */
int EINVAL;
int V4L2_BUF_TYPE_VIDEO_CAPTURE;
int V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
int V4L2_BUF_TYPE_VIDEO_OUTPUT;
int V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
unsigned int V4L2_CAP_VIDEO_CAPTURE;
unsigned int V4L2_CAP_VIDEO_CAPTURE_MPLANE;
unsigned int V4L2_CAP_VIDEO_OUTPUT;
unsigned int V4L2_CAP_VIDEO_OUTPUT_MPLANE;
int /*<<< orphan*/ printf(char *);
int cap_get_buf_type(unsigned int capabilities) {
  if (capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) {
    return V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
  } else if (capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE) {
    return V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
  } else if (capabilities & V4L2_CAP_VIDEO_CAPTURE) {
    return V4L2_BUF_TYPE_VIDEO_CAPTURE;
  } else if (capabilities & V4L2_CAP_VIDEO_OUTPUT) {
    return V4L2_BUF_TYPE_VIDEO_OUTPUT;
  } else {
    printf("Device supports neither capture nor output.\n");
    return -EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cap_get_buf_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2ebb(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1141 <cap_get_buf_type+0x31>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <cap_get_buf_type+0xbd>
mov    -0x8(%rbp),%eax
mov    0x2e55(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1167 <cap_get_buf_type+0x57>
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <cap_get_buf_type+0xbd>
mov    -0x8(%rbp),%eax
mov    0x2e57(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     118d <cap_get_buf_type+0x7d>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <cap_get_buf_type+0xbd>
mov    -0x8(%rbp),%eax
mov    0x2e29(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b3 <cap_get_buf_type+0xa3>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <cap_get_buf_type+0xbd>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    0x2de0(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cap_get_buf_type>:
push   %rax
mov    0x2ec8(%rip),%rax
test   %edi,(%rax)
je     1125 <cap_get_buf_type+0x15>
mov    0x2e95(%rip),%rax
jmp    115f <cap_get_buf_type+0x4f>
mov    0x2e74(%rip),%rax
test   %edi,(%rax)
je     1139 <cap_get_buf_type+0x29>
mov    0x2ec1(%rip),%rax
jmp    115f <cap_get_buf_type+0x4f>
mov    0x2e88(%rip),%rax
test   %edi,(%rax)
je     114d <cap_get_buf_type+0x3d>
mov    0x2e9d(%rip),%rax
jmp    115f <cap_get_buf_type+0x4f>
mov    0x2e6c(%rip),%rax
test   %edi,(%rax)
je     1163 <cap_get_buf_type+0x53>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e32(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rcx
ret

LLVM IR (-O0):
@V4L2_CAP_VIDEO_CAPTURE_MPLANE = global i32 0
@V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = global i32 0
@V4L2_CAP_VIDEO_OUTPUT_MPLANE = global i32 0
@V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = global i32 0
@V4L2_CAP_VIDEO_CAPTURE = global i32 0
@V4L2_BUF_TYPE_VIDEO_CAPTURE = global i32 0
@V4L2_CAP_VIDEO_OUTPUT = global i32 0
@V4L2_BUF_TYPE_VIDEO_OUTPUT = global i32 0
@.str = [45 x i8] c"Device supports neither capture nor output.\0A\00"
@EINVAL = global i32 0
define i32 @cap_get_buf_type(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @V4L2_CAP_VIDEO_CAPTURE_MPLANE
%6 = and i32 %4, %5
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
store i32 %9, i32* %2
br label %35
10: ; preds = %1
%11 = load i32, i32* %3
%12 = load i32, i32* @V4L2_CAP_VIDEO_OUTPUT_MPLANE
%13 = and i32 %11, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
store i32 %16, i32* %2
br label %35
17: ; preds = %10
%18 = load i32, i32* %3
%19 = load i32, i32* @V4L2_CAP_VIDEO_CAPTURE
%20 = and i32 %18, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE
store i32 %23, i32* %2
br label %35
24: ; preds = %17
%25 = load i32, i32* %3
%26 = load i32, i32* @V4L2_CAP_VIDEO_OUTPUT
%27 = and i32 %25, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT
store i32 %30, i32* %2
br label %35
31: ; preds = %24
%32 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @EINVAL
%34 = sub nsw i32 0, %33
store i32 %34, i32* %2
br label %35
35: ; preds = %31, %29, %22, %15, %8
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@V4L2_CAP_VIDEO_CAPTURE_MPLANE = global i32 0
@V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = global i32 0
@V4L2_CAP_VIDEO_OUTPUT_MPLANE = global i32 0
@V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = global i32 0
@V4L2_CAP_VIDEO_CAPTURE = global i32 0
@V4L2_BUF_TYPE_VIDEO_CAPTURE = global i32 0
@V4L2_CAP_VIDEO_OUTPUT = global i32 0
@V4L2_BUF_TYPE_VIDEO_OUTPUT = global i32 0
@EINVAL = global i32 0
@str = [44 x i8] c"Device supports neither capture nor output.\00"
define i32 @cap_get_buf_type(i32 %0) {
%2 = load i32, i32* @V4L2_CAP_VIDEO_CAPTURE_MPLANE
%3 = and i32 %2, %0
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
br label %29
7: ; preds = %1
%8 = load i32, i32* @V4L2_CAP_VIDEO_OUTPUT_MPLANE
%9 = and i32 %8, %0
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
br label %29
13: ; preds = %7
%14 = load i32, i32* @V4L2_CAP_VIDEO_CAPTURE
%15 = and i32 %14, %0
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE
br label %29
19: ; preds = %13
%20 = load i32, i32* @V4L2_CAP_VIDEO_OUTPUT
%21 = and i32 %20, %0
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT
br label %29
25: ; preds = %19
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%27 = load i32, i32* @EINVAL
%28 = sub nsw i32 0, %27
br label %29
29: ; preds = %25, %23, %17, %11, %5
%30 = phi i32 [ %6, %5 ], [ %12, %11 ], [ %18, %17 ], [ %24, %23 ], [ %28, %25 ]
ret i32 %30
}