#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 */
struct TYPE_2__ {
  int data;
};
struct dtv_property {
  TYPE_1__ u;
  int /*<<< orphan*/ cmd;
};
struct dtv_properties {
  int num;
  struct dtv_property *props;
};

/* Variables and functions */
int /*<<< orphan*/ DTV_API_VERSION;
int /*<<< orphan*/ FE_GET_PROPERTY;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int ioctl(int, int /*<<< orphan*/, struct dtv_properties *);
int /*<<< orphan*/ stderr;
int dvbfe_get_version(int fd, int *major, int *minor) {
  struct dtv_property p, *b;
  struct dtv_properties cmd;
  int ret;
  p.cmd = DTV_API_VERSION;
  cmd.num = 1;
  cmd.props = &p;
  b = &p;
  ret = ioctl(fd, FE_GET_PROPERTY, &cmd);
  if (ret < 0) {
    fprintf(stderr, "FE_GET_PROPERTY failed, ret=%d\n", ret);
    return -1;
  }
  *major = (b->u.data >> 8) & 0xff;
  *minor = b->u.data & 0xff;
  return 0;
}


x86 assembly (clang, -O0):
<dvbfe_get_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ebe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x38(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    119c <dvbfe_get_version+0x7c>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%edx
lea    0xe75(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <dvbfe_get_version+0xaa>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvbfe_get_version>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    0x2ec4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
movl   $0x1,0x8(%rsp)
mov    %rsp,%rax
mov    %rax,0x10(%rsp)
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
js     1173 <dvbfe_get_version+0x53>
mov    (%rsp),%eax
movzbl %ah,%ecx
mov    %ecx,(%rbx)
movzbl %al,%eax
mov    %eax,(%r14)
xor    %eax,%eax
jmp    118f <dvbfe_get_version+0x6f>
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%edi
lea    0xe7d(%rip),%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dtv_property = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.dtv_properties = type { i32, %struct.dtv_property* }
@DTV_API_VERSION = global i32 0
@FE_GET_PROPERTY = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"FE_GET_PROPERTY failed, ret=%d\0A\00"
define i32 @dvbfe_get_version(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.dtv_property
%9 = alloca %struct.dtv_property*
%10 = alloca %struct.dtv_properties
%11 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%12 = load i32, i32* @DTV_API_VERSION
%13 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %8, i32 0, i32 1
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %10, i32 0, i32 0
store i32 1, i32* %14
%15 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %10, i32 0, i32 1
store %struct.dtv_property* %8, %struct.dtv_property** %15
store %struct.dtv_property* %8, %struct.dtv_property** %9
%16 = load i32, i32* %5
%17 = load i32, i32* @FE_GET_PROPERTY
%18 = call i32 @ioctl(i32 %16, i32 %17, %struct.dtv_properties* %10)
store i32 %18, i32* %11
%19 = load i32, i32* %11
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %3
%22 = load i32, i32* @stderr
%23 = load i32, i32* %11
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 -1, i32* %4
br label %39
25: ; preds = %3
%26 = load %struct.dtv_property*, %struct.dtv_property** %9
%27 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %26, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = ashr i32 %29, 8
%31 = and i32 %30, 255
%32 = load i32*, i32** %6
store i32 %31, i32* %32
%33 = load %struct.dtv_property*, %struct.dtv_property** %9
%34 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %33, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = and i32 %36, 255
%38 = load i32*, i32** %7
store i32 %37, i32* %38
store i32 0, i32* %4
br label %39
39: ; preds = %25, %21
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
%struct.dtv_property = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.dtv_properties = type { i32, %struct.dtv_property* }
@DTV_API_VERSION = global i32 0
@FE_GET_PROPERTY = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"FE_GET_PROPERTY failed, ret=%d\0A\00"
define i32 @dvbfe_get_version(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca %struct.dtv_property
%5 = alloca %struct.dtv_properties
%6 = bitcast %struct.dtv_property* %4 to i8*
%7 = bitcast %struct.dtv_properties* %5 to i8*
%8 = load i32, i32* @DTV_API_VERSION
%9 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %4, i64 0, i32 1
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %5, i64 0, i32 0
store i32 1, i32* %10
%11 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %5, i64 0, i32 1
store %struct.dtv_property* %4, %struct.dtv_property** %11
%12 = load i32, i32* @FE_GET_PROPERTY
%13 = call i32 @ioctl(i32 %0, i32 %12, %struct.dtv_properties* %5)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %24
18: ; preds = %3
%19 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %4, i64 0, i32 0, i32 0
%20 = load i32, i32* %19
%21 = lshr i32 %20, 8
%22 = and i32 %21, 255
store i32 %22, i32* %1
%23 = and i32 %20, 255
store i32 %23, i32* %2
br label %24
24: ; preds = %18, %15
%25 = phi i32 [ -1, %15 ], [ 0, %18 ]
ret i32 %25
}