#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint16_t;
struct TYPE_2__ {
  int *mask;
  int /*<<< orphan*/ *filter;
};
struct dmx_sct_filter_params {
  int timeout;
  int /*<<< orphan*/ flags;
  TYPE_1__ filter;
  int /*<<< orphan*/ pid;
};
typedef int /*<<< orphan*/ f;

/* Variables and functions */
int /*<<< orphan*/ DMX_IMMEDIATE_START;
int /*<<< orphan*/ DMX_SET_FILTER;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct dmx_sct_filter_params *);
int /*<<< orphan*/ memset(struct dmx_sct_filter_params *, int /*<<< orphan*/,
                          int);
int read(int, int /*<<< orphan*/ *, int);
int get_sec(int fd, uint8_t *buf, uint16_t ppid, uint8_t table) {
  struct dmx_sct_filter_params f;
  memset(&f, 0, sizeof(f));
  f.pid = ppid;
  f.filter.filter[0] = table;
  f.filter.mask[0] = 0xFF;
  f.timeout = 2000;
  f.flags = DMX_IMMEDIATE_START;
  if (ioctl(fd, DMX_SET_FILTER, &f) < 0)
    return -1;
  return read(fd, buf, 4096);
}


x86 assembly (clang, -O0):
<get_sec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
movl   $0xff,(%rax)
movl   $0x7d0,-0x38(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11ac <get_sec+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <get_sec+0x90>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    %ebp,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    %ebx,(%rax)
mov    0x8(%rsp),%rax
movl   $0xff,(%rax)
movl   $0x7d0,(%rsp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %r12,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
js     11ad <get_sec+0x7d>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
jmp    11b2 <get_sec+0x82>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dmx_sct_filter_params = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32*, i32* }
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_FILTER = global i32 0
define i32 @get_sec(i32 %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.dmx_sct_filter_params
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = call i32 @memset(%struct.dmx_sct_filter_params* %10, i32 0, i32 32)
%12 = load i32, i32* %8
%13 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %10, i32 0, i32 3
store i32 %12, i32* %13
%14 = load i32, i32* %9
%15 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %10, i32 0, i32 2
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 1
%17 = load i32*, i32** %16
%18 = getelementptr inbounds i32, i32* %17, i64 0
store i32 %14, i32* %18
%19 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %10, i32 0, i32 2
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
%21 = load i32*, i32** %20
%22 = getelementptr inbounds i32, i32* %21, i64 0
store i32 255, i32* %22
%23 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %10, i32 0, i32 0
store i32 2000, i32* %23
%24 = load i32, i32* @DMX_IMMEDIATE_START
%25 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %10, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* %6
%27 = load i32, i32* @DMX_SET_FILTER
%28 = call i64 @ioctl(i32 %26, i32 %27, %struct.dmx_sct_filter_params* %10)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %4
store i32 -1, i32* %5
br label %35
31: ; preds = %4
%32 = load i32, i32* %6
%33 = load i32*, i32** %7
%34 = call i32 @read(i32 %32, i32* %33, i32 4096)
store i32 %34, i32* %5
br label %35
35: ; preds = %31, %30
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
%struct.dmx_sct_filter_params = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32*, i32* }
@DMX_IMMEDIATE_START = global i32 0
@DMX_SET_FILTER = global i32 0
define i32 @get_sec(i32 %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = alloca %struct.dmx_sct_filter_params
%6 = bitcast %struct.dmx_sct_filter_params* %5 to i8*
%7 = call i32 @memset(%struct.dmx_sct_filter_params* %5, i32 0, i32 32)
%8 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %5, i64 0, i32 3
store i32 %2, i32* %8
%9 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %5, i64 0, i32 2, i32 1
%10 = load i32*, i32** %9
store i32 %3, i32* %10
%11 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %5, i64 0, i32 2, i32 0
%12 = load i32*, i32** %11
store i32 255, i32* %12
%13 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %5, i64 0, i32 0
store i32 2000, i32* %13
%14 = load i32, i32* @DMX_IMMEDIATE_START
%15 = getelementptr inbounds %struct.dmx_sct_filter_params, %struct.dmx_sct_filter_params* %5, i64 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @DMX_SET_FILTER
%17 = call i64 @ioctl(i32 %0, i32 %16, %struct.dmx_sct_filter_params* %5)
%18 = icmp slt i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %4
%20 = call i32 @read(i32 %0, i32* %1, i32 4096)
br label %21
21: ; preds = %4, %19
%22 = phi i32 [ %20, %19 ], [ -1, %4 ]
ret i32 %22
}