#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_DISEQC_SEND_BURST;
int /*<<< orphan*/ FE_SET_TONE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEC_MINI_A;
int /*<<< orphan*/ SEC_MINI_B;
int /*<<< orphan*/ SEC_TONE_OFF;
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 /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  char *fedev = "/dev/dvb/adapter0/frontend0";
  int fd, r;
  if (argc != 2 || (strcmp(argv[1], "a") && strcmp(argv[1], "b"))) {
    fprintf(stderr, "usage: %s <a|b>\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;
  }
  ioctl(fd, FE_SET_TONE, SEC_TONE_OFF);
  usleep(30000);
  if (strcmp(argv[1], "a") == 0)
    r = ioctl(fd, FE_DISEQC_SEND_BURST, SEC_MINI_A);
  else
    r = ioctl(fd, FE_DISEQC_SEND_BURST, SEC_MINI_B);
  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    0xe53(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11f7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe52(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     121f <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe36(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     121f <main+0x8f>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe12(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1331 <main+0x1a1>
lea    0xe0b(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1245 <main+0xb5>
lea    0xdf5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xdea(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    128b <main+0xfb>
lea    0xdd4(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1331 <main+0x1a1>
mov    -0x1c(%rbp),%edi
mov    0x2d4b(%rip),%rax
mov    (%rax),%esi
mov    0x2d12(%rip),%rax
mov    (%rax),%edx
call   1050 <ioctl@plt>
mov    $0x7530,%edi
call   10b0 <usleep@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd5e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12ef <main+0x15f>
mov    -0x1c(%rbp),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
call   1050 <ioctl@plt>
mov    %eax,-0x20(%rbp)
jmp    130c <main+0x17c>
mov    -0x1c(%rbp),%edi
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
mov    0x2cb6(%rip),%rax
mov    (%rax),%edx
call   1050 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1322 <main+0x192>
lea    0xd36(%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    11c5 <main+0x35>
mov    0x8(%rbx),%rdi
lea    0xe76(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11e7 <main+0x57>
mov    0x8(%rbx),%rdi
lea    0xe63(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11e7 <main+0x57>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe48(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    128f <main+0xff>
lea    0xe43(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe03(%rip),%rbp
cmovne %rax,%rbp
lea    0xe32(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1296 <main+0x106>
mov    %eax,%ebp
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
mov    0x2d79(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <ioctl@plt>
mov    $0x7530,%edi
call   10b0 <usleep@plt>
mov    0x8(%rbx),%rdi
lea    0xdc7(%rip),%rsi
call   1070 <strcmp@plt>
mov    0x2d77(%rip),%rcx
mov    (%rcx),%esi
test   %rax,%rax
jne    1271 <main+0xe1>
mov    0x2d59(%rip),%rax
jmp    1278 <main+0xe8>
mov    0x2d40(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12a9 <main+0x119>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdb1(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
jmp    128f <main+0xff>
lea    0xda3(%rip),%rdi
call   10a0 <perror@plt>
jmp    1286 <main+0xf6>

LLVM IR (-O0):
@.str = [28 x i8] c"/dev/dvb/adapter0/frontend0\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [2 x i8] c"b\00"
@stderr = global i32 0
@.str.3 = [17 x i8] c"usage: %s <a|b>\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_OFF = global i32 0
@FE_DISEQC_SEND_BURST = global i32 0
@SEC_MINI_A = global i32 0
@SEC_MINI_B = 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 ([2 x i8], [2 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 ([2 x i8], [2 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 ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %72
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 %72
43: ; preds = %34
%44 = load i32, i32* %7
%45 = load i32, i32* @FE_SET_TONE
%46 = load i32, i32* @SEC_TONE_OFF
%47 = call i32 @ioctl(i32 %44, i32 %45, i32 %46)
%48 = call i32 @usleep(i32 30000)
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %43
%55 = load i32, i32* %7
%56 = load i32, i32* @FE_DISEQC_SEND_BURST
%57 = load i32, i32* @SEC_MINI_A
%58 = call i32 @ioctl(i32 %55, i32 %56, i32 %57)
store i32 %58, i32* %8
br label %64
59: ; preds = %43
%60 = load i32, i32* %7
%61 = load i32, i32* @FE_DISEQC_SEND_BURST
%62 = load i32, i32* @SEC_MINI_B
%63 = call i32 @ioctl(i32 %60, i32 %61, i32 %62)
store i32 %63, i32* %8
br label %64
64: ; preds = %59, %54
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
%70 = load i32, i32* %7
%71 = call i32 @close(i32 %70)
store i32 0, i32* %3
br label %72
72: ; preds = %69, %41, %23
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [28 x i8] c"/dev/dvb/adapter0/frontend0\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [2 x i8] c"b\00"
@stderr = global i32 0
@.str.3 = [17 x i8] c"usage: %s <a|b>\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_OFF = global i32 0
@FE_DISEQC_SEND_BURST = global i32 0
@SEC_MINI_A = global i32 0
@SEC_MINI_B = 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 ([2 x i8], [2 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 ([2 x i8], [2 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 ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %45
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 %45
27: ; preds = %17
%28 = load i32, i32* @FE_SET_TONE
%29 = load i32, i32* @SEC_TONE_OFF
%30 = tail call i32 @ioctl(i32 %23, i32 %28, i32 %29)
%31 = tail call i32 @usleep(i32 30000)
%32 = load i8*, i8** %5
%33 = tail call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
%35 = load i32, i32* @FE_DISEQC_SEND_BURST
%36 = load i32, i32* @SEC_MINI_A
%37 = load i32, i32* @SEC_MINI_B
%38 = select i1 %34, i32 %36, i32 %37
%39 = tail call i32 @ioctl(i32 %23, i32 %35, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %27
%42 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %43
43: ; preds = %41, %27
%44 = tail call i32 @close(i32 %23)
br label %45
45: ; preds = %43, %25, %13
%46 = phi i32 [ 1, %13 ], [ 1, %25 ], [ 0, %43 ]
ret i32 %46
}