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

/* Variables and functions */
int /*<<< orphan*/ DMX_IMMEDIATE_START;
int /*<<< orphan*/ DMX_IN_DVR;
int /*<<< orphan*/ DMX_OUT_DECODER;
int /*<<< orphan*/ DMX_PES_AUDIO;
int /*<<< orphan*/ DMX_PES_VIDEO;
int /*<<< orphan*/ DMX_SET_PES_FILTER;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct dmx_pes_filter_params *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void set_ts_filt(int fd, uint16_t pid, int type) {
  struct dmx_pes_filter_params pesFilterParams;
  pesFilterParams.pid = pid;
  pesFilterParams.input = DMX_IN_DVR;
  pesFilterParams.output = DMX_OUT_DECODER;
  if (type == 1)
    pesFilterParams.pes_type = DMX_PES_VIDEO;
  if (type == 2)
    pesFilterParams.pes_type = DMX_PES_AUDIO;
  pesFilterParams.flags = DMX_IMMEDIATE_START;
  if (ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams) < 0) {
    fprintf(stderr, "FILTER %i: ", pid);
    perror("DMX SET PES FILTER");
  }
}


x86 assembly (clang, -O0):
<set_ts_filt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1175 <set_ts_filt+0x45>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    118b <set_ts_filt+0x5b>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11da <set_ts_filt+0xaa>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe37(%rip),%rdi
call   1050 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ts_filt>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
mov    %esi,0x8(%rsp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
cmp    $0x1,%edx
je     1168 <set_ts_filt+0x38>
cmp    $0x2,%edx
jne    1175 <set_ts_filt+0x45>
mov    0x2e42(%rip),%rax
jmp    116f <set_ts_filt+0x3f>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
js     11a0 <set_ts_filt+0x70>
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
jmp    119a <set_ts_filt+0x6a>

LLVM IR (-O0):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@DMX_IN_DVR = global i32 0
@DMX_OUT_DECODER = global i32 0
@DMX_PES_VIDEO = global i32 0
@DMX_PES_AUDIO = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"FILTER %i: \00"
@.str.1 = [19 x i8] c"DMX SET PES FILTER\00"
define void @set_ts_filt(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.dmx_pes_filter_params
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 0
store i32 %8, i32* %9
%10 = load i32, i32* @DMX_IN_DVR
%11 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 4
store i32 %10, i32* %11
%12 = load i32, i32* @DMX_OUT_DECODER
%13 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 3
store i32 %12, i32* %13
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i32, i32* @DMX_PES_VIDEO
%18 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 2
store i32 %17, i32* %18
br label %19
19: ; preds = %16, %3
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @DMX_PES_AUDIO
%24 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 2
store i32 %23, i32* %24
br label %25
25: ; preds = %22, %19
%26 = load i32, i32* @DMX_IMMEDIATE_START
%27 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* %4
%29 = load i32, i32* @DMX_SET_PES_FILTER
%30 = call i64 @ioctl(i32 %28, i32 %29, %struct.dmx_pes_filter_params* %7)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i32, i32* %5
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %32, %25
ret void
}

LLVM IR (-O2):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@DMX_IN_DVR = global i32 0
@DMX_OUT_DECODER = global i32 0
@DMX_PES_VIDEO = global i32 0
@DMX_PES_AUDIO = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"FILTER %i: \00"
@.str.1 = [19 x i8] c"DMX SET PES FILTER\00"
define void @set_ts_filt(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.dmx_pes_filter_params
%5 = bitcast %struct.dmx_pes_filter_params* %4 to i8*
%6 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 0
store i32 %1, i32* %6
%7 = load i32, i32* @DMX_IN_DVR
%8 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 4
store i32 %7, i32* %8
%9 = load i32, i32* @DMX_OUT_DECODER
%10 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 3
store i32 %9, i32* %10
switch i32 %2, label %16 [
i32 1, label %12
i32 2, label %11
]
11: ; preds = %3
br label %12
12: ; preds = %3, %11
%13 = phi i32* [ @DMX_PES_AUDIO, %11 ], [ @DMX_PES_VIDEO, %3 ]
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 2
store i32 %14, i32* %15
br label %16
16: ; preds = %12, %3
%17 = load i32, i32* @DMX_IMMEDIATE_START
%18 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @DMX_SET_PES_FILTER
%20 = call i64 @ioctl(i32 %0, i32 %19, %struct.dmx_pes_filter_params* %4)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %1)
%25 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %22, %16
ret void
}