#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 pes_type;
  int /*<<< orphan*/ flags;
  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_SET_BUFFER_SIZE;
int /*<<< orphan*/ DMX_SET_PES_FILTER;
int /*<<< orphan*/ DMX_STOP;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
scalar_t__ ioctl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void set_pid(int fd, int pid, int type) {
  struct dmx_pes_filter_params pesFilterParams;
  fprintf(stderr, "set PID 0x%04x (%d)\n", pid, type);
  if (ioctl(fd, DMX_STOP) < 0)
    perror("DMX STOP:");
  if (ioctl(fd, DMX_SET_BUFFER_SIZE, 64 * 1024) < 0)
    perror("DMX SET BUFFER:");
  pesFilterParams.pid = pid;
  pesFilterParams.input = DMX_IN_DVR;
  pesFilterParams.output = DMX_OUT_DECODER;
  pesFilterParams.pes_type = type;
  pesFilterParams.flags = DMX_IMMEDIATE_START;
  if (ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams) < 0)
    perror("DMX SET FILTER");
}


x86 assembly (clang, -O0):
<set_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xea9(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1185 <set_pid+0x55>
lea    0xe95(%rip),%rdi
call   1050 <perror@plt>
mov    -0x4(%rbp),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    $0x10000,%edx
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11b3 <set_pid+0x83>
lea    0xe71(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1210 <set_pid+0xe0>
lea    0xe24(%rip),%rdi
call   1050 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_pid>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xeb1(%rip),%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <fprintf@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     11e1 <set_pid+0xb1>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x10000,%edx
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     11ef <set_pid+0xbf>
mov    %ebp,0x8(%rsp)
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %r14d,0xc(%rsp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     11fd <set_pid+0xcd>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe2d(%rip),%rdi
call   1050 <perror@plt>
jmp    1170 <set_pid+0x40>
lea    0xe29(%rip),%rdi
call   1050 <perror@plt>
jmp    118c <set_pid+0x5c>
lea    0xe2b(%rip),%rdi
call   1050 <perror@plt>
jmp    11d8 <set_pid+0xa8>

LLVM IR (-O0):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [21 x i8] c"set PID 0x%04x (%d)\0A\00"
@DMX_STOP = global i32 0
@.str.1 = [10 x i8] c"DMX STOP:\00"
@DMX_SET_BUFFER_SIZE = global i32 0
@.str.2 = [16 x i8] c"DMX SET BUFFER:\00"
@DMX_IN_DVR = global i32 0
@DMX_OUT_DECODER = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
@.str.3 = [15 x i8] c"DMX SET FILTER\00"
define void @set_pid(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* @stderr
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = load i32, i32* %4
%13 = load i32, i32* @DMX_STOP
%14 = call i64 (i32, i32, ...) @ioctl(i32 %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %3
%19 = load i32, i32* %4
%20 = load i32, i32* @DMX_SET_BUFFER_SIZE
%21 = call i64 (i32, i32, ...) @ioctl(i32 %19, i32 %20, i32 65536)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = load i32, i32* %5
%27 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @DMX_IN_DVR
%29 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 4
store i32 %28, i32* %29
%30 = load i32, i32* @DMX_OUT_DECODER
%31 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 3
store i32 %30, i32* %31
%32 = load i32, i32* %6
%33 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i32, i32* @DMX_IMMEDIATE_START
%35 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %7, i32 0, i32 2
store i32 %34, i32* %35
%36 = load i32, i32* %4
%37 = load i32, i32* @DMX_SET_PES_FILTER
%38 = call i64 (i32, i32, ...) @ioctl(i32 %36, i32 %37, %struct.dmx_pes_filter_params* %7)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %25
%41 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %25
ret void
}

LLVM IR (-O2):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [21 x i8] c"set PID 0x%04x (%d)\0A\00"
@DMX_STOP = global i32 0
@.str.1 = [10 x i8] c"DMX STOP:\00"
@DMX_SET_BUFFER_SIZE = global i32 0
@.str.2 = [16 x i8] c"DMX SET BUFFER:\00"
@DMX_IN_DVR = global i32 0
@DMX_OUT_DECODER = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
@.str.3 = [15 x i8] c"DMX SET FILTER\00"
define void @set_pid(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.dmx_pes_filter_params
%5 = bitcast %struct.dmx_pes_filter_params* %4 to i8*
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%8 = load i32, i32* @DMX_STOP
%9 = tail call i64 (i32, i32, ...) @ioctl(i32 %0, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = load i32, i32* @DMX_SET_BUFFER_SIZE
%15 = tail call i64 (i32, i32, ...) @ioctl(i32 %0, i32 %14, i32 65536)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 0
store i32 %1, i32* %20
%21 = load i32, i32* @DMX_IN_DVR
%22 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 4
store i32 %21, i32* %22
%23 = load i32, i32* @DMX_OUT_DECODER
%24 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 3
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 1
store i32 %2, i32* %25
%26 = load i32, i32* @DMX_IMMEDIATE_START
%27 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i64 0, i32 2
store i32 %26, i32* %27
%28 = load i32, i32* @DMX_SET_PES_FILTER
%29 = call i64 (i32, i32, ...) @ioctl(i32 %0, i32 %28, %struct.dmx_pes_filter_params* %4)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %19
ret void
}