#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 EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
char getopt(int, char **, char *);
int /*<<< orphan*/ launcher_cmd(int, int);
int /*<<< orphan*/ launcher_usage(char *);
int open(char *, int /*<<< orphan*/);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
unsigned int strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ usleep(unsigned int);
int main(int argc, char **argv) {
  char c;
  int fd;
  int cmd = 0x20;
  char *dev = "/dev/launcher0";
  unsigned int duration = 500;
  if (argc < 2) {
    launcher_usage(argv[0]);
  }
  while ((c = getopt(argc, argv, "mlrudfsht:")) != -1) {
    switch (c) {
    case 'm':
      dev = optarg;
      break;
    case 'l':
      cmd = 0x04;
      break;
    case 'r':
      cmd = 0x08;
      break;
    case 'u':
      cmd = 0x02;
      break;
    case 'd':
      cmd = 0x01;
      break;
    case 'f':
      cmd = 0x10;
      break;
    case 's':
      cmd = 0x20;
      break;
    case 't':
      duration = strtol(optarg, NULL, 10);
      fprintf(stdout, "Duration set to %d\n", duration);
      break;
    default:
      launcher_usage(argv[0]);
    }
  }
  fd = open(dev, O_RDWR);
  if (fd == -1) {
    perror("Couldn't open file: %m");
    exit(1);
  }
  launcher_cmd(fd, cmd);
  usleep(duration * 1000);
  launcher_cmd(fd, 0x20);
  close(fd);
  return EXIT_SUCCESS;
}


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   $0x20,-0x1c(%rbp)
lea    0xe84(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1f4,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e5 <main+0x45>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <launcher_usage@plt>
jmp    11ea <main+0x4a>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5f(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     12da <main+0x13a>
movsbl -0x11(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x11,%eax
ja     12c9 <main+0x129>
mov    -0x38(%rbp),%rax
lea    0xdd3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dbb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12d5 <main+0x135>
movl   $0x4,-0x1c(%rbp)
jmp    12d5 <main+0x135>
movl   $0x8,-0x1c(%rbp)
jmp    12d5 <main+0x135>
movl   $0x2,-0x1c(%rbp)
jmp    12d5 <main+0x135>
movl   $0x1,-0x1c(%rbp)
jmp    12d5 <main+0x135>
movl   $0x10,-0x1c(%rbp)
jmp    12d5 <main+0x135>
movl   $0x20,-0x1c(%rbp)
jmp    12d5 <main+0x135>
mov    0x2d60(%rip),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xda3(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12d5 <main+0x135>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <launcher_usage@plt>
jmp    11ea <main+0x4a>
mov    -0x28(%rbp),%rdi
mov    0x2cfb(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    130f <main+0x16f>
lea    0xd76(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10b0 <launcher_cmd@plt>
imul   $0x3e8,-0x2c(%rbp),%edi
call   10c0 <usleep@plt>
mov    -0x18(%rbp),%edi
mov    $0x20,%esi
call   10b0 <launcher_cmd@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x1,%edi
jg     11c0 <main+0x20>
mov    (%rbx),%rdi
call   1060 <launcher_usage@plt>
lea    0xe90(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <getopt@plt>
cmp    $0xff,%al
je     12b2 <main+0x112>
mov    $0x20,%r13d
lea    0xe62(%rip),%rcx
mov    %rcx,0x10(%rsp)
movl   $0x1f4,0xc(%rsp)
lea    0xe5d(%rip),%r12
lea    0xdff(%rip),%r15
jmp    1226 <main+0x86>
mov    (%rbx),%rdi
call   1060 <launcher_usage@plt>
mov    %r13d,%r14d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1090 <getopt@plt>
mov    %r14d,%r13d
cmp    $0xff,%al
je     12cc <main+0x12c>
movsbl %al,%eax
add    $0xffffff9c,%eax
cmp    $0x11,%eax
ja     1203 <main+0x63>
mov    $0x4,%r14d
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    $0x1,%r14d
jmp    120e <main+0x6e>
mov    $0x10,%r14d
jmp    120e <main+0x6e>
mov    0x2da1(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    120b <main+0x6b>
mov    $0x8,%r14d
jmp    120e <main+0x6e>
mov    $0x20,%r14d
jmp    120e <main+0x6e>
mov    0x2d80(%rip),%rax
mov    (%rax),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    0x2d42(%rip),%rcx
mov    (%rcx),%edi
lea    0xdcb(%rip),%rsi
mov    %eax,0xc(%rsp)
mov    %eax,%edx
call   1040 <fprintf@plt>
jmp    120b <main+0x6b>
mov    $0x2,%r14d
jmp    120e <main+0x6e>
movl   $0x1f4,0xc(%rsp)
lea    0xd87(%rip),%rax
mov    %rax,0x10(%rsp)
mov    $0x20,%r14d
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
mov    0x10(%rsp),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1328 <main+0x188>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14d,%esi
call   10b0 <launcher_cmd@plt>
imul   $0x3e8,0xc(%rsp),%edi
call   10c0 <usleep@plt>
mov    %ebx,%edi
mov    $0x20,%esi
call   10b0 <launcher_cmd@plt>
mov    %ebx,%edi
call   1030 <close@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd47(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/launcher0\00"
@.str.1 = [11 x i8] c"mlrudfsht:\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.2 = [20 x i8] c"Duration set to %d\0A\00"
@O_RDWR = global i32 0
@.str.3 = [23 x i8] c"Couldn't open file: %m\00"
@EXIT_SUCCESS = global i32 0
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 i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 32, i32* %8
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %9
store i32 500, i32* %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @launcher_usage(i8* %16)
br label %18
18: ; preds = %13, %2
br label %19
19: ; preds = %47, %18
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call signext i8 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i8 %22, i8* %6
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %48
25: ; preds = %19
%26 = load i8, i8* %6
%27 = sext i8 %26 to i32
switch i32 %27, label %42 [
i32 109, label %28
i32 108, label %30
i32 114, label %31
i32 117, label %32
i32 100, label %33
i32 102, label %34
i32 115, label %35
i32 116, label %36
]
28: ; preds = %25
%29 = load i8*, i8** @optarg
store i8* %29, i8** %9
br label %47
30: ; preds = %25
store i32 4, i32* %8
br label %47
31: ; preds = %25
store i32 8, i32* %8
br label %47
32: ; preds = %25
store i32 2, i32* %8
br label %47
33: ; preds = %25
store i32 1, i32* %8
br label %47
34: ; preds = %25
store i32 16, i32* %8
br label %47
35: ; preds = %25
store i32 32, i32* %8
br label %47
36: ; preds = %25
%37 = load i8*, i8** @optarg
%38 = call i32 @strtol(i8* %37, i32* null, i32 10)
store i32 %38, i32* %10
%39 = load i32, i32* @stdout
%40 = load i32, i32* %10
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %47
42: ; preds = %25
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = call i32 @launcher_usage(i8* %45)
br label %47
47: ; preds = %42, %36, %35, %34, %33, %32, %31, %30, %28
br label %19
48: ; preds = %19
%49 = load i8*, i8** %9
%50 = load i32, i32* @O_RDWR
%51 = call i32 @open(i8* %49, i32 %50)
store i32 %51, i32* %7
%52 = load i32, i32* %7
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = call i32 @launcher_cmd(i32 %58, i32 %59)
%61 = load i32, i32* %10
%62 = mul i32 %61, 1000
%63 = call i32 @usleep(i32 %62)
%64 = load i32, i32* %7
%65 = call i32 @launcher_cmd(i32 %64, i32 32)
%66 = load i32, i32* %7
%67 = call i32 @close(i32 %66)
%68 = load i32, i32* @EXIT_SUCCESS
ret i32 %68
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/launcher0\00"
@.str.1 = [11 x i8] c"mlrudfsht:\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.2 = [20 x i8] c"Duration set to %d\0A\00"
@O_RDWR = global i32 0
@.str.3 = [23 x i8] c"Couldn't open file: %m\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @launcher_usage(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8 %8, -1
br i1 %9, label %37, label %10
10: ; preds = %7, %31
%11 = phi i8 [ %35, %31 ], [ %8, %7 ]
%12 = phi i32 [ %34, %31 ], [ 500, %7 ]
%13 = phi i8* [ %33, %31 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %7 ]
%14 = phi i32 [ %32, %31 ], [ 32, %7 ]
%15 = sext i8 %11 to i32
switch i32 %15, label %28 [
i32 109, label %16
i32 108, label %31
i32 114, label %18
i32 117, label %19
i32 100, label %20
i32 102, label %21
i32 115, label %22
i32 116, label %23
]
16: ; preds = %10
%17 = load i8*, i8** @optarg
br label %31
18: ; preds = %10
br label %31
19: ; preds = %10
br label %31
20: ; preds = %10
br label %31
21: ; preds = %10
br label %31
22: ; preds = %10
br label %31
23: ; preds = %10
%24 = load i8*, i8** @optarg
%25 = tail call i32 @strtol(i8* nocapture %24, i32* null, i32 10)
%26 = load i32, i32* @stdout
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %31
28: ; preds = %10
%29 = load i8*, i8** %1
%30 = tail call i32 @launcher_usage(i8* %29)
br label %31
31: ; preds = %10, %28, %23, %22, %21, %20, %19, %18, %16
%32 = phi i32 [ %14, %28 ], [ %14, %23 ], [ 32, %22 ], [ 16, %21 ], [ 1, %20 ], [ 2, %19 ], [ 8, %18 ], [ %14, %16 ], [ 4, %10 ]
%33 = phi i8* [ %13, %28 ], [ %13, %23 ], [ %13, %22 ], [ %13, %21 ], [ %13, %20 ], [ %13, %19 ], [ %13, %18 ], [ %17, %16 ], [ %13, %10 ]
%34 = phi i32 [ %12, %28 ], [ %25, %23 ], [ %12, %22 ], [ %12, %21 ], [ %12, %20 ], [ %12, %19 ], [ %12, %18 ], [ %12, %16 ], [ %12, %10 ]
%35 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i8 %35, -1
br i1 %36, label %37, label %10
37: ; preds = %31, %7
%38 = phi i32 [ 32, %7 ], [ %32, %31 ]
%39 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %7 ], [ %33, %31 ]
%40 = phi i32 [ 500, %7 ], [ %34, %31 ]
%41 = load i32, i32* @O_RDWR
%42 = tail call i32 @open(i8* %39, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %37
%48 = tail call i32 @launcher_cmd(i32 %42, i32 %38)
%49 = mul i32 %40, 1000
%50 = tail call i32 @usleep(i32 %49)
%51 = tail call i32 @launcher_cmd(i32 %42, i32 32)
%52 = tail call i32 @close(i32 %42)
%53 = load i32, i32* @EXIT_SUCCESS
ret i32 %53
}