#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  size_t len;
  scalar_t__ *data;
};
struct TYPE_4__ {
  TYPE_1__ buffer;
};
struct dtv_property {
  TYPE_2__ u;
  int /*<<< orphan*/ cmd;
};
struct dtv_properties {
  int num;
  struct dtv_property *props;
};
typedef size_t __u32;

/* Variables and functions */
int /*<<< orphan*/ DTV_ENUM_DELSYS;
int /*<<< orphan*/ FE_GET_PROPERTY;
scalar_t__ SYS_ISDBS;
scalar_t__ SYS_ISDBT;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct dtv_properties *);
int /*<<< orphan*/ stderr;
int get_isdbtype(int fefd) {
  struct dtv_properties props;
  struct dtv_property prop[1];
  prop[0].cmd = DTV_ENUM_DELSYS;
  props.num = 1;
  props.props = prop;
  if (ioctl(fefd, FE_GET_PROPERTY, &props) != 0) {
    fprintf(stderr, "Error: ioctl FE_GET_PROPERTY failed. (errno=%d)\n", errno);
    return -1;
  }
  for (__u32 i = 0; i < prop[0].u.buffer.len; ++i) {
    if (prop[0].u.buffer.data[i] == SYS_ISDBT) {
      return 0;
    }
    if (prop[0].u.buffer.data[i] == SYS_ISDBS) {
      return 1;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_isdbtype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x18(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     118f <get_isdbtype+0x6f>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <get_isdbtype+0xf2>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    120b <get_isdbtype+0xeb>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%rax
jne    11cd <get_isdbtype+0xad>
movl   $0x0,-0x4(%rbp)
jmp    1212 <get_isdbtype+0xf2>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%rax
jne    11f5 <get_isdbtype+0xd5>
movl   $0x1,-0x4(%rbp)
jmp    1212 <get_isdbtype+0xf2>
jmp    11fa <get_isdbtype+0xda>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1197 <get_isdbtype+0x77>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_isdbtype>:
sub    $0x28,%rsp
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
movl   $0x1,(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
je     1180 <get_isdbtype+0x60>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
ret
mov    0x10(%rsp),%r9
mov    $0xffffffff,%eax
test   %r9,%r9
je     11c7 <get_isdbtype+0xa7>
mov    0x18(%rsp),%r8
mov    0x2e15(%rip),%rcx
mov    (%rcx),%rsi
mov    0x2e43(%rip),%rcx
mov    (%rcx),%rdi
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
mov    (%r8,%rdx,8),%rcx
cmp    %rsi,%rcx
je     11cc <get_isdbtype+0xac>
cmp    %rdi,%rcx
je     11d3 <get_isdbtype+0xb3>
add    $0x1,%rdx
cmp    %rdx,%r9
jne    11b0 <get_isdbtype+0x90>
add    $0x28,%rsp
ret
xor    %eax,%eax
add    $0x28,%rsp
ret
mov    $0x1,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.dtv_properties = type { i32, %struct.dtv_property* }
%struct.dtv_property = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i64, i64* }
@DTV_ENUM_DELSYS = global i32 0
@FE_GET_PROPERTY = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Error: ioctl FE_GET_PROPERTY failed. (errno=%d)\0A\00"
@errno = global i32 0
@SYS_ISDBT = global i64 0
@SYS_ISDBS = global i64 0
define i32 @get_isdbtype(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.dtv_properties
%5 = alloca [1 x %struct.dtv_property]
%6 = alloca i64
store i32 %0, i32* %3
%7 = load i32, i32* @DTV_ENUM_DELSYS
%8 = getelementptr inbounds [1 x %struct.dtv_property], [1 x %struct.dtv_property]* %5, i64 0, i64 0
%9 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %8, i32 0, i32 1
store i32 %7, i32* %9
%10 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %4, i32 0, i32 0
store i32 1, i32* %10
%11 = getelementptr inbounds [1 x %struct.dtv_property], [1 x %struct.dtv_property]* %5, i64 0, i64 0
%12 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %4, i32 0, i32 1
store %struct.dtv_property* %11, %struct.dtv_property** %12
%13 = load i32, i32* %3
%14 = load i32, i32* @FE_GET_PROPERTY
%15 = call i64 @ioctl(i32 %13, i32 %14, %struct.dtv_properties* %4)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 -1, i32* %2
br label %59
21: ; preds = %1
store i64 0, i64* %6
br label %22
22: ; preds = %55, %21
%23 = load i64, i64* %6
%24 = getelementptr inbounds [1 x %struct.dtv_property], [1 x %struct.dtv_property]* %5, i64 0, i64 0
%25 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %24, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i32 0, i32 0
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 0
%28 = load i64, i64* %27
%29 = icmp ult i64 %23, %28
br i1 %29, label %30, label %58
30: ; preds = %22
%31 = getelementptr inbounds [1 x %struct.dtv_property], [1 x %struct.dtv_property]* %5, i64 0, i64 0
%32 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %31, i32 0, i32 0
%33 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %32, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i32 0, i32 1
%35 = load i64*, i64** %34
%36 = load i64, i64* %6
%37 = getelementptr inbounds i64, i64* %35, i64 %36
%38 = load i64, i64* %37
%39 = load i64, i64* @SYS_ISDBT
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %30
store i32 0, i32* %2
br label %59
42: ; preds = %30
%43 = getelementptr inbounds [1 x %struct.dtv_property], [1 x %struct.dtv_property]* %5, i64 0, i64 0
%44 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %43, i32 0, i32 0
%45 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %44, i32 0, i32 0
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %45, i32 0, i32 1
%47 = load i64*, i64** %46
%48 = load i64, i64* %6
%49 = getelementptr inbounds i64, i64* %47, i64 %48
%50 = load i64, i64* %49
%51 = load i64, i64* @SYS_ISDBS
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %42
store i32 1, i32* %2
br label %59
54: ; preds = %42
br label %55
55: ; preds = %54
%56 = load i64, i64* %6
%57 = add i64 %56, 1
store i64 %57, i64* %6
br label %22
58: ; preds = %22
store i32 -1, i32* %2
br label %59
59: ; preds = %58, %53, %41, %17
%60 = load i32, i32* %2
ret i32 %60
}

LLVM IR (-O2):
%struct.dtv_properties = type { i32, %struct.dtv_property* }
%struct.dtv_property = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i64, i64* }
@DTV_ENUM_DELSYS = global i32 0
@FE_GET_PROPERTY = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Error: ioctl FE_GET_PROPERTY failed. (errno=%d)\0A\00"
@errno = global i32 0
@SYS_ISDBT = global i64 0
@SYS_ISDBS = global i64 0
define i32 @get_isdbtype(i32 %0) {
%2 = alloca %struct.dtv_properties
%3 = alloca [1 x %struct.dtv_property]
%4 = bitcast %struct.dtv_properties* %2 to i8*
%5 = bitcast [1 x %struct.dtv_property]* %3 to i8*
%6 = load i32, i32* @DTV_ENUM_DELSYS
%7 = getelementptr inbounds [1 x %struct.dtv_property], [1 x %struct.dtv_property]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1 x %struct.dtv_property], [1 x %struct.dtv_property]* %3, i64 0, i64 0, i32 1
store i32 %6, i32* %8
%9 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %2, i64 0, i32 0
store i32 1, i32* %9
%10 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %2, i64 0, i32 1
store %struct.dtv_property* %7, %struct.dtv_property** %10
%11 = load i32, i32* @FE_GET_PROPERTY
%12 = call i64 @ioctl(i32 %0, i32 %11, %struct.dtv_properties* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %1
%15 = getelementptr inbounds [1 x %struct.dtv_property], [1 x %struct.dtv_property]* %3, i64 0, i64 0, i32 0, i32 0, i32 0
%16 = load i64, i64* %15
%17 = icmp eq i64 %16, 0
br i1 %17, label %37, label %18
18: ; preds = %14
%19 = getelementptr inbounds [1 x %struct.dtv_property], [1 x %struct.dtv_property]* %3, i64 0, i64 0, i32 0, i32 0, i32 1
%20 = load i64*, i64** %19
%21 = load i64, i64* @SYS_ISDBT
%22 = load i64, i64* @SYS_ISDBS
br label %29
23: ; preds = %1
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %37
27: ; preds = %34
%28 = icmp eq i64 %36, %16
br i1 %28, label %37, label %29
29: ; preds = %18, %27
%30 = phi i64 [ 0, %18 ], [ %36, %27 ]
%31 = getelementptr inbounds i64, i64* %20, i64 %30
%32 = load i64, i64* %31
%33 = icmp eq i64 %32, %21
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = icmp eq i64 %32, %22
%36 = add nuw i64 %30, 1
br i1 %35, label %37, label %27
37: ; preds = %27, %29, %34, %14, %23
%38 = phi i32 [ -1, %23 ], [ -1, %14 ], [ -1, %27 ], [ 0, %29 ], [ 1, %34 ]
ret i32 %38
}