#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_TONE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEC_TONE_OFF;
int /*<<< orphan*/ SEC_TONE_ON;
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], "on") && strcmp(argv[1], "off"))) {
    fprintf(stderr, "usage: %s <on|off>\n", argv[0]);
    return 1;
  }
  if (getenv("FRONTEND"))
    fedev = getenv("FRONTEND");
  printf("set22k: using '%s'\n", fedev);
  if ((fd = open(fedev, O_RDWR)) < 0) {
    perror("open");
    return 1;
  }
  if (strcmp(argv[1], "on") == 0)
    r = ioctl(fd, FE_SET_TONE, SEC_TONE_ON);
  else
    r = ioctl(fd, FE_SET_TONE, SEC_TONE_OFF);
  if (r == -1)
    perror("ioctl FE_SET_TONE");
  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    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe25(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fd <main+0x17d>
lea    0xe21(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1235 <main+0xb5>
lea    0xe0b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe00(%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    127b <main+0xfb>
lea    0xdea(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fd <main+0x17d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd92(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12bb <main+0x13b>
mov    -0x1c(%rbp),%edi
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
mov    0x2d1c(%rip),%rax
mov    (%rax),%edx
call   1050 <ioctl@plt>
mov    %eax,-0x20(%rbp)
jmp    12d8 <main+0x158>
mov    -0x1c(%rbp),%edi
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
mov    0x2cf2(%rip),%rax
mov    (%rax),%edx
call   1050 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    12ee <main+0x16e>
lea    0xd70(%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    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe5b(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    125c <main+0xdc>
lea    0xe59(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe13(%rip),%rbp
cmovne %rax,%rbp
lea    0xe48(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1263 <main+0xe3>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
lea    0xdfa(%rip),%rsi
call   1070 <strcmp@plt>
mov    0x2db2(%rip),%rcx
mov    (%rcx),%esi
test   %rax,%rax
jne    123e <main+0xbe>
mov    0x2d8c(%rip),%rax
jmp    1245 <main+0xc5>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1276 <main+0xf6>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdea(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
jmp    125c <main+0xdc>
lea    0xddc(%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"on\00"
@.str.2 = [4 x i8] c"off\00"
@stderr = global i32 0
@.str.3 = [20 x i8] c"usage: %s <on|off>\0A\00"
@.str.4 = [9 x i8] c"FRONTEND\00"
@.str.5 = [20 x i8] c"set22k: using '%s'\0A\00"
@O_RDWR = global i32 0
@.str.6 = [5 x i8] c"open\00"
@FE_SET_TONE = global i32 0
@SEC_TONE_ON = global i32 0
@SEC_TONE_OFF = global i32 0
@.str.7 = [18 x i8] c"ioctl FE_SET_TONE\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 ([4 x i8], [4 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 ([20 x i8], [20 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 ([20 x i8], [20 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))
store i32 1, i32* %3
br label %67
43: ; preds = %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_TONE
%52 = load i32, i32* @SEC_TONE_ON
%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_TONE
%57 = load i32, i32* @SEC_TONE_OFF
%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 ([18 x i8], [18 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, %41, %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"on\00"
@.str.2 = [4 x i8] c"off\00"
@stderr = global i32 0
@.str.3 = [20 x i8] c"usage: %s <on|off>\0A\00"
@.str.4 = [9 x i8] c"FRONTEND\00"
@.str.5 = [20 x i8] c"set22k: using '%s'\0A\00"
@O_RDWR = global i32 0
@.str.6 = [5 x i8] c"open\00"
@FE_SET_TONE = global i32 0
@SEC_TONE_ON = global i32 0
@SEC_TONE_OFF = global i32 0
@.str.7 = [18 x i8] c"ioctl FE_SET_TONE\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 ([4 x i8], [4 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 ([20 x i8], [20 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 ([20 x i8], [20 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 %41
27: ; preds = %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_TONE
%32 = load i32, i32* @SEC_TONE_ON
%33 = load i32, i32* @SEC_TONE_OFF
%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 ([18 x i8], [18 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, %25, %13
%42 = phi i32 [ 1, %13 ], [ 1, %25 ], [ 0, %39 ]
ret i32 %42
}