#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*/ F_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
char *strdup(char const *);
char *get_device_path(const char *hint) {
  char temp[256];
  if (access(hint, F_OK) == 0) {
    goto cleanup;
  }
  snprintf(temp, sizeof temp, "/dev/input/%s", hint);
  if (access(temp, F_OK) == 0) {
    hint = temp;
    goto cleanup;
  }
  snprintf(temp, sizeof temp, "/dev/input/event%s", hint);
  if (access(temp, F_OK) == 0) {
    hint = temp;
    goto cleanup;
  }
  do {
  } while (0);
  hint = 0;
cleanup:
  return hint ? strdup(hint) : 0;
}


x86 assembly (clang, -O0):
<get_device_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    1160 <get_device_path+0x30>
jmp    1208 <get_device_path+0xd8>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xe89(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    11ab <get_device_path+0x7b>
lea    -0x110(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <get_device_path+0xd8>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xe4c(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    11f6 <get_device_path+0xc6>
lea    -0x110(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <get_device_path+0xd8>
jmp    11fb <get_device_path+0xcb>
jmp    1200 <get_device_path+0xd0>
movq   $0x0,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1228 <get_device_path+0xf8>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x118(%rbp)
jmp    1236 <get_device_path+0x106>
xor    %eax,%eax
mov    %rax,-0x118(%rbp)
jmp    1236 <get_device_path+0x106>
mov    -0x118(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_device_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r14
mov    0x2e92(%rip),%r15
mov    (%r15),%esi
call   1040 <access@plt>
test   %rax,%rax
je     11ab <get_device_path+0x7b>
mov    %rsp,%rbx
lea    0xea3(%rip),%rdx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rcx
call   1030 <snprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %rax,%rax
je     11b3 <get_device_path+0x83>
mov    %rsp,%rbx
lea    0xe87(%rip),%rdx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rcx
call   1030 <snprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %rax,%rax
je     11b3 <get_device_path+0x83>
xor    %eax,%eax
jmp    11bb <get_device_path+0x8b>
mov    %r14,%rbx
test   %r14,%r14
je     11a7 <get_device_path+0x77>
mov    %rbx,%rdi
call   1050 <strdup@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [14 x i8] c"/dev/input/%s\00"
@.str.1 = [19 x i8] c"/dev/input/event%s\00"
define i8* @get_device_path(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @F_OK
%6 = call i64 @access(i8* %4, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %32
9: ; preds = %1
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* @F_OK
%15 = call i64 @access(i8* %13, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
store i8* %18, i8** %2
br label %32
19: ; preds = %9
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%21 = load i8*, i8** %2
%22 = call i32 @snprintf(i8* %20, i32 256, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%24 = load i32, i32* @F_OK
%25 = call i64 @access(i8* %23, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
store i8* %28, i8** %2
br label %32
29: ; preds = %19
br label %30
30: ; preds = %29
br label %31
31: ; preds = %30
store i8* null, i8** %2
br label %32
32: ; preds = %31, %27, %17, %8
%33 = load i8*, i8** %2
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** %2
%37 = call i8* @strdup(i8* %36)
br label %39
38: ; preds = %32
br label %39
39: ; preds = %38, %35
%40 = phi i8* [ %37, %35 ], [ null, %38 ]
ret i8* %40
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [14 x i8] c"/dev/input/%s\00"
@.str.1 = [19 x i8] c"/dev/input/event%s\00"
define noalias i8* @get_device_path(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @F_OK
%5 = tail call i64 @access(i8* %0, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @F_OK
%10 = call i64 @access(i8* %3, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %7
%13 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%14 = load i32, i32* @F_OK
%15 = call i64 @access(i8* %3, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %22
17: ; preds = %1
%18 = icmp eq i8* %0, null
br i1 %18, label %22, label %19
19: ; preds = %12, %7, %17
%20 = phi i8* [ %0, %17 ], [ %3, %7 ], [ %3, %12 ]
%21 = call i8* @strdup(i8* %20)
br label %22
22: ; preds = %12, %17, %19
%23 = phi i8* [ %21, %19 ], [ null, %17 ], [ null, %12 ]
ret i8* %23
}