#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;
};

/* Variables and functions */
int /*<<< orphan*/ DMX_IMMEDIATE_START;
int /*<<< orphan*/ DMX_IN_FRONTEND;
int /*<<< orphan*/ DMX_OUT_TS_TAP;
int /*<<< orphan*/ DMX_PES_VIDEO;
int /*<<< orphan*/ DMX_SET_PES_FILTER;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int ioctl(int, int /*<<< orphan*/, struct dmx_pes_filter_params *);
int /*<<< orphan*/ stderr;
int demux_start(int dmxfd) {
  struct dmx_pes_filter_params filter;
  filter.pid = 0x2000;
  filter.input = DMX_IN_FRONTEND;
  filter.output = DMX_OUT_TS_TAP;
  filter.pes_type = DMX_PES_VIDEO;
  filter.flags = DMX_IMMEDIATE_START;
  if (ioctl(dmxfd, DMX_SET_PES_FILTER, &filter) == -1) {
    fprintf(stderr, "Error: DMX_SET_PES_FILTER failed. (errno=%d)\n", errno);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<demux_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x2000,-0x20(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11aa <demux_start+0x8a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <demux_start+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<demux_start>:
sub    $0x18,%rsp
movl   $0x2000,(%rsp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     117e <demux_start+0x5e>
add    $0x18,%rsp
ret
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@DMX_IN_FRONTEND = global i32 0
@DMX_OUT_TS_TAP = global i32 0
@DMX_PES_VIDEO = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"Error: DMX_SET_PES_FILTER failed. (errno=%d)\0A\00"
@errno = global i32 0
define i32 @demux_start(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.dmx_pes_filter_params
store i32 %0, i32* %3
%5 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i32 0, i32 0
store i32 8192, i32* %5
%6 = load i32, i32* @DMX_IN_FRONTEND
%7 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i32 0, i32 4
store i32 %6, i32* %7
%8 = load i32, i32* @DMX_OUT_TS_TAP
%9 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i32 0, i32 3
store i32 %8, i32* %9
%10 = load i32, i32* @DMX_PES_VIDEO
%11 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i32 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @DMX_IMMEDIATE_START
%13 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %4, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* %3
%15 = load i32, i32* @DMX_SET_PES_FILTER
%16 = call i32 @ioctl(i32 %14, i32 %15, %struct.dmx_pes_filter_params* %4)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 -1, i32* %2
br label %23
22: ; preds = %1
store i32 0, i32* %2
br label %23
23: ; preds = %22, %18
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.dmx_pes_filter_params = type { i32, i32, i32, i32, i32 }
@DMX_IN_FRONTEND = global i32 0
@DMX_OUT_TS_TAP = global i32 0
@DMX_PES_VIDEO = global i32 0
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_PES_FILTER = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"Error: DMX_SET_PES_FILTER failed. (errno=%d)\0A\00"
@errno = global i32 0
define i32 @demux_start(i32 %0) {
%2 = alloca %struct.dmx_pes_filter_params
%3 = bitcast %struct.dmx_pes_filter_params* %2 to i8*
%4 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %2, i64 0, i32 0
store i32 8192, i32* %4
%5 = load i32, i32* @DMX_IN_FRONTEND
%6 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %2, i64 0, i32 4
store i32 %5, i32* %6
%7 = load i32, i32* @DMX_OUT_TS_TAP
%8 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %2, i64 0, i32 3
store i32 %7, i32* %8
%9 = load i32, i32* @DMX_PES_VIDEO
%10 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %2, i64 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @DMX_IMMEDIATE_START
%12 = getelementptr inbounds %struct.dmx_pes_filter_params, %struct.dmx_pes_filter_params* %2, i64 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @DMX_SET_PES_FILTER
%14 = call i32 @ioctl(i32 %0, i32 %13, %struct.dmx_pes_filter_params* %2)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %1, %16
%21 = phi i32 [ -1, %16 ], [ 0, %1 ]
ret i32 %21
}