#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 */
typedef int pid_t;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ and_leds(int, int);
int atol(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ disp_help();
int /*<<< orphan*/ disp_version();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ get_leds(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ nanosecond_wait(int);
int open_con();
int /*<<< orphan*/ optarg;
scalar_t__ optind;
int /*<<< orphan*/ or_leds(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ set_leds(int, int);
int /*<<< orphan*/ xor_leds(int, int);
int main(int argc, char *argv[]) {
  int con;
  short daemon_mode = 0;
  int c;
  pid_t my_pid;
  do {
    c = 0;
    optind = 0;
    while ((c = getopt(argc, argv, "Ddvhgs:a:o:x:w:")) != EOF) {
      switch (c) {
      case 'v':
        disp_version();
        break;
      case 'h':
        disp_help();
        break;
      case 'g':
        con = open_con();
        printf("%i\n", (int)get_leds(con) & 7);
        close(con);
        break;
      case 's':
        con = open_con();
        set_leds(con, atol(optarg) & 7);
        close(con);
        break;
      case 'a':
        con = open_con();
        and_leds(con, atol(optarg) & 7);
        close(con);
        break;
      case 'o':
        con = open_con();
        or_leds(con, atol(optarg) & 7);
        close(con);
        break;
      case 'x':
        con = open_con();
        xor_leds(con, atol(optarg) & 7);
        close(con);
        break;
      case 'D':
        daemon_mode = 1;
        my_pid = fork();
        if (my_pid != -1 && my_pid != 0)
          exit(0);
        break;
      case 'd':
        daemon_mode = 1;
        break;
      case 'w':
        nanosecond_wait(atol(optarg));
        break;
      }
    }
  } while (daemon_mode == 1);
  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)
movw   $0x0,-0x16(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2dbe(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xea5(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2da2(%rip),%rcx
cmp    (%rcx),%eax
je     13ec <main+0x1fc>
mov    -0x1c(%rbp),%eax
add    $0xffffffbc,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x34,%eax
ja     13e7 <main+0x1f7>
mov    -0x28(%rbp),%rax
lea    0xd9a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1080 <disp_version@plt>
jmp    13e7 <main+0x1f7>
mov    $0x0,%al
call   1040 <disp_help@plt>
jmp    13e7 <main+0x1f7>
mov    $0x0,%al
call   1030 <open_con@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <get_leds@plt>
mov    %eax,%esi
and    $0x7,%esi
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    13e7 <main+0x1f7>
mov    $0x0,%al
call   1030 <open_con@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
and    $0x7,%esi
call   1100 <set_leds@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    13e7 <main+0x1f7>
mov    $0x0,%al
call   1030 <open_con@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%esi
and    $0x7,%esi
call   1090 <and_leds@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    13e7 <main+0x1f7>
mov    $0x0,%al
call   1030 <open_con@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
and    $0x7,%esi
call   10a0 <or_leds@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    13e7 <main+0x1f7>
mov    $0x0,%al
call   1030 <open_con@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
and    $0x7,%esi
call   10e0 <xor_leds@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    13e7 <main+0x1f7>
movw   $0x1,-0x16(%rbp)
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
je     13c2 <main+0x1d2>
cmpl   $0x0,-0x20(%rbp)
je     13c2 <main+0x1d2>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    13e7 <main+0x1f7>
movw   $0x1,-0x16(%rbp)
jmp    13e7 <main+0x1f7>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
mov    %eax,%edi
call   10f0 <nanosecond_wait@plt>
jmp    1221 <main+0x31>
jmp    13f1 <main+0x201>
movswl -0x16(%rbp),%eax
cmp    $0x1,%eax
je     120c <main+0x1c>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xecd(%rip),%r14
mov    0x2dd2(%rip),%rbx
lea    0xdeb(%rip),%r15
xor    %r13d,%r13d
jmp    1230 <main+0x40>
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%r13w
mov    $0x1,%r13w
jne    138c <main+0x19c>
mov    0x2da1(%rip),%rax
movq   $0x0,(%rax)
jmp    127e <main+0x8e>
xor    %eax,%eax
call   1030 <open_con@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <get_leds@plt>
and    $0x7,%eax
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    0x2d67(%rip),%rbx
call   1070 <close@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   10c0 <getopt@plt>
cmp    (%rbx),%eax
je     1220 <main+0x30>
add    $0xffffffbc,%eax
cmp    $0x34,%eax
ja     127e <main+0x8e>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
xor    %eax,%eax
call   1110 <fork@plt>
add    $0xffffffff,%eax
mov    $0x1,%r13w
cmp    $0xfffffffd,%eax
ja     127e <main+0x8e>
jmp    139d <main+0x1ad>
xor    %eax,%eax
call   1030 <open_con@plt>
mov    %eax,%ebx
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
and    $0x7,%eax
mov    %ebx,%edi
mov    %eax,%esi
call   1090 <and_leds@plt>
jmp    1270 <main+0x80>
mov    $0x1,%r13w
jmp    127e <main+0x8e>
xor    %eax,%eax
call   1040 <disp_help@plt>
jmp    127e <main+0x8e>
xor    %eax,%eax
call   1030 <open_con@plt>
mov    %eax,%ebx
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
and    $0x7,%eax
mov    %ebx,%edi
mov    %eax,%esi
call   10a0 <or_leds@plt>
jmp    1270 <main+0x80>
xor    %eax,%eax
call   1030 <open_con@plt>
mov    %eax,%ebx
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
and    $0x7,%eax
mov    %ebx,%edi
mov    %eax,%esi
call   1100 <set_leds@plt>
jmp    1270 <main+0x80>
xor    %eax,%eax
call   1080 <disp_version@plt>
jmp    127e <main+0x8e>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
mov    %eax,%edi
call   10f0 <nanosecond_wait@plt>
jmp    127e <main+0x8e>
xor    %eax,%eax
call   1030 <open_con@plt>
mov    %eax,%ebx
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
call   10b0 <atol@plt>
and    $0x7,%eax
mov    %ebx,%edi
mov    %eax,%esi
call   10e0 <xor_leds@plt>
jmp    1270 <main+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@optind = global i64 0
@.str = [16 x i8] c"Ddvhgs:a:o:x:w:\00"
@EOF = global i32 0
@.str.1 = [4 x i8] c"%i\0A\00"
@optarg = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i16
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i16 0, i16* %7
br label %10
10: ; preds = %85, %2
store i32 0, i32* %8
store i64 0, i64* @optind
br label %11
11: ; preds = %83, %10
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %8
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %84
17: ; preds = %11
%18 = load i32, i32* %8
switch i32 %18, label %83 [
i32 118, label %19
i32 104, label %21
i32 103, label %23
i32 115, label %32
i32 97, label %41
i32 111, label %50
i32 120, label %59
i32 68, label %68
i32 100, label %78
i32 119, label %79
]
19: ; preds = %17
%20 = call i32 (...) @disp_version()
br label %83
21: ; preds = %17
%22 = call i32 (...) @disp_help()
br label %83
23: ; preds = %17
%24 = call i32 (...) @open_con()
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = call i64 @get_leds(i32 %25)
%27 = trunc i64 %26 to i32
%28 = and i32 %27, 7
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
br label %83
32: ; preds = %17
%33 = call i32 (...) @open_con()
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = load i32, i32* @optarg
%36 = call i32 @atol(i32 %35)
%37 = and i32 %36, 7
%38 = call i32 @set_leds(i32 %34, i32 %37)
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
br label %83
41: ; preds = %17
%42 = call i32 (...) @open_con()
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = load i32, i32* @optarg
%45 = call i32 @atol(i32 %44)
%46 = and i32 %45, 7
%47 = call i32 @and_leds(i32 %43, i32 %46)
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
br label %83
50: ; preds = %17
%51 = call i32 (...) @open_con()
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = load i32, i32* @optarg
%54 = call i32 @atol(i32 %53)
%55 = and i32 %54, 7
%56 = call i32 @or_leds(i32 %52, i32 %55)
%57 = load i32, i32* %6
%58 = call i32 @close(i32 %57)
br label %83
59: ; preds = %17
%60 = call i32 (...) @open_con()
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = load i32, i32* @optarg
%63 = call i32 @atol(i32 %62)
%64 = and i32 %63, 7
%65 = call i32 @xor_leds(i32 %61, i32 %64)
%66 = load i32, i32* %6
%67 = call i32 @close(i32 %66)
br label %83
68: ; preds = %17
store i16 1, i16* %7
%69 = call i32 (...) @fork()
store i32 %69, i32* %9
%70 = load i32, i32* %9
%71 = icmp ne i32 %70, -1
br i1 %71, label %72, label %77
72: ; preds = %68
%73 = load i32, i32* %9
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 @exit(i32 0)
unreachable
77: ; preds = %72, %68
br label %83
78: ; preds = %17
store i16 1, i16* %7
br label %83
79: ; preds = %17
%80 = load i32, i32* @optarg
%81 = call i32 @atol(i32 %80)
%82 = call i32 @nanosecond_wait(i32 %81)
br label %83
83: ; preds = %17, %79, %78, %77, %59, %50, %41, %32, %23, %21, %19
br label %11
84: ; preds = %11
br label %85
85: ; preds = %84
%86 = load i16, i16* %7
%87 = sext i16 %86 to i32
%88 = icmp eq i32 %87, 1
br i1 %88, label %10, label %89
89: ; preds = %85
ret i32 0
}

LLVM IR (-O2):
@optind = global i64 0
@.str = [16 x i8] c"Ddvhgs:a:o:x:w:\00"
@EOF = global i32 0
@.str.1 = [4 x i8] c"%i\0A\00"
@optarg = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %66, %2
%4 = phi i16 [ 0, %2 ], [ 1, %66 ]
store i64 0, i64* @optind
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %66, label %8
8: ; preds = %3, %61
%9 = phi i32 [ %63, %61 ], [ %5, %3 ]
%10 = phi i16 [ %62, %61 ], [ %4, %3 ]
switch i32 %9, label %61 [
i32 118, label %11
i32 104, label %13
i32 103, label %15
i32 115, label %22
i32 97, label %29
i32 111, label %36
i32 120, label %43
i32 68, label %50
i32 100, label %56
i32 119, label %57
]
11: ; preds = %8
%12 = tail call i32 (...) @disp_version()
br label %61
13: ; preds = %8
%14 = tail call i32 (...) @disp_help()
br label %61
15: ; preds = %8
%16 = tail call i32 (...) @open_con()
%17 = tail call i64 @get_leds(i32 %16)
%18 = trunc i64 %17 to i32
%19 = and i32 %18, 7
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = tail call i32 @close(i32 %16)
br label %61
22: ; preds = %8
%23 = tail call i32 (...) @open_con()
%24 = load i32, i32* @optarg
%25 = tail call i32 @atol(i32 %24)
%26 = and i32 %25, 7
%27 = tail call i32 @set_leds(i32 %23, i32 %26)
%28 = tail call i32 @close(i32 %23)
br label %61
29: ; preds = %8
%30 = tail call i32 (...) @open_con()
%31 = load i32, i32* @optarg
%32 = tail call i32 @atol(i32 %31)
%33 = and i32 %32, 7
%34 = tail call i32 @and_leds(i32 %30, i32 %33)
%35 = tail call i32 @close(i32 %30)
br label %61
36: ; preds = %8
%37 = tail call i32 (...) @open_con()
%38 = load i32, i32* @optarg
%39 = tail call i32 @atol(i32 %38)
%40 = and i32 %39, 7
%41 = tail call i32 @or_leds(i32 %37, i32 %40)
%42 = tail call i32 @close(i32 %37)
br label %61
43: ; preds = %8
%44 = tail call i32 (...) @open_con()
%45 = load i32, i32* @optarg
%46 = tail call i32 @atol(i32 %45)
%47 = and i32 %46, 7
%48 = tail call i32 @xor_leds(i32 %44, i32 %47)
%49 = tail call i32 @close(i32 %44)
br label %61
50: ; preds = %8
%51 = tail call i32 (...) @fork()
%52 = add i32 %51, -1
%53 = icmp ult i32 %52, -2
br i1 %53, label %54, label %61
54: ; preds = %50
%55 = tail call i32 @exit(i32 0)
unreachable
56: ; preds = %8
br label %61
57: ; preds = %8
%58 = load i32, i32* @optarg
%59 = tail call i32 @atol(i32 %58)
%60 = tail call i32 @nanosecond_wait(i32 %59)
br label %61
61: ; preds = %50, %8, %57, %56, %43, %36, %29, %22, %15, %13, %11
%62 = phi i16 [ %10, %8 ], [ %10, %57 ], [ 1, %56 ], [ 1, %50 ], [ %10, %43 ], [ %10, %36 ], [ %10, %29 ], [ %10, %22 ], [ %10, %15 ], [ %10, %13 ], [ %10, %11 ]
%63 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%64 = load i32, i32* @EOF
%65 = icmp eq i32 %63, %64
br i1 %65, label %66, label %8
66: ; preds = %61, %3
%67 = phi i16 [ %4, %3 ], [ %62, %61 ]
%68 = icmp eq i16 %67, 1
br i1 %68, label %3, label %69
69: ; preds = %66
ret i32 0
}