#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*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *pref_find_yakrc() {
  static char buf[256];
  strcpy(buf, "./yakrc");
  if (access(buf, R_OK) == 0)
    return buf;
  strcpy(buf, getenv("HOME"));
  strcat(buf, "/.yak/yakrc");
  if (access(buf, R_OK) == 0)
    return buf;
  return NULL;
}


x86 assembly (clang, -O0):
<pref_find_yakrc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0x2f01(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0x2ee5(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    118a <pref_find_yakrc+0x4a>
lea    0x2ecf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ef <pref_find_yakrc+0xaf>
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0x2eb0(%rip),%rdi
call   1040 <strcpy@plt>
lea    0x2ea4(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <strcat@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
lea    0x2e88(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    11e7 <pref_find_yakrc+0xa7>
lea    0x2e72(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ef <pref_find_yakrc+0xaf>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pref_find_yakrc>:
push   %r15
push   %r14
push   %rbx
lea    0x2f04(%rip),%rbx
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    0x2e7e(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
test   %rax,%rax
je     11b3 <pref_find_yakrc+0x73>
lea    0xe8f(%rip),%rdi
call   1030 <getenv@plt>
lea    0x2ecb(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0xe76(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1050 <access@plt>
xor    %ebx,%ebx
test   %rax,%rax
cmove  %r14,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@pref_find_yakrc.buf = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"./yakrc\00"
@R_OK = global i32 0
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [12 x i8] c"/.yak/yakrc\00"
define i8* @pref_find_yakrc() {
%1 = alloca i8*
%2 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @R_OK
%4 = call i64 @access(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i8** %1
br label %16
7: ; preds = %0
%8 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i8* %8)
%10 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @R_OK
%12 = call i64 @access(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %7
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i8** %1
br label %16
15: ; preds = %7
store i8* null, i8** %1
br label %16
16: ; preds = %15, %14, %6
%17 = load i8*, i8** %1
ret i8* %17
}

LLVM IR (-O2):
@pref_find_yakrc.buf = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"./yakrc\00"
@R_OK = global i32 0
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [12 x i8] c"/.yak/yakrc\00"
define i8* @pref_find_yakrc() {
%1 = tail call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @R_OK
%3 = tail call i64 @access(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i8* %6)
%8 = tail call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @R_OK
%10 = tail call i64 @access(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i32 %9)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), i8* null
br label %13
13: ; preds = %5, %0
%14 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @pref_find_yakrc.buf, i64 0, i64 0), %0 ], [ %12, %5 ]
ret i8* %14
}