#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 PATH_MAX;
int /*<<< orphan*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
char *strdup(char *);
char *find_rvm_system(void) {
  char buffer[PATH_MAX];
  char *locations[] = {"/usr/local/rvm/bin/rvm", "/opt/rvm/bin/rvm",
                       "/usr/bin/rvm", NULL};
  int i;
  for (i = 0; locations[i] != NULL; i++) {
    if (access(buffer, X_OK) == 0)
      return strdup(locations[i]);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_rvm_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x2ec1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2c95(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c92(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c8f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c8c(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rax
cmpq   $0x0,-0x40(%rbp,%rax,8)
je     11e4 <find_rvm_system+0xc4>
mov    -0x50(%rbp),%rdi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1030 <access@plt>
cmp    $0x0,%rax
jne    11d1 <find_rvm_system+0xb1>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    11f3 <find_rvm_system+0xd3>
jmp    11d6 <find_rvm_system+0xb6>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1187 <find_rvm_system+0x67>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_rvm_system>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2ec2(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e98(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   1030 <access@plt>
test   %rax,%rax
je     1183 <find_rvm_system+0x63>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1030 <access@plt>
test   %rax,%rax
je     1187 <find_rvm_system+0x67>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1030 <access@plt>
test   %rax,%rax
je     118e <find_rvm_system+0x6e>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
jmp    1193 <find_rvm_system+0x73>
mov    $0x1,%eax
jmp    1193 <find_rvm_system+0x73>
mov    $0x2,%eax
lea    0x2c56(%rip),%rcx
mov    (%rcx,%rax,8),%rdi
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <strdup@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [23 x i8] c"/usr/local/rvm/bin/rvm\00"
@.str.1 = [17 x i8] c"/opt/rvm/bin/rvm\00"
@.str.2 = [13 x i8] c"/usr/bin/rvm\00"
@__const.find_rvm_system.locations = [4 x i8*] [i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* null]
@X_OK = global i32 0
define i8* @find_rvm_system() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca [4 x i8*]
%5 = alloca i32
%6 = alloca i32
%7 = load i32, i32* @PATH_MAX
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %2
%10 = alloca i8, i64 %8
store i64 %8, i64* %3
%11 = bitcast [4 x i8*]* %4 to i8*
store i32 0, i32* %5
br label %12
12: ; preds = %29, %0
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %32
18: ; preds = %12
%19 = load i32, i32* @X_OK
%20 = call i64 @access(i8* %10, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i8* @strdup(i8* %26)
store i8* %27, i8** %1
store i32 1, i32* %6
br label %33
28: ; preds = %18
br label %29
29: ; preds = %28
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %12
32: ; preds = %12
store i8* null, i8** %1
store i32 1, i32* %6
br label %33
33: ; preds = %32, %22
%34 = load i8*, i8** %2
%35 = load i8*, i8** %1
ret i8* %35
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [23 x i8] c"/usr/local/rvm/bin/rvm\00"
@.str.1 = [17 x i8] c"/opt/rvm/bin/rvm\00"
@.str.2 = [13 x i8] c"/usr/bin/rvm\00"
@__const.find_rvm_system.locations = [4 x i8*] [i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* null]
@X_OK = global i32 0
define noalias i8* @find_rvm_system() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = load i32, i32* @X_OK
%5 = call i64 @access(i8* %3, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %16, %12, %0
%8 = phi i64 [ 0, %0 ], [ 1, %12 ], [ 2, %16 ]
%9 = getelementptr inbounds [4 x i8*], [4 x i8*]* @__const.find_rvm_system.locations, i64 0, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i8* @strdup(i8* %10)
br label %20
12: ; preds = %0
%13 = load i32, i32* @X_OK
%14 = call i64 @access(i8* %3, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %7, label %16
16: ; preds = %12
%17 = load i32, i32* @X_OK
%18 = call i64 @access(i8* %3, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %7, label %20
20: ; preds = %16, %7
%21 = phi i8* [ %11, %7 ], [ null, %16 ]
ret i8* %21
}