#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*/ SnifLoop(int, int /*<<< orphan*/);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ menu(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  int fd;
  char device[3];
  if ((argc != 2) && (argc != 3) ||
      ((argc > 2) && ((strlen(argv[1]) != 4) || strncmp(argv[1], "-t", 2)))) {
    menu(argv[0]);
    return 1;
  }
  if (argc == 3)
    strcpy(device, &argv[1][2]);
  else
    strcpy(device, "-1");
  fd = open(argv[argc - 1], O_RDONLY);
  if (fd < 0) {
    perror(argv[argc - 1]);
    return 1;
  }
  SnifLoop(fd, atoi(device));
  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)
cmpl   $0x2,-0x8(%rbp)
je     11ba <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jne    11fd <main+0x6d>
cmpl   $0x2,-0x8(%rbp)
jle    1215 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
cmp    $0x4,%eax
jne    11fd <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe17(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1215 <main+0x85>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <menu@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bf <main+0x12f>
cmpl   $0x3,-0x8(%rbp)
jne    1239 <main+0xa9>
lea    -0x17(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
add    $0x2,%rsi
call   1040 <strcpy@plt>
jmp    1249 <main+0xb9>
lea    -0x17(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1297 <main+0x107>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bf <main+0x12f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x17(%rbp),%rdi
call   10a0 <atoi@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   10b0 <SnifLoop@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    11d4 <main+0x44>
mov    %edi,%ebx
cmp    $0x3,%edi
jb     11e3 <main+0x53>
mov    0x8(%r14),%rdi
call   1060 <strlen@plt>
cmp    $0x4,%eax
jne    11d4 <main+0x44>
mov    0x8(%r14),%rdi
lea    0xe3b(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1234 <main+0xa4>
mov    (%r14),%rdi
call   1050 <menu@plt>
mov    $0x1,%eax
jmp    122b <main+0x9b>
lea    0xe19(%rip),%rsi
lea    0xd(%rsp),%rdi
call   1040 <strcpy@plt>
add    $0xffffffff,%ebx
mov    (%r14,%rbx,8),%rdi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     123e <main+0xae>
mov    %eax,%ebp
lea    0xd(%rsp),%rdi
call   10a0 <atoi@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   10b0 <SnifLoop@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x8(%r14),%rsi
add    $0x2,%rsi
jmp    11ea <main+0x5a>
mov    (%r14,%rbx,8),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
jmp    122b <main+0x9b>

LLVM IR (-O0):
@.str = [3 x i8] c"-t\00"
@.str.1 = [3 x i8] c"-1\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [3 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %28, label %13
13: ; preds = %10, %2
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 2
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
%21 = icmp ne i32 %20, 4
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %22, %16, %10
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @menu(i8* %31)
store i32 1, i32* %3
br label %72
33: ; preds = %22, %13
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 3
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = getelementptr inbounds i8, i8* %40, i64 2
%42 = call i32 @strcpy(i8* %37, i8* %41)
br label %46
43: ; preds = %33
%44 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%45 = call i32 @strcpy(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %43, %36
%47 = load i8**, i8*** %5
%48 = load i32, i32* %4
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %47, i64 %50
%52 = load i8*, i8** %51
%53 = load i32, i32* @O_RDONLY
%54 = call i32 @open(i8* %52, i32 %53)
store i32 %54, i32* %6
%55 = load i32, i32* %6
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %46
%58 = load i8**, i8*** %5
%59 = load i32, i32* %4
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %58, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 @perror(i8* %63)
store i32 1, i32* %3
br label %72
65: ; preds = %46
%66 = load i32, i32* %6
%67 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%68 = call i32 @atoi(i8* %67)
%69 = call i32 @SnifLoop(i32 %66, i32 %68)
%70 = load i32, i32* %6
%71 = call i32 @close(i32 %70)
store i32 0, i32* %3
br label %72
72: ; preds = %65, %57, %28
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [3 x i8] c"-t\00"
@.str.1 = [3 x i8] c"-1\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = and i32 %0, -2
%6 = icmp eq i32 %5, 2
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = icmp ugt i32 %0, 2
br i1 %8, label %9, label %25
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = icmp eq i32 %12, 4
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %2, %14, %9
%19 = load i8*, i8** %1
%20 = tail call i32 @menu(i8* %19)
br label %42
21: ; preds = %14
%22 = load i8*, i8** %10
%23 = getelementptr inbounds i8, i8* %22, i64 2
%24 = call i32 @strcpy(i8* %4, i8* %23)
br label %27
25: ; preds = %7
%26 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = add nsw i32 %0, -1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* %31, i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %27
%36 = load i8*, i8** %30
%37 = call i32 @perror(i8* %36)
br label %42
38: ; preds = %27
%39 = call i32 @atoi(i8* %4)
%40 = call i32 @SnifLoop(i32 %33, i32 %39)
%41 = call i32 @close(i32 %33)
br label %42
42: ; preds = %38, %35, %18
%43 = phi i32 [ 1, %18 ], [ 1, %35 ], [ 0, %38 ]
ret i32 %43
}