#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 */

/* Variables and functions */
int /*<<< orphan*/ FE_SET_VOLTAGE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEC_VOLTAGE_13;
int /*<<< orphan*/ SEC_VOLTAGE_18;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  char *fedev = "/dev/dvb/adapter0/frontend0";
  int fd, r;
  if (argc != 2 || (strcmp(argv[1], "13") && strcmp(argv[1], "18"))) {
    fprintf(
        stderr,
        "usage: %s <13|18>\n"
        "\n"
        "\nTest switching the voltage signal high and low on a SAT frontend."
        "\n(Note: DiSEqC equipment ignores this after it has once seen a diseqc"
        "\n sequence; reload the driver or unplug/replug the SAT cable to "
        "reset.)"
        "\n"
        "\nusage: FRONTEND=/dev/dvb/adapterX/frontendX setvoltage {13|18}"
        "\n",
        argv[0]);
    return -1;
  }
  if (getenv("FRONTEND"))
    fedev = getenv("FRONTEND");
  printf("setvoltage: using '%s'\n", fedev);
  if ((fd = open(fedev, O_RDWR)) < 0)
    perror("open");
  if (strcmp(argv[1], "13") == 0)
    r = ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13);
  else
    r = ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_18);
  if (r == -1)
    perror("ioctl FE_SET_VOLTAGE");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11e7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe62(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     120f <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     120f <main+0x8f>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe24(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f1 <main+0x171>
lea    0xf2f(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1235 <main+0xb5>
lea    0xf19(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xf0e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    126f <main+0xef>
lea    0xefc(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd9e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12af <main+0x12f>
mov    -0x1c(%rbp),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
mov    0x2d40(%rip),%rax
mov    (%rax),%edx
call   1050 <ioctl@plt>
mov    %eax,-0x20(%rbp)
jmp    12cc <main+0x14c>
mov    -0x1c(%rbp),%edi
mov    0x2d1f(%rip),%rax
mov    (%rax),%esi
mov    0x2cfe(%rip),%rax
mov    (%rax),%edx
call   1050 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    12e2 <main+0x162>
lea    0xe8e(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11b5 <main+0x35>
mov    0x8(%rbx),%rdi
lea    0xe86(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11d7 <main+0x57>
mov    0x8(%rbx),%rdi
lea    0xe74(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11d7 <main+0x57>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe5a(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    125c <main+0xdc>
lea    0xf67(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe13(%rip),%rbp
cmovne %rax,%rbp
lea    0xf56(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1263 <main+0xe3>
mov    0x8(%rbx),%rdi
lea    0xdfa(%rip),%rsi
call   1070 <strcmp@plt>
mov    0x2daa(%rip),%rcx
mov    (%rcx),%esi
test   %rax,%rax
jne    123e <main+0xbe>
mov    0x2da4(%rip),%rax
jmp    1245 <main+0xc5>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1271 <main+0xf1>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xefc(%rip),%rdi
call   10a0 <perror@plt>
jmp    1217 <main+0x97>
lea    0xef3(%rip),%rdi
call   10a0 <perror@plt>
jmp    1253 <main+0xd3>

LLVM IR (-O0):
@.str = [28 x i8] c"/dev/dvb/adapter0/frontend0\00"
@.str.1 = [3 x i8] c"13\00"
@.str.2 = [3 x i8] c"18\00"
@stderr = global i32 0
@.str.3 = [291 x i8] c"usage: %s <13|18>\0A\0A\0ATest switching the voltage signal high and low on a SAT frontend.\0A(Note: DiSEqC equipment ignores this after it has once seen a diseqc\0A sequence; reload the driver or unplug/replug the SAT cable to reset.)\0A\0Ausage: FRONTEND=/dev/dvb/adapterX/frontendX setvoltage {13|18}\0A\00"
@.str.4 = [9 x i8] c"FRONTEND\00"
@.str.5 = [24 x i8] c"setvoltage: using '%s'\0A\00"
@O_RDWR = global i32 0
@.str.6 = [5 x i8] c"open\00"
@FE_SET_VOLTAGE = global i32 0
@SEC_VOLTAGE_13 = global i32 0
@SEC_VOLTAGE_18 = global i32 0
@.str.7 = [21 x i8] c"ioctl FE_SET_VOLTAGE\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %23, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %11
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %17, %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([291 x i8], [291 x i8]* @.str.3, i64 0, i64 0), i8* %27)
store i32 -1, i32* %3
br label %67
29: ; preds = %17, %11
%30 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i8* %33, i8** %6
br label %34
34: ; preds = %32, %29
%35 = load i8*, i8** %6
%36 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %6
%38 = load i32, i32* @O_RDWR
%39 = call i32 @open(i8* %37, i32 %38)
store i32 %39, i32* %7
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %43
43: ; preds = %41, %34
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %43
%50 = load i32, i32* %7
%51 = load i32, i32* @FE_SET_VOLTAGE
%52 = load i32, i32* @SEC_VOLTAGE_13
%53 = call i32 @ioctl(i32 %50, i32 %51, i32 %52)
store i32 %53, i32* %8
br label %59
54: ; preds = %43
%55 = load i32, i32* %7
%56 = load i32, i32* @FE_SET_VOLTAGE
%57 = load i32, i32* @SEC_VOLTAGE_18
%58 = call i32 @ioctl(i32 %55, i32 %56, i32 %57)
store i32 %58, i32* %8
br label %59
59: ; preds = %54, %49
%60 = load i32, i32* %8
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %62, %59
%65 = load i32, i32* %7
%66 = call i32 @close(i32 %65)
store i32 0, i32* %3
br label %67
67: ; preds = %64, %23
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [28 x i8] c"/dev/dvb/adapter0/frontend0\00"
@.str.1 = [3 x i8] c"13\00"
@.str.2 = [3 x i8] c"18\00"
@stderr = global i32 0
@.str.3 = [291 x i8] c"usage: %s <13|18>\0A\0A\0ATest switching the voltage signal high and low on a SAT frontend.\0A(Note: DiSEqC equipment ignores this after it has once seen a diseqc\0A sequence; reload the driver or unplug/replug the SAT cable to reset.)\0A\0Ausage: FRONTEND=/dev/dvb/adapterX/frontendX setvoltage {13|18}\0A\00"
@.str.4 = [9 x i8] c"FRONTEND\00"
@.str.5 = [24 x i8] c"setvoltage: using '%s'\0A\00"
@O_RDWR = global i32 0
@.str.6 = [5 x i8] c"open\00"
@FE_SET_VOLTAGE = global i32 0
@SEC_VOLTAGE_13 = global i32 0
@SEC_VOLTAGE_18 = global i32 0
@.str.7 = [21 x i8] c"ioctl FE_SET_VOLTAGE\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9, %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([291 x i8], [291 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %41
17: ; preds = %9, %4
%18 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i8* %18, null
%20 = select i1 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %18
%21 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @O_RDWR
%23 = tail call i32 @open(i8* %20, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %27
27: ; preds = %25, %17
%28 = load i8*, i8** %5
%29 = tail call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
%31 = load i32, i32* @FE_SET_VOLTAGE
%32 = load i32, i32* @SEC_VOLTAGE_13
%33 = load i32, i32* @SEC_VOLTAGE_18
%34 = select i1 %30, i32 %32, i32 %33
%35 = tail call i32 @ioctl(i32 %23, i32 %31, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %39
39: ; preds = %37, %27
%40 = tail call i32 @close(i32 %23)
br label %41
41: ; preds = %39, %13
%42 = phi i32 [ -1, %13 ], [ 0, %39 ]
ret i32 %42
}