#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 ushort;
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_FRONTEND;
int /*<<< orphan*/ DMX_OUT_TAP;
int /*<<< orphan*/ DMX_PES_OTHER;
int /*<<< orphan*/ DMX_SET_PES_FILTER;
int /*<<< orphan*/ DMX_STOP;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct dmx_pes_filter_params *);
int /*<<< orphan*/ perror(char *);
void set_recpid(int fd, ushort ttpid) {
  struct dmx_pes_filter_params pesFilterParamsREC;
  if (ttpid == 0 || ttpid == 0xffff) {
    ioctl(fd, DMX_STOP, 0);
    return;
  }
  pesFilterParamsREC.pid = ttpid;
  pesFilterParamsREC.input = DMX_IN_FRONTEND;
  pesFilterParamsREC.output = DMX_OUT_TAP;
  pesFilterParamsREC.pes_type = DMX_PES_OTHER;
  pesFilterParamsREC.flags = DMX_IMMEDIATE_START;
  if (ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParamsREC) < 0)
    perror("set_recpid");
}


x86 assembly (clang, -O0):
<set_recpid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1145 <set_recpid+0x25>
cmpl   $0xffff,-0x8(%rbp)
jne    115f <set_recpid+0x3f>
mov    -0x4(%rbp),%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <ioctl@plt>
jmp    11c0 <set_recpid+0xa0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11c0 <set_recpid+0xa0>
lea    0xe45(%rip),%rdi
call   1040 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_recpid>:
sub    $0x18,%rsp
cmp    $0xffff,%esi
je     1130 <set_recpid+0x10>
test   %esi,%esi
jne    1144 <set_recpid+0x24>
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
add    $0x18,%rsp
jmp    1030 <ioctl@plt>
mov    %esi,(%rsp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
js     1196 <set_recpid+0x76>
add    $0x18,%rsp
ret
lea    0xe63(%rip),%rdi
call   1040 <perror@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@DMX_STOP = global i32 0
@DMX_IN_FRONTEND = global i32 0
@DMX_OUT_TAP = global i32 0
@DMX_PES_OTHER = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
@.str = [11 x i8] c"set_recpid\00"
define void @set_recpid(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.dmx_pes_filter_params
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 65535
br i1 %10, label %11, label %15
11: ; preds = %8, %2
%12 = load i32, i32* %3
%13 = load i32, i32* @DMX_STOP
%14 = call i64 @ioctl(i32 %12, i32 %13, %struct.dmx_pes_filter_params* null)
br label %32
15: ; preds = %8
%16 = load i32, i32* %4
%17 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %5, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @DMX_IN_FRONTEND
%19 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %5, i32 0, i32 4
store i32 %18, i32* %19
%20 = load i32, i32* @DMX_OUT_TAP
%21 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %5, i32 0, i32 3
store i32 %20, i32* %21
%22 = load i32, i32* @DMX_PES_OTHER
%23 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %5, i32 0, i32 2
store i32 %22, i32* %23
%24 = load i32, i32* @DMX_IMMEDIATE_START
%25 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %5, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* %3
%27 = load i32, i32* @DMX_SET_PES_FILTER
%28 = call i64 @ioctl(i32 %26, i32 %27, %struct.dmx_pes_filter_params* %5)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %15
%31 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %11, %30, %15
ret void
}

LLVM IR (-O2):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@DMX_STOP = global i32 0
@DMX_IN_FRONTEND = global i32 0
@DMX_OUT_TAP = global i32 0
@DMX_PES_OTHER = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
@.str = [11 x i8] c"set_recpid\00"
define void @set_recpid(i32 %0, i32 %1) {
%3 = alloca %struct.dmx_pes_filter_params
%4 = bitcast %struct.dmx_pes_filter_params* %3 to i8*
switch i32 %1, label %8 [
i32 65535, label %5
i32 0, label %5
]
5: ; preds = %2, %2
%6 = load i32, i32* @DMX_STOP
%7 = tail call i64 @ioctl(i32 %0, i32 %6, %struct.dmx_pes_filter_params* null)
br label %23
8: ; preds = %2
%9 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %3, i64 0, i32 0
store i32 %1, i32* %9
%10 = load i32, i32* @DMX_IN_FRONTEND
%11 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %3, i64 0, i32 4
store i32 %10, i32* %11
%12 = load i32, i32* @DMX_OUT_TAP
%13 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %3, i64 0, i32 3
store i32 %12, i32* %13
%14 = load i32, i32* @DMX_PES_OTHER
%15 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %3, i64 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @DMX_IMMEDIATE_START
%17 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @DMX_SET_PES_FILTER
%19 = call i64 @ioctl(i32 %0, i32 %18, %struct.dmx_pes_filter_params* %3)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %8
%22 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %8, %21, %5
ret void
}