#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*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getuid();
char *scan_devices();
int /*<<< orphan*/ stderr;
char *strdup(char *);
int /*<<< orphan*/ usage();
char *parse_args(int argc, char **argv) {
  char *filename;
  if (argc < 2) {
    fprintf(stderr, "No device specified, trying to scan all of %s/%s*\n",
            "/dev/input", "event");
    if (getuid() != 0)
      fprintf(stderr, "Not running as root, no devices may be available.\n");
    filename = scan_devices();
    if (!filename) {
      usage();
      return NULL;
    }
  } else
    filename = strdup(argv[argc - 1]);
  return filename;
}


x86 assembly (clang, -O0):
<parse_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    11e5 <parse_args+0x95>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
lea    0xeb3(%rip),%rdx
lea    0xeb7(%rip),%rcx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
cmp    $0x0,%rax
je     11b6 <parse_args+0x66>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1060 <scan_devices@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e0 <parse_args+0x90>
mov    $0x0,%al
call   1050 <usage@plt>
movq   $0x0,-0x8(%rbp)
jmp    1207 <parse_args+0xb7>
jmp    11ff <parse_args+0xaf>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_args>:
push   %rbx
cmp    $0x1,%edi
jg     11b4 <parse_args+0x64>
mov    0x2e83(%rip),%rbx
mov    (%rbx),%edi
lea    0xe9a(%rip),%rsi
lea    0xec6(%rip),%rdx
lea    0xeca(%rip),%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <getuid@plt>
test   %rax,%rax
je     1197 <parse_args+0x47>
mov    (%rbx),%edi
lea    0xeb4(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1060 <scan_devices@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11af <parse_args+0x5f>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <usage@plt>
mov    %rbx,%rax
pop    %rbx
ret
add    $0xffffffff,%edi
mov    (%rsi,%rdi,8),%rdi
pop    %rbx
jmp    1070 <strdup@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"No device specified, trying to scan all of %s/%s*\0A\00"
@.str.1 = [11 x i8] c"/dev/input\00"
@.str.2 = [6 x i8] c"event\00"
@.str.3 = [51 x i8] c"Not running as root, no devices may be available.\0A\00"
define i8* @parse_args(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %24
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%12 = call i64 (...) @getuid()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %14, %9
%18 = call i8* (...) @scan_devices()
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 (...) @usage()
store i8* null, i8** %3
br label %34
23: ; preds = %17
br label %32
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %25, i64 %28
%30 = load i8*, i8** %29
%31 = call i8* @strdup(i8* %30)
store i8* %31, i8** %6
br label %32
32: ; preds = %24, %23
%33 = load i8*, i8** %6
store i8* %33, i8** %3
br label %34
34: ; preds = %32, %21
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"No device specified, trying to scan all of %s/%s*\0A\00"
@.str.1 = [11 x i8] c"/dev/input\00"
@.str.2 = [6 x i8] c"event\00"
@.str.3 = [51 x i8] c"Not running as root, no devices may be available.\0A\00"
define i8* @parse_args(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i64 (...) @getuid()
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %9, %4
%13 = tail call i8* (...) @scan_devices()
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = tail call i32 (...) @usage()
br label %23
17: ; preds = %2
%18 = add nsw i32 %0, -1
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = tail call i8* @strdup(i8* %21)
br label %23
23: ; preds = %17, %12, %15
%24 = phi i8* [ null, %15 ], [ %13, %12 ], [ %22, %17 ]
ret i8* %24
}