#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int stat(char *, struct stat *);
char *xconfigGetDefaultProjectRoot(void) {
  char *paths[] = {"/usr/X11R6", "/usr/X11", NULL};
  struct stat stat_buf;
  int i;
  for (i = 0; paths[i]; i++) {
    if (stat(paths[i], &stat_buf) == -1) {
      continue;
    }
    if (S_ISDIR(stat_buf.st_mode)) {
      return paths[i];
    }
  }
  return paths[0];
}


x86 assembly (clang, -O0):
<xconfigGetDefaultProjectRoot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2cd1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cce(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2ccb(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmpq   $0x0,-0x20(%rbp,%rax,8)
je     11b7 <xconfigGetDefaultProjectRoot+0x97>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    1180 <xconfigGetDefaultProjectRoot+0x60>
jmp    11a9 <xconfigGetDefaultProjectRoot+0x89>
mov    -0x28(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11a4 <xconfigGetDefaultProjectRoot+0x84>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rax
mov    %rax,-0x8(%rbp)
jmp    11bf <xconfigGetDefaultProjectRoot+0x9f>
jmp    11a9 <xconfigGetDefaultProjectRoot+0x89>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1150 <xconfigGetDefaultProjectRoot+0x30>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xconfigGetDefaultProjectRoot>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%r14
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     1148 <xconfigGetDefaultProjectRoot+0x28>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
jne    116c <xconfigGetDefaultProjectRoot+0x4c>
lea    0xebc(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     116c <xconfigGetDefaultProjectRoot+0x4c>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
jne    116f <xconfigGetDefaultProjectRoot+0x4f>
mov    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [11 x i8] c"/usr/X11R6\00"
@.str.1 = [9 x i8] c"/usr/X11\00"
@__const.xconfigGetDefaultProjectRoot.paths = [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i8* null]
define i8* @xconfigGetDefaultProjectRoot() {
%1 = alloca i8*
%2 = alloca [3 x i8*]
%3 = alloca %struct.stat
%4 = alloca i32
%5 = bitcast [3 x i8*]* %2 to i8*
store i32 0, i32* %4
br label %6
6: ; preds = %31, %0
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 %8
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %34
12: ; preds = %6
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = call i32 @stat(i8* %16, %struct.stat* %3)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %12
br label %31
20: ; preds = %12
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @S_ISDIR(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 %27
%29 = load i8*, i8** %28
store i8* %29, i8** %1
br label %37
30: ; preds = %20
br label %31
31: ; preds = %30, %19
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %6
34: ; preds = %6
%35 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%36 = load i8*, i8** %35
store i8* %36, i8** %1
br label %37
37: ; preds = %34, %25
%38 = load i8*, i8** %1
ret i8* %38
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [11 x i8] c"/usr/X11R6\00"
@.str.1 = [9 x i8] c"/usr/X11\00"
define i8* @xconfigGetDefaultProjectRoot() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%4 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = load i32, i32* %3
%8 = tail call i64 @S_ISDIR(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %6, %0
%11 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* %3
%15 = tail call i64 @S_ISDIR(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13, %10
br label %18
18: ; preds = %17, %13, %6
%19 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %17 ]
ret i8* %19
}