#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*/ close_uinput();
int /*<<< orphan*/ daemonKill(char *);
int /*<<< orphan*/ daemonize(char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ init_config();
int /*<<< orphan*/ init_iic();
scalar_t__ init_uinput();
int /*<<< orphan*/ joy_RPi_exit();
scalar_t__ joy_RPi_init();
int /*<<< orphan*/ joy_RPi_poll();
int /*<<< orphan*/ joy_enable_repeat();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ showHelp();
int /*<<< orphan*/ showVersion();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  int en_daemonize = 0;
  int i;
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-d")) {
      en_daemonize = 1;
    }
    if (!strcmp(argv[i], "-k")) {
      daemonKill("/tmp/pikeyd.pid");
      exit(0);
    }
    if (!strcmp(argv[i], "-r")) {
      joy_enable_repeat();
    }
    if (!strcmp(argv[i], "-v")) {
      showVersion();
      exit(0);
    }
    if (!strcmp(argv[i], "-h")) {
      showHelp();
      exit(0);
    }
  }
  if (en_daemonize) {
    daemonize("/tmp", "/tmp/pikeyd.pid");
  }
  init_iic();
  init_config();
  if (init_uinput() == 0) {
    sleep(1);
    if (joy_RPi_init() >= 0) {
      if (!en_daemonize) {
        printf("Press ^C to exit.\n");
      }
      for (;;) {
        joy_RPi_poll();
        usleep(4000);
      }
      joy_RPi_exit();
    }
    close_uinput();
  }
  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)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1325 <main+0x125>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdbd(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1258 <main+0x58>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd98(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    128c <main+0x8c>
lea    0xd86(%rip),%rdi
call   1110 <daemonKill@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd77(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12b4 <main+0xb4>
mov    $0x0,%al
call   10d0 <joy_enable_repeat@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd52(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12e3 <main+0xe3>
mov    $0x0,%al
call   1090 <showVersion@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd26(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1312 <main+0x112>
mov    $0x0,%al
call   1050 <showHelp@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    1317 <main+0x117>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1224 <main+0x24>
cmpl   $0x0,-0x14(%rbp)
je     1342 <main+0x142>
lea    0xce9(%rip),%rdi
lea    0xcc9(%rip),%rsi
call   1070 <daemonize@plt>
mov    $0x0,%al
call   1060 <init_iic@plt>
mov    $0x0,%al
call   10b0 <init_config@plt>
mov    $0x0,%al
call   10e0 <init_uinput@plt>
cmp    $0x0,%rax
jne    13b4 <main+0x1b4>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    $0x0,%al
call   1040 <joy_RPi_init@plt>
cmp    $0x0,%rax
jl     13ad <main+0x1ad>
cmpl   $0x0,-0x14(%rbp)
jne    1392 <main+0x192>
lea    0xc97(%rip),%rdi
call   1080 <printf@plt>
jmp    1397 <main+0x197>
mov    $0x0,%al
call   10c0 <joy_RPi_poll@plt>
mov    $0xfa0,%edi
call   1120 <usleep@plt>
jmp    1397 <main+0x197>
mov    $0x0,%al
call   1030 <close_uinput@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%bpl
cmp    $0x2,%edi
jl     12d7 <main+0xd7>
mov    %rsi,%rbx
mov    %edi,%r15d
mov    $0x1,%r12d
lea    0xdf2(%rip),%rbp
xor    %r13d,%r13d
nopl   (%rax)
mov    (%rbx,%r12,8),%r14
mov    %r14,%rdi
lea    0xdc2(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
mov    $0x1,%eax
cmove  %eax,%r13d
mov    %r14,%rdi
lea    0xdab(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     134c <main+0x14c>
mov    %r14,%rdi
lea    0xda7(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
jne    1283 <main+0x83>
xor    %eax,%eax
call   10d0 <joy_enable_repeat@plt>
mov    (%rbx,%r12,8),%r14
mov    %r14,%rdi
lea    0xd8c(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     135f <main+0x15f>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     136d <main+0x16d>
add    $0x1,%r12
cmp    %r12,%r15
jne    1230 <main+0x30>
test   %r13d,%r13d
mov    $0x1,%bpl
je     12d7 <main+0xd7>
lea    0xd56(%rip),%rdi
lea    0xd36(%rip),%rsi
call   1080 <daemonize@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <init_iic@plt>
xor    %eax,%eax
call   10b0 <init_config@plt>
xor    %eax,%eax
call   10e0 <init_uinput@plt>
test   %rax,%rax
je     1302 <main+0x102>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1100 <sleep@plt>
xor    %eax,%eax
call   1040 <joy_RPi_init@plt>
test   %rax,%rax
js     1343 <main+0x143>
test   %bpl,%bpl
je     1330 <main+0x130>
lea    0xd00(%rip),%rdi
call   1070 <puts@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   10c0 <joy_RPi_poll@plt>
mov    $0xfa0,%edi
call   1120 <usleep@plt>
jmp    1330 <main+0x130>
xor    %eax,%eax
call   1030 <close_uinput@plt>
jmp    12f1 <main+0xf1>
lea    0xcb3(%rip),%rdi
call   1110 <daemonKill@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
xor    %eax,%eax
call   1090 <showVersion@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
xor    %eax,%eax
call   1050 <showHelp@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-d\00"
@.str.1 = [3 x i8] c"-k\00"
@.str.2 = [16 x i8] c"/tmp/pikeyd.pid\00"
@.str.3 = [3 x i8] c"-r\00"
@.str.4 = [3 x i8] c"-v\00"
@.str.5 = [3 x i8] c"-h\00"
@.str.6 = [5 x i8] c"/tmp\00"
@.str.7 = [19 x i8] c"Press ^C to exit.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %7
br label %8
8: ; preds = %65, %2
%9 = load i32, i32* %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %68
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %12
store i32 1, i32* %6
br label %21
21: ; preds = %20, %12
%22 = load i8**, i8*** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %21
%30 = call i32 @daemonKill(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %21
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %32
%41 = call i32 (...) @joy_enable_repeat()
br label %42
42: ; preds = %40, %32
%43 = load i8**, i8*** %5
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @strcmp(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %42
%51 = call i32 (...) @showVersion()
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %42
%54 = load i8**, i8*** %5
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = call i32 @strcmp(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%60 = icmp ne i32 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %53
%62 = call i32 (...) @showHelp()
%63 = call i32 @exit(i32 0)
unreachable
64: ; preds = %53
br label %65
65: ; preds = %64
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %8
68: ; preds = %8
%69 = load i32, i32* %6
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 @daemonize(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %73
73: ; preds = %71, %68
%74 = call i32 (...) @init_iic()
%75 = call i32 (...) @init_config()
%76 = call i64 (...) @init_uinput()
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %93
78: ; preds = %73
%79 = call i32 @sleep(i32 1)
%80 = call i64 (...) @joy_RPi_init()
%81 = icmp sge i64 %80, 0
br i1 %81, label %82, label %91
82: ; preds = %78
%83 = load i32, i32* %6
%84 = icmp ne i32 %83, 0
br i1 %84, label %87, label %85
85: ; preds = %82
%86 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
br label %88
88: ; preds = %88, %87
%89 = call i32 (...) @joy_RPi_poll()
%90 = call i32 @usleep(i32 4000)
br label %88
91: ; preds = %78
%92 = call i32 (...) @close_uinput()
br label %93
93: ; preds = %91, %73
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-d\00"
@.str.1 = [3 x i8] c"-k\00"
@.str.2 = [16 x i8] c"/tmp/pikeyd.pid\00"
@.str.3 = [3 x i8] c"-r\00"
@.str.4 = [3 x i8] c"-v\00"
@.str.5 = [3 x i8] c"-h\00"
@.str.6 = [5 x i8] c"/tmp\00"
@str = [18 x i8] c"Press ^C to exit.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %45
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %8
6: ; preds = %34
%7 = icmp eq i64 %37, %5
br i1 %7, label %41, label %8
8: ; preds = %4, %6
%9 = phi i64 [ 1, %4 ], [ %37, %6 ]
%10 = phi i32 [ 0, %4 ], [ %15, %6 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %9
%12 = load i8*, i8** %11
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i32 1, i32 %10
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %8
%19 = tail call i32 @daemonKill(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %8
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call i32 (...) @joy_enable_repeat()
%26 = load i8*, i8** %11
br label %27
27: ; preds = %24, %21
%28 = phi i8* [ %26, %24 ], [ %12, %21 ]
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = tail call i32 (...) @showVersion()
%33 = tail call i32 @exit(i32 0)
unreachable
34: ; preds = %27
%35 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i32 %35, 0
%37 = add nuw nsw i64 %9, 1
br i1 %36, label %38, label %6
38: ; preds = %34
%39 = tail call i32 (...) @showHelp()
%40 = tail call i32 @exit(i32 0)
unreachable
41: ; preds = %6
%42 = icmp eq i32 %15, 0
br i1 %42, label %45, label %43
43: ; preds = %41
%44 = tail call i32 @daemonize(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %2, %43, %41
%46 = phi i1 [ false, %43 ], [ true, %41 ], [ true, %2 ]
%47 = tail call i32 (...) @init_iic()
%48 = tail call i32 (...) @init_config()
%49 = tail call i64 (...) @init_uinput()
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %64
51: ; preds = %45
%52 = tail call i32 @sleep(i32 1)
%53 = tail call i64 (...) @joy_RPi_init()
%54 = icmp sgt i64 %53, -1
br i1 %54, label %55, label %62
55: ; preds = %51
br i1 %46, label %56, label %58
56: ; preds = %55
%57 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %58
58: ; preds = %56, %55
br label %59
59: ; preds = %58, %59
%60 = tail call i32 (...) @joy_RPi_poll()
%61 = tail call i32 @usleep(i32 4000)
br label %59
62: ; preds = %51
%63 = tail call i32 (...) @close_uinput()
br label %64
64: ; preds = %62, %45
ret i32 0
}