#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 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;
scalar_t__ v4l_type_is_output(unsigned int);
scalar_t__ v4l_type_is_planar(unsigned int);
unsigned v4l_type_invert(unsigned type) {
  if (v4l_type_is_planar(type))
    return v4l_type_is_output(type) ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
                                    : V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
  return v4l_type_is_output(type) ? V4L2_BUF_TYPE_VIDEO_CAPTURE
                                  : V4L2_BUF_TYPE_VIDEO_OUTPUT;
}


x86 assembly (clang, -O0):
<v4l_type_invert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <v4l_type_is_planar@plt>
cmp    $0x0,%rax
je     1177 <v4l_type_invert+0x57>
mov    -0x8(%rbp),%edi
call   1030 <v4l_type_is_output@plt>
cmp    $0x0,%rax
je     1160 <v4l_type_invert+0x40>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    116c <v4l_type_invert+0x4c>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <v4l_type_invert+0x8c>
mov    -0x8(%rbp),%edi
call   1030 <v4l_type_is_output@plt>
cmp    $0x0,%rax
je     119a <v4l_type_invert+0x7a>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
jmp    11a6 <v4l_type_invert+0x86>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v4l_type_invert>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1040 <v4l_type_is_planar@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1030 <v4l_type_is_output@plt>
test   %r14,%r14
mov    0x2e91(%rip),%rcx
cmove  0x2ea1(%rip),%rcx
mov    0x2eaa(%rip),%rdx
cmove  0x2e82(%rip),%rdx
test   %rax,%rax
cmovne %rcx,%rdx
mov    (%rdx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@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
define i32 @v4l_type_invert(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i64 @v4l_type_is_planar(i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i64 @v4l_type_is_output(i32 %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 %27
17: ; preds = %1
%18 = load i32, i32* %3
%19 = call i64 @v4l_type_is_output(i32 %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
br label %25
23: ; preds = %17
%24 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT
br label %25
25: ; preds = %23, %21
%26 = phi i32 [ %22, %21 ], [ %24, %23 ]
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %15
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@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
define i32 @v4l_type_invert(i32 %0) {
%2 = tail call i64 @v4l_type_is_planar(i32 %0)
%3 = icmp eq i64 %2, 0
%4 = tail call i64 @v4l_type_is_output(i32 %0)
%5 = icmp eq i64 %4, 0
%6 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE
%7 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
%8 = select i1 %3, i32 %6, i32 %7
%9 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT
%10 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
%11 = select i1 %3, i32 %9, i32 %10
%12 = select i1 %5, i32 %11, i32 %8
ret i32 %12
}