#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 /*<<< orphan*/ pathToLong();
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
bool getEnvPath(char path[]) {
  char temp[1024] = {'\0'};
  int len;
  char *envv;
  if ((envv = getenv("ELCALC")) != NULL) {
    strcat(temp, envv);
    len = strlen(temp);
    if (temp[len - 1] == '/') {
      if (strlen("items.lst") + len >= 1024) {
        pathToLong();
      }
      strcat(temp, "items.lst");
    }
  } else {
    return false;
  }
  strcpy(path, temp);
  return true;
}


x86 assembly (clang, -O0):
<getEnvPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x420(%rbp)
cmp    $0x0,%rax
je     121c <getEnvPath+0xbc>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x414(%rbp)
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    1217 <getEnvPath+0xb7>
lea    0xe20(%rip),%rdi
call   1060 <strlen@plt>
add    -0x414(%rbp),%eax
cmp    $0x400,%eax
jl     1204 <getEnvPath+0xa4>
mov    $0x0,%al
call   1050 <pathToLong@plt>
lea    -0x410(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1080 <strcat@plt>
jmp    1228 <getEnvPath+0xc8>
movl   $0x0,-0x4(%rbp)
jmp    123f <getEnvPath+0xdf>
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getEnvPath>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
xor    %ebp,%ebp
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ec <getEnvPath+0x8c>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    11dc <getEnvPath+0x7c>
lea    0xe4f(%rip),%rdi
call   1060 <strlen@plt>
add    %ebp,%eax
cmp    $0x400,%eax
jl     11cd <getEnvPath+0x6d>
xor    %eax,%eax
call   1050 <pathToLong@plt>
lea    0xe33(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strcat@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"ELCALC\00"
@.str.1 = [10 x i8] c"items.lst\00"
define i32 @getEnvPath(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = bitcast [1024 x i8]* %4 to i8*
%8 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %34
10: ; preds = %1
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = load i8*, i8** %6
%13 = call i32 @strcat(i8* %11, i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %33
23: ; preds = %10
%24 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* %5
%26 = add nsw i32 %24, %25
%27 = icmp sge i32 %26, 1024
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 (...) @pathToLong()
br label %30
30: ; preds = %28, %23
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %30, %10
br label %35
34: ; preds = %1
store i32 0, i32* %2
br label %39
35: ; preds = %33
%36 = load i8*, i8** %3
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%38 = call i32 @strcpy(i8* %36, i8* %37)
store i32 1, i32* %2
br label %39
39: ; preds = %35, %34
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [7 x i8] c"ELCALC\00"
@.str.1 = [10 x i8] c"items.lst\00"
define i32 @getEnvPath(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %24, label %6
6: ; preds = %1
%7 = call i32 @strcat(i8* %3, i8* %4)
%8 = call i32 @strlen(i8* %3)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %14, label %22
14: ; preds = %6
%15 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%16 = add nsw i32 %15, %8
%17 = icmp sgt i32 %16, 1023
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 (...) @pathToLong()
br label %20
20: ; preds = %18, %14
%21 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %6, %20
%23 = call i32 @strcpy(i8* %0, i8* %3)
br label %24
24: ; preds = %1, %22
%25 = phi i32 [ 1, %22 ], [ 0, %1 ]
ret i32 %25
}