#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 */
char *getenv(char *);
int strlen(char *);
char *_get_path(void) {
  static char *_path = NULL;
  _path = getenv("BASIC_PATH");
  if (_path == NULL) {
    _path = ".";
  }
  if (_path[strlen(_path) - 1] == '/') {
    _path[strlen(_path) - 1] = '\0';
  }
  return _path;
}


x86 assembly (clang, -O0):
<_get_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2efd(%rip)
cmpq   $0x0,0x2ef5(%rip)
jne    1157 <_get_path+0x37>
lea    0xebb(%rip),%rax
mov    %rax,0x2ee1(%rip)
mov    0x2eda(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0x2ecf(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11ae <_get_path+0x8e>
mov    0x2eaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e9f(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2e83(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_path>:
push   %rbx
lea    0xed8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xed4(%rip),%rbx
cmovne %rax,%rbx
mov    %rbx,0x2ef6(%rip)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1169 <_get_path+0x49>
mov    0x2ede(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    0x2ec8(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@_get_path._path = internal global i8* null
@.str = [11 x i8] c"BASIC_PATH\00"
@.str.1 = [2 x i8] c".\00"
define i8* @_get_path() {
%1 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %1, i8** @_get_path._path
%2 = load i8*, i8** @_get_path._path
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %5
4: ; preds = %0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** @_get_path._path
br label %5
5: ; preds = %4, %0
%6 = load i8*, i8** @_get_path._path
%7 = load i8*, i8** @_get_path._path
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 47
br i1 %14, label %15, label %22
15: ; preds = %5
%16 = load i8*, i8** @_get_path._path
%17 = load i8*, i8** @_get_path._path
%18 = call i32 @strlen(i8* %17)
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %16, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %15, %5
%23 = load i8*, i8** @_get_path._path
ret i8* %23
}

LLVM IR (-O2):
@_get_path._path = internal unnamed_addr global i8* null
@.str = [11 x i8] c"BASIC_PATH\00"
@.str.1 = [2 x i8] c".\00"
define i8* @_get_path() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
%3 = select i1 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %1
store i8* %3, i8** @_get_path._path
%4 = tail call i32 @strlen(i8* %3)
%5 = add nsw i32 %4, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %3, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load i8*, i8** @_get_path._path
%12 = tail call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %10, %0
%17 = load i8*, i8** @_get_path._path
ret i8* %17
}