#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*/ O_RDONLY;
int /*<<< orphan*/ chck_frontend_state(int);
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int strtol(int /*<<< orphan*/, char **, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int adapter = 0;
  int minor = 0;
  char devname[80];
  int fd_front;
  int c;
  memset(devname, 0, 80);
  for (;;) {
    if (-1 == (c = getopt(argc, argv, "a:")))
      break;
    switch (c) {
    case 'a':
      adapter = strtol(optarg, (char **)NULL, 0);
      break;
    case 'm':
      minor = strtol(optarg, (char **)NULL, 0);
      break;
    }
  }
  sprintf(devname, "/dev/dvb/adapter%d/frontend%d", adapter, minor);
  if ((fd_front = open(devname, O_RDONLY)) < 0) {
    perror("frontend");
    printf("Error opening %s\n", devname);
    exit(1);
  }
  chck_frontend_state(fd_front);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2b(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,%ecx
mov    %ecx,-0x78(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11f1 <main+0x61>
jmp    124e <main+0xbe>
mov    -0x78(%rbp),%eax
mov    %eax,-0x7c(%rbp)
sub    $0x61,%eax
je     1216 <main+0x86>
jmp    1205 <main+0x75>
mov    -0x7c(%rbp),%eax
sub    $0x6d,%eax
je     1232 <main+0xa2>
jmp    1249 <main+0xb9>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x14(%rbp)
jmp    1249 <main+0xb9>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x18(%rbp)
jmp    11c7 <main+0x37>
lea    -0x70(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xda4(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
jge    12a8 <main+0x118>
lea    0xd98(%rip),%rdi
call   1080 <perror@plt>
lea    -0x70(%rbp),%rsi
lea    0xd91(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x74(%rbp),%edi
call   1030 <chck_frontend_state@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
lea    0xe44(%rip),%r15
mov    0x2e35(%rip),%r13
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     1210 <main+0x80>
cmp    $0x6d,%eax
je     11fe <main+0x6e>
cmp    $0x61,%eax
jne    11d0 <main+0x40>
mov    0x0(%r13),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%r12d
jmp    11d0 <main+0x40>
mov    0x0(%r13),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%r14d
jmp    11d0 <main+0x40>
lea    0xdec(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r12d,%edx
mov    %r14d,%ecx
call   10a0 <sprintf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1255 <main+0xc5>
mov    %eax,%edi
call   1030 <chck_frontend_state@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc5(%rip),%rdi
call   1080 <perror@plt>
lea    0xdc2(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"a:\00"
@optarg = global i32 0
@.str.1 = [30 x i8] c"/dev/dvb/adapter%d/frontend%d\00"
@O_RDONLY = global i32 0
@.str.2 = [9 x i8] c"frontend\00"
@.str.3 = [18 x i8] c"Error opening %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [80 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 80)
br label %13
13: ; preds = %27, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %10
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %19
18: ; preds = %13
br label %28
19: ; preds = %13
%20 = load i32, i32* %10
switch i32 %20, label %27 [
i32 97, label %21
i32 109, label %24
]
21: ; preds = %19
%22 = load i32, i32* @optarg
%23 = call i32 @strtol(i32 %22, i8** null, i32 0)
store i32 %23, i32* %6
br label %27
24: ; preds = %19
%25 = load i32, i32* @optarg
%26 = call i32 @strtol(i32 %25, i8** null, i32 0)
store i32 %26, i32* %7
br label %27
27: ; preds = %19, %24, %21
br label %13
28: ; preds = %18
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %31)
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%34 = load i32, i32* @O_RDONLY
%35 = call i32 @open(i8* %33, i32 %34)
store i32 %35, i32* %9
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %28
%38 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%40 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %28
%43 = load i32, i32* %9
%44 = call i32 @chck_frontend_state(i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"a:\00"
@optarg = global i32 0
@.str.1 = [30 x i8] c"/dev/dvb/adapter%d/frontend%d\00"
@O_RDONLY = global i32 0
@.str.2 = [9 x i8] c"frontend\00"
@.str.3 = [18 x i8] c"Error opening %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 80)
br label %6
6: ; preds = %16, %2
%7 = phi i32 [ %18, %16 ], [ 0, %2 ]
%8 = phi i32 [ %10, %16 ], [ 0, %2 ]
br label %9
9: ; preds = %6, %13
%10 = phi i32 [ %8, %6 ], [ %15, %13 ]
br label %11
11: ; preds = %9, %11
%12 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %12, label %11 [
i32 -1, label %19
i32 97, label %13
i32 109, label %16
]
13: ; preds = %11
%14 = load i32, i32* @optarg
%15 = call i32 @strtol(i32 %14, i8** null, i32 0)
br label %9
16: ; preds = %11
%17 = load i32, i32* @optarg
%18 = call i32 @strtol(i32 %17, i8** null, i32 0)
br label %6
19: ; preds = %11
%20 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %7)
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %4, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = call i32 @chck_frontend_state(i32 %22)
ret i32 0
}