#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 */
struct option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
};

/* Variables and functions */
char *basename(char *);
int check_and_pidfile();
int /*<<< orphan*/ close(int);
scalar_t__ daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exec_command(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt_long_only(int, char **, char *, struct option *, int *);
int make_command_socket();
int /*<<< orphan*/ show_version(char const *);
int /*<<< orphan*/ shutdown(int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage(char const *);
int main(int argc, char **argv) {
  const char *pname = basename(argv[0]);
  int oldpid = 0;
  int debug = 0;
  int aircommander_sock = -1;
  while (1) {
    int opt;
    int opt_index;
    static struct option long_opts[] = {
        {"debug", 0, 0, 'd'},
        {"version", 0, 0, 'v'},
        {"help", 0, 0, 'h'},
        {0, 0, 0, 0},
    };
    opt = getopt_long_only(argc, argv, "dvh", long_opts, &opt_index);
    if (opt == -1) {
      break;
    }
    switch (opt) {
    case 'd':
      debug = 1;
      break;
    case 'v':
      show_version(pname);
      break;
    case 'h':
    case '?':
    case '0':
    default:
      usage(pname);
      break;
    }
  }
  oldpid = check_and_pidfile();
  if (oldpid > 0) {
    fprintf(stderr, "warnning another %s is running\n", pname);
    exit(-1);
  }
  if (!debug) {
    if (daemon(0, 0)) {
      fprintf(stderr, "unable daemon - %s\n", strerror(errno));
      exit(-1);
    }
  }
  aircommander_sock = make_command_socket();
  if (aircommander_sock < 0) {
    fprintf(stderr, "unable create command socket\n");
    exit(-1);
  }
  exec_command(aircommander_sock);
  shutdown(aircommander_sock, 2);
  close(aircommander_sock);
  exit(-1);
}


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)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <basename@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdfa(%rip),%rdx
lea    0x2e70(%rip),%rcx
lea    -0x2c(%rbp),%r8
call   1070 <getopt_long_only@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    123b <main+0x6b>
jmp    12c0 <main+0xf0>
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x30,%eax
je     12ad <main+0xdd>
jmp    124f <main+0x7f>
mov    -0x30(%rbp),%eax
sub    $0x3f,%eax
je     12ad <main+0xdd>
jmp    1260 <main+0x90>
mov    -0x30(%rbp),%eax
sub    $0x64,%eax
je     1293 <main+0xc3>
jmp    1271 <main+0xa1>
mov    -0x30(%rbp),%eax
sub    $0x68,%eax
je     12ad <main+0xdd>
jmp    1282 <main+0xb2>
mov    -0x30(%rbp),%eax
sub    $0x76,%eax
je     129f <main+0xcf>
jmp    12b2 <main+0xe2>
movl   $0x1,-0x20(%rbp)
jmp    12bb <main+0xeb>
mov    -0x18(%rbp),%rdi
call   1030 <show_version@plt>
jmp    12bb <main+0xeb>
jmp    12b2 <main+0xe2>
mov    -0x18(%rbp),%rdi
call   10b0 <usage@plt>
jmp    120b <main+0x3b>
mov    $0x0,%al
call   10d0 <check_and_pidfile@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    12f9 <main+0x129>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd2f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jne    1353 <main+0x183>
xor    %esi,%esi
mov    %esi,%edi
call   10a0 <daemon@plt>
cmp    $0x0,%rax
je     134e <main+0x17e>
mov    0x2cc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xcfa(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
jmp    1353 <main+0x183>
mov    $0x0,%al
call   10c0 <make_command_socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1388 <main+0x1b8>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
lea    0xcd4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x24(%rbp),%edi
call   1060 <exec_command@plt>
mov    -0x24(%rbp),%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rdi
call   1090 <basename@plt>
mov    %rax,%r14
movl   $0x0,(%rsp)
lea    0xe1a(%rip),%r15
lea    0x2e90(%rip),%r12
lea    0x4(%rsp),%r13
jmp    1218 <main+0x48>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <show_version@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1070 <getopt_long_only@plt>
cmp    $0x64,%eax
je     1250 <main+0x80>
cmp    $0x76,%eax
je     1210 <main+0x40>
cmp    $0xffffffff,%eax
je     1259 <main+0x89>
mov    %r14,%rdi
call   10b0 <usage@plt>
jmp    1218 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movl   $0x1,(%rsp)
jmp    1218 <main+0x48>
xor    %eax,%eax
call   10d0 <check_and_pidfile@plt>
test   %eax,%eax
jle    127c <main+0xac>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
mov    %r14,%rdx
jmp    1305 <main+0x135>
cmpl   $0x0,(%rsp)
jne    1290 <main+0xc0>
xor    %edi,%edi
xor    %esi,%esi
call   10a0 <daemon@plt>
test   %rax,%rax
jne    12e2 <main+0x112>
xor    %eax,%eax
call   10c0 <make_command_socket@plt>
test   %eax,%eax
jns    12bc <main+0xec>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <exec_command@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%ebx
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd37(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
@main.long_opts = internal global [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8 0, i32 0, i32 100 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8 0, i32 0, i32 118 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8 0, i32 0, i32 104 }, %struct.option zeroinitializer]
@.str = [6 x i8] c"debug\00"
@.str.1 = [8 x i8] c"version\00"
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [4 x i8] c"dvh\00"
@stderr = global i32 0
@.str.4 = [32 x i8] c"warnning another %s is running\0A\00"
@.str.5 = [20 x i8] c"unable daemon - %s\0A\00"
@errno = global i32 0
@.str.6 = [30 x i8] c"unable create command socket\0A\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
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i8* @basename(i8* %14)
store i8* %15, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 -1, i32* %9
br label %16
16: ; preds = %2, %33
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt_long_only(i32 %17, i8** %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([4 x %struct.option], [4 x %struct.option]* @main.long_opts, i64 0, i64 0), i32* %11)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %16
br label %34
23: ; preds = %16
%24 = load i32, i32* %10
switch i32 %24, label %30 [
i32 100, label %25
i32 118, label %26
i32 104, label %29
i32 63, label %29
i32 48, label %29
]
25: ; preds = %23
store i32 1, i32* %8
br label %33
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = call i32 @show_version(i8* %27)
br label %33
29: ; preds = %23, %23, %23
br label %30
30: ; preds = %23, %29
%31 = load i8*, i8** %6
%32 = call i32 @usage(i8* %31)
br label %33
33: ; preds = %30, %26, %25
br label %16
34: ; preds = %22
%35 = call i32 (...) @check_and_pidfile()
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %6
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %34
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 0
br i1 %45, label %56, label %46
46: ; preds = %43
%47 = call i64 @daemon(i32 0, i32 0)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 -1)
unreachable
55: ; preds = %46
br label %56
56: ; preds = %55, %43
%57 = call i32 (...) @make_command_socket()
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %56
%65 = load i32, i32* %9
%66 = call i32 @exec_command(i32 %65)
%67 = load i32, i32* %9
%68 = call i32 @shutdown(i32 %67, i32 2)
%69 = load i32, i32* %9
%70 = call i32 @close(i32 %69)
%71 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@main.long_opts = internal global [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8 0, i32 0, i32 100 }, %struct.option { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8 0, i32 0, i32 118 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8 0, i32 0, i32 104 }, %struct.option zeroinitializer]
@.str = [6 x i8] c"debug\00"
@.str.1 = [8 x i8] c"version\00"
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [4 x i8] c"dvh\00"
@stderr = global i32 0
@.str.4 = [32 x i8] c"warnning another %s is running\0A\00"
@.str.5 = [20 x i8] c"unable daemon - %s\0A\00"
@errno = global i32 0
@.str.6 = [30 x i8] c"unable create command socket\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = load i8*, i8** %1
%5 = tail call i8* @basename(i8* %4)
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %14, %2
%8 = phi i32 [ 0, %2 ], [ %15, %14 ]
%9 = call i32 @getopt_long_only(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([4 x %struct.option], [4 x %struct.option]* @main.long_opts, i64 0, i64 0), i32* %3)
switch i32 %9, label %12 [
i32 -1, label %16
i32 100, label %14
i32 118, label %10
]
10: ; preds = %7
%11 = call i32 @show_version(i8* %5)
br label %14
12: ; preds = %7
%13 = call i32 @usage(i8* %5)
br label %14
14: ; preds = %10, %12, %7
%15 = phi i32 [ %8, %12 ], [ %8, %10 ], [ 1, %7 ]
br label %7
16: ; preds = %7
%17 = call i32 (...) @check_and_pidfile()
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %16
%24 = icmp eq i32 %8, 0
br i1 %24, label %25, label %34
25: ; preds = %23
%26 = call i64 @daemon(i32 0, i32 0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %25, %23
%35 = call i32 (...) @make_command_socket()
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %34
%42 = call i32 @exec_command(i32 %35)
%43 = call i32 @shutdown(i32 %35, i32 2)
%44 = call i32 @close(i32 %35)
%45 = call i32 @exit(i32 -1)
unreachable
}