#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 dmx_pes_filter_params {
  int pid;
  int /*<<< orphan*/ flags;
  int /*<<< orphan*/ pes_type;
  int /*<<< orphan*/ output;
  int /*<<< orphan*/ input;
};
typedef int /*<<< orphan*/ filter;

/* Variables and functions */
int /*<<< orphan*/ DMX_IMMEDIATE_START;
int /*<<< orphan*/ DMX_IN_DVR;
int /*<<< orphan*/ DMX_IN_FRONTEND;
int /*<<< orphan*/ DMX_OUT_DECODER;
int /*<<< orphan*/ DMX_OUT_TAP;
int /*<<< orphan*/ DMX_OUT_TS_TAP;
int /*<<< orphan*/ DMX_PES_AUDIO;
int /*<<< orphan*/ DMX_PES_PCR;
int /*<<< orphan*/ DMX_PES_SUBTITLE;
int /*<<< orphan*/ DMX_PES_TELETEXT;
int /*<<< orphan*/ DMX_PES_VIDEO;
int /*<<< orphan*/ DMX_SET_PES_FILTER;
int EINVAL;
int ioctl(int, int /*<<< orphan*/, struct dmx_pes_filter_params *);
int /*<<< orphan*/ memset(struct dmx_pes_filter_params *, int /*<<< orphan*/,
                          int);
int dvbdemux_set_pes_filter(int fd, int pid, int input, int output, int pestype,
                            int start) {
  struct dmx_pes_filter_params filter;
  memset(&filter, 0, sizeof(filter));
  filter.pid = pid;
  switch (input) {
  case 0:
    filter.input = DMX_IN_FRONTEND;
    break;
  case 1:
    filter.input = DMX_IN_DVR;
    break;
  default:
    return -EINVAL;
  }
  switch (output) {
  case 0:
    filter.output = DMX_OUT_DECODER;
    break;
  case 1:
    filter.output = DMX_OUT_TAP;
    break;
  case 2:
    filter.output = DMX_OUT_TS_TAP;
    break;
  default:
    return -EINVAL;
  }
  switch (pestype) {
  case 0:
    filter.pes_type = DMX_PES_AUDIO;
    break;
  case 1:
    filter.pes_type = DMX_PES_VIDEO;
    break;
  case 2:
    filter.pes_type = DMX_PES_TELETEXT;
    break;
  case 3:
    filter.pes_type = DMX_PES_SUBTITLE;
    break;
  case 4:
    filter.pes_type = DMX_PES_PCR;
    break;
  default:
    return -EINVAL;
  }
  if (start)
    filter.flags |= DMX_IMMEDIATE_START;
  return ioctl(fd, DMX_SET_PES_FILTER, &filter);
}


x86 assembly (clang, -O0):
<dvbdemux_set_pes_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     1176 <dvbdemux_set_pes_filter+0x56>
jmp    1165 <dvbdemux_set_pes_filter+0x45>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1187 <dvbdemux_set_pes_filter+0x67>
jmp    1198 <dvbdemux_set_pes_filter+0x78>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    11ab <dvbdemux_set_pes_filter+0x8b>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    11ab <dvbdemux_set_pes_filter+0x8b>
xor    %eax,%eax
mov    0x2e0f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12e4 <dvbdemux_set_pes_filter+0x1c4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
test   %eax,%eax
je     11e0 <dvbdemux_set_pes_filter+0xc0>
jmp    11be <dvbdemux_set_pes_filter+0x9e>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
je     11f1 <dvbdemux_set_pes_filter+0xd1>
jmp    11cf <dvbdemux_set_pes_filter+0xaf>
mov    -0x38(%rbp),%eax
sub    $0x2,%eax
je     1202 <dvbdemux_set_pes_filter+0xe2>
jmp    1213 <dvbdemux_set_pes_filter+0xf3>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1226 <dvbdemux_set_pes_filter+0x106>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1226 <dvbdemux_set_pes_filter+0x106>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1226 <dvbdemux_set_pes_filter+0x106>
xor    %eax,%eax
mov    0x2d94(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12e4 <dvbdemux_set_pes_filter+0x1c4>
mov    -0x18(%rbp),%eax
mov    %rax,-0x40(%rbp)
sub    $0x4,%rax
ja     12a0 <dvbdemux_set_pes_filter+0x180>
mov    -0x40(%rbp),%rax
lea    0xdbe(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    12b3 <dvbdemux_set_pes_filter+0x193>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    12b3 <dvbdemux_set_pes_filter+0x193>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    12b3 <dvbdemux_set_pes_filter+0x193>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    12b3 <dvbdemux_set_pes_filter+0x193>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    12b3 <dvbdemux_set_pes_filter+0x193>
xor    %eax,%eax
mov    0x2d07(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12e4 <dvbdemux_set_pes_filter+0x1c4>
cmpl   $0x0,-0x1c(%rbp)
je     12cc <dvbdemux_set_pes_filter+0x1ac>
mov    0x2cd4(%rip),%rax
mov    (%rax),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2cd2(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvbdemux_set_pes_filter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r15d
mov    %r8d,%r12d
mov    %ecx,%r13d
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    %ebp,(%rsp)
test   %ebx,%ebx
je     1162 <dvbdemux_set_pes_filter+0x42>
cmp    $0x1,%ebx
jne    11cb <dvbdemux_set_pes_filter+0xab>
mov    0x2e68(%rip),%rax
jmp    1169 <dvbdemux_set_pes_filter+0x49>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
cmp    $0x3,%r13d
jae    11cb <dvbdemux_set_pes_filter+0xab>
movslq %r13d,%rax
lea    0x2c39(%rip),%rcx
mov    (%rcx,%rax,8),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
cmp    $0x5,%r12d
jae    11cb <dvbdemux_set_pes_filter+0xab>
movslq %r12d,%rax
lea    0x2c37(%rip),%rcx
mov    (%rcx,%rax,8),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
test   %r15d,%r15d
je     11b5 <dvbdemux_set_pes_filter+0x95>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
or     %eax,0x4(%rsp)
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r14d,%edi
call   1040 <ioctl@plt>
jmp    11d6 <dvbdemux_set_pes_filter+0xb6>
mov    0x2e06(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@DMX_IN_FRONTEND = global i32 0
@DMX_IN_DVR = global i32 0
@EINVAL = global i32 0
@DMX_OUT_DECODER = global i32 0
@DMX_OUT_TAP = global i32 0
@DMX_OUT_TS_TAP = global i32 0
@DMX_PES_AUDIO = global i32 0
@DMX_PES_VIDEO = global i32 0
@DMX_PES_TELETEXT = global i32 0
@DMX_PES_SUBTITLE = global i32 0
@DMX_PES_PCR = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
define i32 @dvbdemux_set_pes_filter(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.dmx_pes_filter_params
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%15 = call i32 @memset(%struct.dmx_pes_filter_params* %14, i32 0, i32 20)
%16 = load i32, i32* %9
%17 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %10
switch i32 %18, label %25 [
i32 0, label %19
i32 1, label %22
]
19: ; preds = %6
%20 = load i32, i32* @DMX_IN_FRONTEND
%21 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 4
store i32 %20, i32* %21
br label %28
22: ; preds = %6
%23 = load i32, i32* @DMX_IN_DVR
%24 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 4
store i32 %23, i32* %24
br label %28
25: ; preds = %6
%26 = load i32, i32* @EINVAL
%27 = sub nsw i32 0, %26
store i32 %27, i32* %7
br label %74
28: ; preds = %22, %19
%29 = load i32, i32* %11
switch i32 %29, label %39 [
i32 0, label %30
i32 1, label %33
i32 2, label %36
]
30: ; preds = %28
%31 = load i32, i32* @DMX_OUT_DECODER
%32 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 3
store i32 %31, i32* %32
br label %42
33: ; preds = %28
%34 = load i32, i32* @DMX_OUT_TAP
%35 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 3
store i32 %34, i32* %35
br label %42
36: ; preds = %28
%37 = load i32, i32* @DMX_OUT_TS_TAP
%38 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 3
store i32 %37, i32* %38
br label %42
39: ; preds = %28
%40 = load i32, i32* @EINVAL
%41 = sub nsw i32 0, %40
store i32 %41, i32* %7
br label %74
42: ; preds = %36, %33, %30
%43 = load i32, i32* %12
switch i32 %43, label %59 [
i32 0, label %44
i32 1, label %47
i32 2, label %50
i32 3, label %53
i32 4, label %56
]
44: ; preds = %42
%45 = load i32, i32* @DMX_PES_AUDIO
%46 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 2
store i32 %45, i32* %46
br label %62
47: ; preds = %42
%48 = load i32, i32* @DMX_PES_VIDEO
%49 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 2
store i32 %48, i32* %49
br label %62
50: ; preds = %42
%51 = load i32, i32* @DMX_PES_TELETEXT
%52 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 2
store i32 %51, i32* %52
br label %62
53: ; preds = %42
%54 = load i32, i32* @DMX_PES_SUBTITLE
%55 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 2
store i32 %54, i32* %55
br label %62
56: ; preds = %42
%57 = load i32, i32* @DMX_PES_PCR
%58 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 2
store i32 %57, i32* %58
br label %62
59: ; preds = %42
%60 = load i32, i32* @EINVAL
%61 = sub nsw i32 0, %60
store i32 %61, i32* %7
br label %74
62: ; preds = %56, %53, %50, %47, %44
%63 = load i32, i32* %13
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load i32, i32* @DMX_IMMEDIATE_START
%67 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %14, i32 0, i32 1
%68 = load i32, i32* %67
%69 = or i32 %68, %66
store i32 %69, i32* %67
br label %70
70: ; preds = %65, %62
%71 = load i32, i32* %8
%72 = load i32, i32* @DMX_SET_PES_FILTER
%73 = call i32 @ioctl(i32 %71, i32 %72, %struct.dmx_pes_filter_params* %14)
store i32 %73, i32* %7
br label %74
74: ; preds = %70, %59, %39, %25
%75 = load i32, i32* %7
ret i32 %75
}

LLVM IR (-O2):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@DMX_IN_FRONTEND = global i32 0
@DMX_IN_DVR = global i32 0
@EINVAL = global i32 0
@DMX_OUT_DECODER = global i32 0
@DMX_OUT_TAP = global i32 0
@DMX_OUT_TS_TAP = global i32 0
@DMX_PES_AUDIO = global i32 0
@DMX_PES_VIDEO = global i32 0
@DMX_PES_TELETEXT = global i32 0
@DMX_PES_SUBTITLE = global i32 0
@DMX_PES_PCR = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
@switch.table.dvbdemux_set_pes_filter = [3 x i32*] [i32* @DMX_OUT_DECODER, i32* @DMX_OUT_TAP, i32* @DMX_OUT_TS_TAP]
@switch.table.dvbdemux_set_pes_filter.1 = [5 x i32*] [i32* @DMX_PES_AUDIO, i32* @DMX_PES_VIDEO, i32* @DMX_PES_TELETEXT, i32* @DMX_PES_SUBTITLE, i32* @DMX_PES_PCR]
define i32 @dvbdemux_set_pes_filter(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca %struct.dmx_pes_filter_params
%8 = bitcast %struct.dmx_pes_filter_params* %7 to i8*
%9 = call i32 @memset(%struct.dmx_pes_filter_params* %7, i32 0, i32 20)
%10 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i64 0, i32 0
store i32 %1, i32* %10
switch i32 %2, label %12 [
i32 0, label %15
i32 1, label %11
]
11: ; preds = %6
br label %15
12: ; preds = %6
%13 = load i32, i32* @EINVAL
%14 = sub nsw i32 0, %13
br label %48
15: ; preds = %6, %11
%16 = phi i32* [ @DMX_IN_DVR, %11 ], [ @DMX_IN_FRONTEND, %6 ]
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i64 0, i32 4
store i32 %17, i32* %18
%19 = icmp ult i32 %3, 3
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32, i32* @EINVAL
%22 = sub nsw i32 0, %21
br label %48
23: ; preds = %15
%24 = sext i32 %3 to i64
%25 = getelementptr inbounds [3 x i32*], [3 x i32*]* @switch.table.dvbdemux_set_pes_filter, i64 0, i64 %24
%26 = load i32*, i32** %25
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i64 0, i32 3
store i32 %27, i32* %28
%29 = icmp ult i32 %4, 5
br i1 %29, label %33, label %30
30: ; preds = %23
%31 = load i32, i32* @EINVAL
%32 = sub nsw i32 0, %31
br label %48
33: ; preds = %23
%34 = sext i32 %4 to i64
%35 = getelementptr inbounds [5 x i32*], [5 x i32*]* @switch.table.dvbdemux_set_pes_filter.1, i64 0, i64 %34
%36 = load i32*, i32** %35
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i64 0, i32 2
store i32 %37, i32* %38
%39 = icmp eq i32 %5, 0
br i1 %39, label %45, label %40
40: ; preds = %33
%41 = load i32, i32* @DMX_IMMEDIATE_START
%42 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i64 0, i32 1
%43 = load i32, i32* %42
%44 = or i32 %43, %41
store i32 %44, i32* %42
br label %45
45: ; preds = %40, %33
%46 = load i32, i32* @DMX_SET_PES_FILTER
%47 = call i32 @ioctl(i32 %0, i32 %46, %struct.dmx_pes_filter_params* %7)
br label %48
48: ; preds = %45, %30, %20, %12
%49 = phi i32 [ %14, %12 ], [ %22, %20 ], [ %32, %30 ], [ %47, %45 ]
ret i32 %49
}