#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 *, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char *);
bool valid_dev_path(const char *path) {
  char buffer[1024];
  size_t length;
  strcpy(buffer, path);
  strcat(buffer, "/");
  length = strlen(buffer);
  strcat(buffer, "usr/lib/libxcrun.dylib");
  if (access(buffer, F_OK) == 0)
    return true;
  buffer[length] = 0;
  strcat(buffer, "usr/bin/xcrun");
  if (access(buffer, F_OK) == 0)
    return true;
  return false;
}


x86 assembly (clang, -O0):
<valid_dev_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    11c3 <valid_dev_path+0x83>
movl   $0x1,-0x4(%rbp)
jmp    1217 <valid_dev_path+0xd7>
mov    -0x418(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x410(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    1210 <valid_dev_path+0xd0>
movl   $0x1,-0x4(%rbp)
jmp    1217 <valid_dev_path+0xd7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<valid_dev_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r14
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    0x2e4e(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
test   %rax,%rax
je     11c9 <valid_dev_path+0x89>
movb   $0x0,(%rsp,%r14,1)
lea    0xe73(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    11ce <valid_dev_path+0x8e>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [23 x i8] c"usr/lib/libxcrun.dylib\00"
@F_OK = global i32 0
@.str.2 = [14 x i8] c"usr/bin/xcrun\00"
define i32 @valid_dev_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i64
store i8* %0, i8** %3
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @strcpy(i8* %6, i8* %7)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %5
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = load i32, i32* @F_OK
%17 = call i64 @access(i8* %15, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %1
store i32 1, i32* %2
br label %31
20: ; preds = %1
%21 = load i64, i64* %5
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%26 = load i32, i32* @F_OK
%27 = call i64 @access(i8* %25, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %20
store i32 1, i32* %2
br label %31
30: ; preds = %20
store i32 0, i32* %2
br label %31
31: ; preds = %30, %29, %19
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [23 x i8] c"usr/lib/libxcrun.dylib\00"
@F_OK = global i32 0
@.str.2 = [14 x i8] c"usr/bin/xcrun\00"
define i32 @valid_dev_path(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
%5 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @strlen(i8* %3)
%7 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @F_OK
%9 = call i64 @access(i8* %3, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %6
store i8 0, i8* %12
%13 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @F_OK
%15 = call i64 @access(i8* %3, i32 %14)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %11, %1
%19 = phi i32 [ 1, %1 ], [ %17, %11 ]
ret i32 %19
}