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

/* Variables and functions */
int /*<<< orphan*/ DTV_STREAM_ID;
int /*<<< orphan*/ DTV_TUNE;
int /*<<< orphan*/ DTV_VOLTAGE;
int /*<<< orphan*/ FE_SET_PROPERTY;
unsigned int SEC_VOLTAGE_13;
unsigned int SEC_VOLTAGE_18;
unsigned int SEC_VOLTAGE_OFF;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int get_isdbtype(int);
int ioctl(int, int /*<<< orphan*/, struct dtv_properties *);
scalar_t__ set_isdb_s_frequency(char *, struct dtv_property *);
scalar_t__ set_isdb_t_frequency(char *, struct dtv_property *);
int /*<<< orphan*/ stderr;
int frontend_tune(int fefd, char *channel, unsigned int tsid, int lnb) {
  int isdbtype;
  struct dtv_property prop[4];
  struct dtv_properties props;
  props.num = 0;
  props.props = prop;
  isdbtype = get_isdbtype(fefd);
  if (isdbtype == 0) {
    if (set_isdb_t_frequency(channel, &prop[props.num]) != 0) {
      return -1;
    }
    props.num++;
  } else if (isdbtype == 1) {
    prop[props.num].cmd = DTV_VOLTAGE;
    if (lnb == 15) {
      prop[props.num].u.data = SEC_VOLTAGE_18;
    } else if (lnb == 11) {
      prop[props.num].u.data = SEC_VOLTAGE_13;
    } else {
      prop[props.num].u.data = SEC_VOLTAGE_OFF;
    }
    props.num++;
    if (set_isdb_s_frequency(channel, &prop[props.num]) != 0) {
      return -1;
    }
    props.num++;
    prop[props.num].cmd = DTV_STREAM_ID;
    prop[props.num].u.data = tsid;
    props.num++;
  }
  prop[props.num].cmd = DTV_TUNE;
  props.num++;
  if (ioctl(fefd, FE_SET_PROPERTY, &props) == -1) {
    fprintf(stderr, "Error: FE_SET_PROPERTY failed. (errno=%d)\n", errno);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<frontend_tune>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movq   $0x0,-0x50(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <get_isdbtype@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11c9 <frontend_tune+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rax
lea    -0x40(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
call   1070 <set_isdb_t_frequency@plt>
cmp    $0x0,%rax
je     11b8 <frontend_tune+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    1319 <frontend_tune+0x1c9>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    12ad <frontend_tune+0x15d>
cmpl   $0x1,-0x1c(%rbp)
jne    12a8 <frontend_tune+0x158>
mov    0x2e06(%rip),%rax
mov    (%rax),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,8)
cmpl   $0xf,-0x18(%rbp)
jne    1204 <frontend_tune+0xb4>
mov    0x2dcb(%rip),%rax
mov    (%rax),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,-0x3c(%rbp,%rax,8)
jmp    123a <frontend_tune+0xea>
cmpl   $0xb,-0x18(%rbp)
jne    1224 <frontend_tune+0xd4>
mov    0x2dd3(%rip),%rax
mov    (%rax),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,-0x3c(%rbp,%rax,8)
jmp    1235 <frontend_tune+0xe5>
mov    0x2d6d(%rip),%rax
mov    (%rax),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,-0x3c(%rbp,%rax,8)
jmp    123a <frontend_tune+0xea>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rax
lea    -0x40(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <set_isdb_s_frequency@plt>
cmp    $0x0,%rax
je     1274 <frontend_tune+0x124>
movl   $0xffffffff,-0x4(%rbp)
jmp    1319 <frontend_tune+0x1c9>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    0x2d19(%rip),%rax
mov    (%rax),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,8)
mov    -0x14(%rbp),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,-0x3c(%rbp,%rax,8)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    12ad <frontend_tune+0x15d>
mov    0x2d24(%rip),%rax
mov    (%rax),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,8)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ce4(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1312 <frontend_tune+0x1c2>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
mov    0x2cb8(%rip),%rax
mov    (%rax),%edx
lea    0xcff(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1319 <frontend_tune+0x1c9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frontend_tune>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%r15d
mov    %rsp,%rax
mov    %rax,0x30(%rsp)
call   1060 <get_isdbtype@plt>
cmp    $0x1,%eax
je     119e <frontend_tune+0x4e>
test   %eax,%eax
jne    11bd <frontend_tune+0x6d>
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1070 <set_isdb_t_frequency@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1262 <frontend_tune+0x112>
mov    $0x1,%eax
jmp    120b <frontend_tune+0xbb>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
cmp    $0xb,%ebx
jne    11c1 <frontend_tune+0x71>
mov    0x2e32(%rip),%rax
cmp    $0xf,%ebx
je     11cd <frontend_tune+0x7d>
jmp    11d4 <frontend_tune+0x84>
xor    %eax,%eax
jmp    120b <frontend_tune+0xbb>
mov    0x2dd0(%rip),%rax
cmp    $0xf,%ebx
jne    11d4 <frontend_tune+0x84>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1030 <set_isdb_s_frequency@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1262 <frontend_tune+0x112>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %r14d,0x14(%rsp)
mov    $0x3,%eax
mov    0x2dc6(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rsp,%rax,8)
add    $0x1,%rax
mov    %rax,0x28(%rsp)
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
lea    0x28(%rsp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1262 <frontend_tune+0x112>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%edx
lea    0xda8(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dtv_property = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.dtv_properties = type { i64, %struct.dtv_property* }
@DTV_VOLTAGE = global i32 0
@SEC_VOLTAGE_18 = global i32 0
@SEC_VOLTAGE_13 = global i32 0
@SEC_VOLTAGE_OFF = global i32 0
@DTV_STREAM_ID = global i32 0
@DTV_TUNE = global i32 0
@FE_SET_PROPERTY = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Error: FE_SET_PROPERTY failed. (errno=%d)\0A\00"
@errno = global i32 0
define i32 @frontend_tune(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4 x %struct.dtv_property]
%12 = alloca %struct.dtv_properties
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
store i64 0, i64* %13
%14 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 0
%15 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 1
store %struct.dtv_property* %14, %struct.dtv_property** %15
%16 = load i32, i32* %6
%17 = call i32 @get_isdbtype(i32 %16)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %4
%21 = load i8*, i8** %7
%22 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%23 = load i64, i64* %22
%24 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 %23
%25 = call i64 @set_isdb_t_frequency(i8* %21, %struct.dtv_property* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 -1, i32* %5
br label %116
28: ; preds = %20
%29 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%30 = load i64, i64* %29
%31 = add i64 %30, 1
store i64 %31, i64* %29
br label %98
32: ; preds = %4
%33 = load i32, i32* %10
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %97
35: ; preds = %32
%36 = load i32, i32* @DTV_VOLTAGE
%37 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%38 = load i64, i64* %37
%39 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 %38
%40 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %39, i32 0, i32 0
store i32 %36, i32* %40
%41 = load i32, i32* %9
%42 = icmp eq i32 %41, 15
br i1 %42, label %43, label %50
43: ; preds = %35
%44 = load i32, i32* @SEC_VOLTAGE_18
%45 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%46 = load i64, i64* %45
%47 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 %46
%48 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %47, i32 0, i32 1
%49 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %48, i32 0, i32 0
store i32 %44, i32* %49
br label %68
50: ; preds = %35
%51 = load i32, i32* %9
%52 = icmp eq i32 %51, 11
br i1 %52, label %53, label %60
53: ; preds = %50
%54 = load i32, i32* @SEC_VOLTAGE_13
%55 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%56 = load i64, i64* %55
%57 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 %56
%58 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %57, i32 0, i32 1
%59 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %58, i32 0, i32 0
store i32 %54, i32* %59
br label %67
60: ; preds = %50
%61 = load i32, i32* @SEC_VOLTAGE_OFF
%62 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%63 = load i64, i64* %62
%64 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 %63
%65 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %64, i32 0, i32 1
%66 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %65, i32 0, i32 0
store i32 %61, i32* %66
br label %67
67: ; preds = %60, %53
br label %68
68: ; preds = %67, %43
%69 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%70 = load i64, i64* %69
%71 = add i64 %70, 1
store i64 %71, i64* %69
%72 = load i8*, i8** %7
%73 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%74 = load i64, i64* %73
%75 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 %74
%76 = call i64 @set_isdb_s_frequency(i8* %72, %struct.dtv_property* %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %68
store i32 -1, i32* %5
br label %116
79: ; preds = %68
%80 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%81 = load i64, i64* %80
%82 = add i64 %81, 1
store i64 %82, i64* %80
%83 = load i32, i32* @DTV_STREAM_ID
%84 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%85 = load i64, i64* %84
%86 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 %85
%87 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %86, i32 0, i32 0
store i32 %83, i32* %87
%88 = load i32, i32* %8
%89 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%90 = load i64, i64* %89
%91 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 %90
%92 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %91, i32 0, i32 1
%93 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %92, i32 0, i32 0
store i32 %88, i32* %93
%94 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%95 = load i64, i64* %94
%96 = add i64 %95, 1
store i64 %96, i64* %94
br label %97
97: ; preds = %79, %32
br label %98
98: ; preds = %97, %28
%99 = load i32, i32* @DTV_TUNE
%100 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%101 = load i64, i64* %100
%102 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %11, i64 0, i64 %101
%103 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %102, i32 0, i32 0
store i32 %99, i32* %103
%104 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
%105 = load i64, i64* %104
%106 = add i64 %105, 1
store i64 %106, i64* %104
%107 = load i32, i32* %6
%108 = load i32, i32* @FE_SET_PROPERTY
%109 = call i32 @ioctl(i32 %107, i32 %108, %struct.dtv_properties* %12)
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %115
111: ; preds = %98
%112 = load i32, i32* @stderr
%113 = load i32, i32* @errno
%114 = call i32 @fprintf(i32 %112, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %113)
store i32 -1, i32* %5
br label %116
115: ; preds = %98
store i32 0, i32* %5
br label %116
116: ; preds = %115, %111, %78, %27
%117 = load i32, i32* %5
ret i32 %117
}

LLVM IR (-O2):
%struct.dtv_property = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.dtv_properties = type { i64, %struct.dtv_property* }
@DTV_VOLTAGE = global i32 0
@SEC_VOLTAGE_18 = global i32 0
@SEC_VOLTAGE_13 = global i32 0
@SEC_VOLTAGE_OFF = global i32 0
@DTV_STREAM_ID = global i32 0
@DTV_TUNE = global i32 0
@FE_SET_PROPERTY = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Error: FE_SET_PROPERTY failed. (errno=%d)\0A\00"
@errno = global i32 0
define i32 @frontend_tune(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [4 x %struct.dtv_property]
%6 = alloca %struct.dtv_properties
%7 = bitcast [4 x %struct.dtv_property]* %5 to i8*
%8 = bitcast %struct.dtv_properties* %6 to i8*
%9 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %6, i64 0, i32 0
%10 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %5, i64 0, i64 0
%11 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %6, i64 0, i32 1
store %struct.dtv_property* %10, %struct.dtv_property** %11
%12 = call i32 @get_isdbtype(i32 %0)
switch i32 %12, label %34 [
i32 0, label %13
i32 1, label %16
]
13: ; preds = %4
%14 = call i64 @set_isdb_t_frequency(i8* %1, %struct.dtv_property* %10)
%15 = icmp eq i64 %14, 0
br i1 %15, label %34, label %46
16: ; preds = %4
%17 = load i32, i32* @DTV_VOLTAGE
%18 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %5, i64 0, i64 0, i32 0
store i32 %17, i32* %18
%19 = icmp eq i32 %3, 11
%20 = icmp eq i32 %3, 15
%21 = load i32, i32* @SEC_VOLTAGE_18
%22 = load i32, i32* @SEC_VOLTAGE_13
%23 = load i32, i32* @SEC_VOLTAGE_OFF
%24 = select i1 %19, i32 %22, i32 %23
%25 = select i1 %20, i32 %21, i32 %24
%26 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %5, i64 0, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %5, i64 0, i64 1
%28 = call i64 @set_isdb_s_frequency(i8* %1, %struct.dtv_property* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %46
30: ; preds = %16
%31 = load i32, i32* @DTV_STREAM_ID
%32 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %5, i64 0, i64 2, i32 0
store i32 %31, i32* %32
%33 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %5, i64 0, i64 2, i32 1, i32 0
store i32 %2, i32* %33
br label %34
34: ; preds = %13, %4, %30
%35 = phi i64 [ 0, %4 ], [ 3, %30 ], [ 1, %13 ]
%36 = load i32, i32* @DTV_TUNE
%37 = getelementptr inbounds [4 x %struct.dtv_property], [4 x %struct.dtv_property]* %5, i64 0, i64 %35, i32 0
store i32 %36, i32* %37
%38 = add nuw nsw i64 %35, 1
store i64 %38, i64* %9
%39 = load i32, i32* @FE_SET_PROPERTY
%40 = call i32 @ioctl(i32 %0, i32 %39, %struct.dtv_properties* %6)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %34
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %34, %16, %13, %42
%47 = phi i32 [ -1, %42 ], [ -1, %13 ], [ -1, %16 ], [ 0, %34 ]
ret i32 %47
}