#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*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ lightcount_help();
void *memory_alloc();
int /*<<< orphan*/ memory_free(void *);
int /*<<< orphan*/ memory_help();
int sniff_create_socket(char const *const);
int /*<<< orphan*/ sniff_help();
int /*<<< orphan*/ sniff_loop(int, void *, void *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ storage_close();
int /*<<< orphan*/ storage_help();
scalar_t__ storage_open(char const *const);
int /*<<< orphan*/ timer_help();
int /*<<< orphan*/ timer_loop_bg(void *, void *);
int /*<<< orphan*/ timer_loop_stop();
int main(int argc, char const *const *argv) {
  int socket = -1;
  void *memory[2];
  if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'h' &&
      argv[1][2] == '\0') {
    lightcount_help();
    sniff_help();
    memory_help();
    timer_help();
    storage_help();
    return 0;
  }
  if (argc != 3 || (socket = sniff_create_socket(argv[1])) < 0 ||
      storage_open(argv[2]) != 0) {
    if (socket >= 0)
      close(socket);
    fprintf(stderr, "lightcount: Initialization failed or bad command line "
                    "options. See -h for help.\n");
    return 0;
  }
  memory[0] = memory_alloc();
  memory[1] = memory_alloc();
  assert(memory[0] != NULL && memory[1] != NULL);
  timer_loop_bg(memory[0], memory[1]);
  sniff_loop(socket, memory[0], memory[1]);
  timer_loop_stop();
  memory_free(memory[0]);
  memory_free(memory[1]);
  storage_close();
  close(socket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1294 <main+0x94>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1294 <main+0x94>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x68,%eax
jne    1294 <main+0x94>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    1294 <main+0x94>
mov    $0x0,%al
call   10b0 <lightcount_help@plt>
mov    $0x0,%al
call   1050 <sniff_help@plt>
mov    $0x0,%al
call   1060 <memory_help@plt>
mov    $0x0,%al
call   1100 <timer_help@plt>
mov    $0x0,%al
call   10e0 <storage_help@plt>
movl   $0x0,-0x4(%rbp)
jmp    138b <main+0x18b>
cmpl   $0x3,-0x8(%rbp)
jne    12ce <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <sniff_create_socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     12ce <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <storage_open@plt>
cmp    $0x0,%rax
je     1301 <main+0x101>
cmpl   $0x0,-0x14(%rbp)
jl     12e0 <main+0xe0>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xd10(%rip),%rsi
call   10d0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    138b <main+0x18b>
mov    $0x0,%al
call   1090 <memory_alloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1090 <memory_alloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x31(%rbp)
je     1332 <main+0x132>
cmpq   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <timer_loop_bg@plt>
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <sniff_loop@plt>
mov    $0x0,%al
call   1110 <timer_loop_stop@plt>
mov    -0x30(%rbp),%rdi
call   1070 <memory_free@plt>
mov    -0x28(%rbp),%rdi
call   1070 <memory_free@plt>
mov    $0x0,%al
call   1120 <storage_close@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
je     124e <main+0x4e>
cmp    $0x2,%edi
jne    1272 <main+0x72>
mov    0x8(%rbx),%rax
cmpb   $0x2d,(%rax)
jne    1272 <main+0x72>
cmpb   $0x68,0x1(%rax)
jne    1272 <main+0x72>
cmpb   $0x0,0x2(%rax)
jne    1272 <main+0x72>
xor    %eax,%eax
call   10b0 <lightcount_help@plt>
xor    %eax,%eax
call   1050 <sniff_help@plt>
xor    %eax,%eax
call   1060 <memory_help@plt>
xor    %eax,%eax
call   1100 <timer_help@plt>
xor    %eax,%eax
call   10e0 <storage_help@plt>
jmp    1287 <main+0x87>
mov    0x8(%rbx),%rdi
call   1040 <sniff_create_socket@plt>
test   %eax,%eax
js     1272 <main+0x72>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   10f0 <storage_open@plt>
test   %rax,%rax
je     1294 <main+0x94>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
call   10d0 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1090 <memory_alloc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1090 <memory_alloc@plt>
mov    %rax,%r15
test   %r14,%r14
setne  %al
test   %r15,%r15
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   10c0 <assert@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <timer_loop_bg@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <sniff_loop@plt>
xor    %eax,%eax
call   1110 <timer_loop_stop@plt>
mov    %r14,%rdi
call   1070 <memory_free@plt>
mov    %r15,%rdi
call   1070 <memory_free@plt>
xor    %eax,%eax
call   1120 <storage_close@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
jmp    1287 <main+0x87>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [81 x i8] c"lightcount: Initialization failed or bad command line options. See -h for help.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %40
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 45
br i1 %17, label %18, label %40
18: ; preds = %10
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 104
br i1 %25, label %26, label %40
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8, i8* %29, i64 2
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %26
%35 = call i32 (...) @lightcount_help()
%36 = call i32 (...) @sniff_help()
%37 = call i32 (...) @memory_help()
%38 = call i32 (...) @timer_help()
%39 = call i32 (...) @storage_help()
store i32 0, i32* %3
br label %101
40: ; preds = %26, %18, %10, %2
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 3
br i1 %42, label %55, label %43
43: ; preds = %40
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @sniff_create_socket(i8* %46)
store i32 %47, i32* %6
%48 = icmp slt i32 %47, 0
br i1 %48, label %55, label %49
49: ; preds = %43
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i64 @storage_open(i8* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %64
55: ; preds = %49, %43, %40
%56 = load i32, i32* %6
%57 = icmp sge i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %6
%60 = call i32 @close(i32 %59)
br label %61
61: ; preds = %58, %55
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %101
64: ; preds = %49
%65 = call i8* (...) @memory_alloc()
%66 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
store i8* %65, i8** %66
%67 = call i8* (...) @memory_alloc()
%68 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
store i8* %67, i8** %68
%69 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%70 = load i8*, i8** %69
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %76
72: ; preds = %64
%73 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
%74 = load i8*, i8** %73
%75 = icmp ne i8* %74, null
br label %76
76: ; preds = %72, %64
%77 = phi i1 [ false, %64 ], [ %75, %72 ]
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%81 = load i8*, i8** %80
%82 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
%83 = load i8*, i8** %82
%84 = call i32 @timer_loop_bg(i8* %81, i8* %83)
%85 = load i32, i32* %6
%86 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%87 = load i8*, i8** %86
%88 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
%89 = load i8*, i8** %88
%90 = call i32 @sniff_loop(i32 %85, i8* %87, i8* %89)
%91 = call i32 (...) @timer_loop_stop()
%92 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%93 = load i8*, i8** %92
%94 = call i32 @memory_free(i8* %93)
%95 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
%96 = load i8*, i8** %95
%97 = call i32 @memory_free(i8* %96)
%98 = call i32 (...) @storage_close()
%99 = load i32, i32* %6
%100 = call i32 @close(i32 %99)
store i32 0, i32* %3
br label %101
101: ; preds = %76, %61, %34
%102 = load i32, i32* %3
ret i32 %102
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [81 x i8] c"lightcount: Initialization failed or bad command line options. See -h for help.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %34 [
i32 2, label %3
i32 3, label %22
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 45
br i1 %7, label %8, label %34
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 104
br i1 %11, label %12, label %34
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %5, i64 2
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = tail call i32 (...) @lightcount_help()
%18 = tail call i32 (...) @sniff_help()
%19 = tail call i32 (...) @memory_help()
%20 = tail call i32 (...) @timer_help()
%21 = tail call i32 (...) @storage_help()
br label %52
22: ; preds = %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @sniff_create_socket(i8* %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %22
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i64 @storage_open(i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = tail call i32 @close(i32 %25)
br label %34
34: ; preds = %3, %8, %12, %2, %22, %32
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
br label %52
37: ; preds = %27
%38 = tail call i8* (...) @memory_alloc()
%39 = tail call i8* (...) @memory_alloc()
%40 = icmp ne i8* %38, null
%41 = icmp ne i8* %39, null
%42 = select i1 %40, i1 %41, i1 false
%43 = zext i1 %42 to i32
%44 = tail call i32 @assert(i32 %43)
%45 = tail call i32 @timer_loop_bg(i8* %38, i8* %39)
%46 = tail call i32 @sniff_loop(i32 %25, i8* %38, i8* %39)
%47 = tail call i32 (...) @timer_loop_stop()
%48 = tail call i32 @memory_free(i8* %38)
%49 = tail call i32 @memory_free(i8* %39)
%50 = tail call i32 (...) @storage_close()
%51 = tail call i32 @close(i32 %25)
br label %52
52: ; preds = %37, %34, %16
ret i32 0
}