#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 v4l_fd {
  int dummy;
};
typedef int /*<<< orphan*/ __u32;

/* Variables and functions */
int /*<<< orphan*/ V4L2_BUF_TYPE_SDR_CAPTURE;
int /*<<< orphan*/ V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
int /*<<< orphan*/ V4L2_BUF_TYPE_SLICED_VBI_OUTPUT;
int /*<<< orphan*/ V4L2_BUF_TYPE_VBI_CAPTURE;
int /*<<< orphan*/ V4L2_BUF_TYPE_VBI_OUTPUT;
int /*<<< orphan*/ V4L2_BUF_TYPE_VIDEO_CAPTURE;
int /*<<< orphan*/ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
int /*<<< orphan*/ V4L2_BUF_TYPE_VIDEO_OUTPUT;
int /*<<< orphan*/ V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
scalar_t__ v4l_has_raw_vbi_cap(struct v4l_fd const *);
scalar_t__ v4l_has_raw_vbi_out(struct v4l_fd const *);
scalar_t__ v4l_has_sdr_cap(struct v4l_fd const *);
scalar_t__ v4l_has_sliced_vbi_cap(struct v4l_fd const *);
scalar_t__ v4l_has_sliced_vbi_out(struct v4l_fd const *);
scalar_t__ v4l_has_vid_cap(struct v4l_fd const *);
scalar_t__ v4l_has_vid_mplane(struct v4l_fd const *);
scalar_t__ v4l_has_vid_out(struct v4l_fd const *);
__u32 v4l_determine_type(const struct v4l_fd *f) {
  if (v4l_has_vid_mplane(f))
    return v4l_has_vid_cap(f) ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
                              : V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
  if (v4l_has_vid_cap(f))
    return V4L2_BUF_TYPE_VIDEO_CAPTURE;
  if (v4l_has_vid_out(f))
    return V4L2_BUF_TYPE_VIDEO_OUTPUT;
  if (v4l_has_raw_vbi_cap(f))
    return V4L2_BUF_TYPE_VBI_CAPTURE;
  if (v4l_has_sliced_vbi_cap(f))
    return V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
  if (v4l_has_raw_vbi_out(f))
    return V4L2_BUF_TYPE_VBI_OUTPUT;
  if (v4l_has_sliced_vbi_out(f))
    return V4L2_BUF_TYPE_SLICED_VBI_OUTPUT;
  if (v4l_has_sdr_cap(f))
    return V4L2_BUF_TYPE_SDR_CAPTURE;
  return 0;
}


x86 assembly (clang, -O0):
<v4l_determine_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <v4l_has_vid_mplane@plt>
cmp    $0x0,%rax
je     11da <v4l_determine_type+0x5a>
mov    -0x10(%rbp),%rdi
call   1060 <v4l_has_vid_cap@plt>
cmp    $0x0,%rax
je     11c3 <v4l_determine_type+0x43>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    11cf <v4l_determine_type+0x4f>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12dd <v4l_determine_type+0x15d>
mov    -0x10(%rbp),%rdi
call   1060 <v4l_has_vid_cap@plt>
cmp    $0x0,%rax
je     11fe <v4l_determine_type+0x7e>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12dd <v4l_determine_type+0x15d>
mov    -0x10(%rbp),%rdi
call   1090 <v4l_has_vid_out@plt>
cmp    $0x0,%rax
je     1222 <v4l_determine_type+0xa2>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12dd <v4l_determine_type+0x15d>
mov    -0x10(%rbp),%rdi
call   1050 <v4l_has_raw_vbi_cap@plt>
cmp    $0x0,%rax
je     1246 <v4l_determine_type+0xc6>
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12dd <v4l_determine_type+0x15d>
mov    -0x10(%rbp),%rdi
call   1070 <v4l_has_sliced_vbi_cap@plt>
cmp    $0x0,%rax
je     126a <v4l_determine_type+0xea>
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12dd <v4l_determine_type+0x15d>
mov    -0x10(%rbp),%rdi
call   10a0 <v4l_has_raw_vbi_out@plt>
cmp    $0x0,%rax
je     128e <v4l_determine_type+0x10e>
mov    0x2d24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12dd <v4l_determine_type+0x15d>
mov    -0x10(%rbp),%rdi
call   1030 <v4l_has_sliced_vbi_out@plt>
cmp    $0x0,%rax
je     12b2 <v4l_determine_type+0x132>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12dd <v4l_determine_type+0x15d>
mov    -0x10(%rbp),%rdi
call   1080 <v4l_has_sdr_cap@plt>
cmp    $0x0,%rax
je     12d6 <v4l_determine_type+0x156>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12dd <v4l_determine_type+0x15d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v4l_determine_type>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <v4l_has_vid_mplane@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <v4l_has_vid_cap@plt>
test   %rbx,%rbx
je     11ad <v4l_determine_type+0x2d>
test   %rax,%rax
jne    11be <v4l_determine_type+0x3e>
mov    0x2e50(%rip),%rax
jmp    1251 <v4l_determine_type+0xd1>
test   %rax,%rax
je     11ca <v4l_determine_type+0x4a>
mov    0x2e2f(%rip),%rax
jmp    1251 <v4l_determine_type+0xd1>
mov    0x2e03(%rip),%rax
jmp    1251 <v4l_determine_type+0xd1>
mov    %r14,%rdi
call   1090 <v4l_has_vid_out@plt>
test   %rax,%rax
je     11e0 <v4l_determine_type+0x60>
mov    0x2dfa(%rip),%rax
jmp    1251 <v4l_determine_type+0xd1>
mov    %r14,%rdi
call   1050 <v4l_has_raw_vbi_cap@plt>
test   %rax,%rax
je     11f6 <v4l_determine_type+0x76>
mov    0x2dcc(%rip),%rax
jmp    1251 <v4l_determine_type+0xd1>
mov    %r14,%rdi
call   1070 <v4l_has_sliced_vbi_cap@plt>
test   %rax,%rax
je     120c <v4l_determine_type+0x8c>
mov    0x2d96(%rip),%rax
jmp    1251 <v4l_determine_type+0xd1>
mov    %r14,%rdi
call   10a0 <v4l_has_raw_vbi_out@plt>
test   %rax,%rax
je     1222 <v4l_determine_type+0xa2>
mov    0x2d88(%rip),%rax
jmp    1251 <v4l_determine_type+0xd1>
mov    %r14,%rdi
call   1030 <v4l_has_sliced_vbi_out@plt>
test   %rax,%rax
je     1238 <v4l_determine_type+0xb8>
mov    0x2d9a(%rip),%rax
jmp    1251 <v4l_determine_type+0xd1>
mov    %r14,%rdi
call   1080 <v4l_has_sdr_cap@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1253 <v4l_determine_type+0xd3>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.v4l_fd = type { i32 }
@V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = global i32 0
@V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = global i32 0
@V4L2_BUF_TYPE_VIDEO_CAPTURE = global i32 0
@V4L2_BUF_TYPE_VIDEO_OUTPUT = global i32 0
@V4L2_BUF_TYPE_VBI_CAPTURE = global i32 0
@V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = global i32 0
@V4L2_BUF_TYPE_VBI_OUTPUT = global i32 0
@V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = global i32 0
@V4L2_BUF_TYPE_SDR_CAPTURE = global i32 0
define i32 @v4l_determine_type(%struct.v4l_fd* %0) {
%2 = alloca i32
%3 = alloca %struct.v4l_fd*
store %struct.v4l_fd* %0, %struct.v4l_fd** %3
%4 = load %struct.v4l_fd*, %struct.v4l_fd** %3
%5 = call i64 @v4l_has_vid_mplane(%struct.v4l_fd* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = load %struct.v4l_fd*, %struct.v4l_fd** %3
%9 = call i64 @v4l_has_vid_cap(%struct.v4l_fd* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
br label %15
13: ; preds = %7
%14 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %12, %11 ], [ %14, %13 ]
store i32 %16, i32* %2
br label %60
17: ; preds = %1
%18 = load %struct.v4l_fd*, %struct.v4l_fd** %3
%19 = call i64 @v4l_has_vid_cap(%struct.v4l_fd* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE
store i32 %22, i32* %2
br label %60
23: ; preds = %17
%24 = load %struct.v4l_fd*, %struct.v4l_fd** %3
%25 = call i64 @v4l_has_vid_out(%struct.v4l_fd* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT
store i32 %28, i32* %2
br label %60
29: ; preds = %23
%30 = load %struct.v4l_fd*, %struct.v4l_fd** %3
%31 = call i64 @v4l_has_raw_vbi_cap(%struct.v4l_fd* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = load i32, i32* @V4L2_BUF_TYPE_VBI_CAPTURE
store i32 %34, i32* %2
br label %60
35: ; preds = %29
%36 = load %struct.v4l_fd*, %struct.v4l_fd** %3
%37 = call i64 @v4l_has_sliced_vbi_cap(%struct.v4l_fd* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load i32, i32* @V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
store i32 %40, i32* %2
br label %60
41: ; preds = %35
%42 = load %struct.v4l_fd*, %struct.v4l_fd** %3
%43 = call i64 @v4l_has_raw_vbi_out(%struct.v4l_fd* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = load i32, i32* @V4L2_BUF_TYPE_VBI_OUTPUT
store i32 %46, i32* %2
br label %60
47: ; preds = %41
%48 = load %struct.v4l_fd*, %struct.v4l_fd** %3
%49 = call i64 @v4l_has_sliced_vbi_out(%struct.v4l_fd* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = load i32, i32* @V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
store i32 %52, i32* %2
br label %60
53: ; preds = %47
%54 = load %struct.v4l_fd*, %struct.v4l_fd** %3
%55 = call i64 @v4l_has_sdr_cap(%struct.v4l_fd* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = load i32, i32* @V4L2_BUF_TYPE_SDR_CAPTURE
store i32 %58, i32* %2
br label %60
59: ; preds = %53
store i32 0, i32* %2
br label %60
60: ; preds = %59, %57, %51, %45, %39, %33, %27, %21, %15
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
%struct.v4l_fd = type { i32 }
@V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = global i32 0
@V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = global i32 0
@V4L2_BUF_TYPE_VIDEO_CAPTURE = global i32 0
@V4L2_BUF_TYPE_VIDEO_OUTPUT = global i32 0
@V4L2_BUF_TYPE_VBI_CAPTURE = global i32 0
@V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = global i32 0
@V4L2_BUF_TYPE_VBI_OUTPUT = global i32 0
@V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = global i32 0
@V4L2_BUF_TYPE_SDR_CAPTURE = global i32 0
define i32 @v4l_determine_type(%struct.v4l_fd* %0) {
%2 = tail call i64 @v4l_has_vid_mplane(%struct.v4l_fd* %0)
%3 = icmp eq i64 %2, 0
%4 = tail call i64 @v4l_has_vid_cap(%struct.v4l_fd* %0)
%5 = icmp eq i64 %4, 0
br i1 %3, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
%8 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
%9 = select i1 %5, i32 %8, i32 %7
br label %43
10: ; preds = %1
br i1 %5, label %13, label %11
11: ; preds = %10
%12 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE
br label %43
13: ; preds = %10
%14 = tail call i64 @v4l_has_vid_out(%struct.v4l_fd* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT
br label %43
18: ; preds = %13
%19 = tail call i64 @v4l_has_raw_vbi_cap(%struct.v4l_fd* %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = load i32, i32* @V4L2_BUF_TYPE_VBI_CAPTURE
br label %43
23: ; preds = %18
%24 = tail call i64 @v4l_has_sliced_vbi_cap(%struct.v4l_fd* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = load i32, i32* @V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
br label %43
28: ; preds = %23
%29 = tail call i64 @v4l_has_raw_vbi_out(%struct.v4l_fd* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = load i32, i32* @V4L2_BUF_TYPE_VBI_OUTPUT
br label %43
33: ; preds = %28
%34 = tail call i64 @v4l_has_sliced_vbi_out(%struct.v4l_fd* %0)
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = load i32, i32* @V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
br label %43
38: ; preds = %33
%39 = tail call i64 @v4l_has_sdr_cap(%struct.v4l_fd* %0)
%40 = icmp eq i64 %39, 0
%41 = load i32, i32* @V4L2_BUF_TYPE_SDR_CAPTURE
%42 = select i1 %40, i32 0, i32 %41
br label %43
43: ; preds = %38, %36, %31, %26, %21, %16, %11, %6
%44 = phi i32 [ %9, %6 ], [ %12, %11 ], [ %17, %16 ], [ %22, %21 ], [ %27, %26 ], [ %32, %31 ], [ %37, %36 ], [ %42, %38 ]
ret i32 %44
}