#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*/ getcwd(char *, size_t);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strlcpy(char *, char const *, size_t);
size_t strlen(char *);
scalar_t__ valid_dev_path(char *);
bool xcselect_find_developer_contents_from_path(const char *p, char *dst,
                                                bool *is_cmd_line,
                                                size_t dst_size) {
  size_t length;
  if (*p != '/') {
    getcwd(dst, dst_size);
    strcat(dst, "/");
    strcat(dst, p);
  } else
    strlcpy(dst, p, dst_size);
  length = strlen(dst);
  if (valid_dev_path(dst))
    return true;
  dst[length++] = '/';
  dst[length] = 0;
  strcat(dst, "Library/Developer/CommandLineTools");
  if (valid_dev_path(dst)) {
    *is_cmd_line = true;
    return true;
  }
  dst[length] = 0;
  strcat(dst, "CommandLineTools");
  if (valid_dev_path(dst)) {
    *is_cmd_line = true;
    return true;
  }
  dst[length] = 0;
  strcat(dst, "Contents/Developer");
  if (valid_dev_path(dst))
    return true;
  return false;
}


x86 assembly (clang, -O0):
<xcselect_find_developer_contents_from_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11a7 <xcselect_find_developer_contents_from_path+0x57>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <getcwd@plt>
mov    -0x18(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
jmp    11b8 <xcselect_find_developer_contents_from_path+0x68>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <strlcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <valid_dev_path@plt>
cmp    $0x0,%rax
je     11e4 <xcselect_find_developer_contents_from_path+0x94>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <xcselect_find_developer_contents_from_path+0x177>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
movb   $0x2f,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1050 <valid_dev_path@plt>
cmp    $0x0,%rax
je     1240 <xcselect_find_developer_contents_from_path+0xf0>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12c7 <xcselect_find_developer_contents_from_path+0x177>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xdbd(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1050 <valid_dev_path@plt>
cmp    $0x0,%rax
je     1285 <xcselect_find_developer_contents_from_path+0x135>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12c7 <xcselect_find_developer_contents_from_path+0x177>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1050 <valid_dev_path@plt>
cmp    $0x0,%rax
je     12c0 <xcselect_find_developer_contents_from_path+0x170>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <xcselect_find_developer_contents_from_path+0x177>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcselect_find_developer_contents_from_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
cmpb   $0x2f,(%rdi)
jne    1175 <xcselect_find_developer_contents_from_path+0x25>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %rcx,%rdx
call   1060 <strlcpy@plt>
jmp    119a <xcselect_find_developer_contents_from_path+0x4a>
mov    %rbx,%rdi
mov    %rcx,%rsi
call   1040 <getcwd@plt>
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <valid_dev_path@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1203 <xcselect_find_developer_contents_from_path+0xb3>
movw   $0x2f,(%rbx,%r15,1)
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1050 <valid_dev_path@plt>
test   %rax,%rax
jne    11fc <xcselect_find_developer_contents_from_path+0xac>
movb   $0x0,0x1(%rbx,%r15,1)
lea    0xe2d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1050 <valid_dev_path@plt>
test   %rax,%rax
je     1210 <xcselect_find_developer_contents_from_path+0xc0>
movl   $0x1,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,0x1(%rbx,%r15,1)
lea    0xe08(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1050 <valid_dev_path@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    1203 <xcselect_find_developer_contents_from_path+0xb3>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [35 x i8] c"Library/Developer/CommandLineTools\00"
@.str.2 = [17 x i8] c"CommandLineTools\00"
@.str.3 = [19 x i8] c"Contents/Developer\00"
define i32 @xcselect_find_developer_contents_from_path(i8* %0, i8* %1, i32* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i64 %3, i64* %9
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 47
br i1 %14, label %15, label %24
15: ; preds = %4
%16 = load i8*, i8** %7
%17 = load i64, i64* %9
%18 = call i32 @getcwd(i8* %16, i64 %17)
%19 = load i8*, i8** %7
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load i8*, i8** %7
%22 = load i8*, i8** %6
%23 = call i32 @strcat(i8* %21, i8* %22)
br label %29
24: ; preds = %4
%25 = load i8*, i8** %7
%26 = load i8*, i8** %6
%27 = load i64, i64* %9
%28 = call i32 @strlcpy(i8* %25, i8* %26, i64 %27)
br label %29
29: ; preds = %24, %15
%30 = load i8*, i8** %7
%31 = call i64 @strlen(i8* %30)
store i64 %31, i64* %10
%32 = load i8*, i8** %7
%33 = call i64 @valid_dev_path(i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 1, i32* %5
br label %73
36: ; preds = %29
%37 = load i8*, i8** %7
%38 = load i64, i64* %10
%39 = add i64 %38, 1
store i64 %39, i64* %10
%40 = getelementptr inbounds i8, i8* %37, i64 %38
store i8 47, i8* %40
%41 = load i8*, i8** %7
%42 = load i64, i64* %10
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %7
%45 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%46 = load i8*, i8** %7
%47 = call i64 @valid_dev_path(i8* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %36
%50 = load i32*, i32** %8
store i32 1, i32* %50
store i32 1, i32* %5
br label %73
51: ; preds = %36
%52 = load i8*, i8** %7
%53 = load i64, i64* %10
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8 0, i8* %54
%55 = load i8*, i8** %7
%56 = call i32 @strcat(i8* %55, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%57 = load i8*, i8** %7
%58 = call i64 @valid_dev_path(i8* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %51
%61 = load i32*, i32** %8
store i32 1, i32* %61
store i32 1, i32* %5
br label %73
62: ; preds = %51
%63 = load i8*, i8** %7
%64 = load i64, i64* %10
%65 = getelementptr inbounds i8, i8* %63, i64 %64
store i8 0, i8* %65
%66 = load i8*, i8** %7
%67 = call i32 @strcat(i8* %66, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%68 = load i8*, i8** %7
%69 = call i64 @valid_dev_path(i8* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %62
store i32 1, i32* %5
br label %73
72: ; preds = %62
store i32 0, i32* %5
br label %73
73: ; preds = %72, %71, %60, %49, %35
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [35 x i8] c"Library/Developer/CommandLineTools\00"
@.str.2 = [17 x i8] c"CommandLineTools\00"
@.str.3 = [19 x i8] c"Contents/Developer\00"
define i32 @xcselect_find_developer_contents_from_path(i8* %0, i8* %1, i32* nocapture writeonly %2, i64 %3) {
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 47
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i32 @getcwd(i8* %1, i64 %3)
%9 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @strcat(i8* %1, i8* %0)
br label %13
11: ; preds = %4
%12 = tail call i32 @strlcpy(i8* %1, i8* %0, i64 %3)
br label %13
13: ; preds = %11, %7
%14 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%15 = tail call i64 @valid_dev_path(i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = add i64 %14, 1
%19 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 47, i8* %19
%20 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %20
%21 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i64 @valid_dev_path(i8* %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %17
store i32 1, i32* %2
br label %35
25: ; preds = %17
store i8 0, i8* %20
%26 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i64 @valid_dev_path(i8* %1)
%28 = icmp eq i64 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %25
store i32 1, i32* %2
br label %35
30: ; preds = %25
store i8 0, i8* %20
%31 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%32 = tail call i64 @valid_dev_path(i8* %1)
%33 = icmp ne i64 %32, 0
%34 = zext i1 %33 to i32
br label %35
35: ; preds = %30, %13, %29, %24
%36 = phi i32 [ 1, %24 ], [ 1, %29 ], [ 1, %13 ], [ %34, %30 ]
ret i32 %36
}