#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*/ printf(char *);
int setenv(char *, char *, int);
char *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strtok(char *, char *);
void changePath(char *prePipe) {
  char temp[1000], temp2[1000];
  char PATH[1000];
  strcpy(temp, prePipe);
  strtok(temp, "$PATH:");
  int j = strlen(temp) + 5;
  int i;
  for (i = 0; j < (strlen(prePipe) + 1); i++) {
    temp[i] = prePipe[j];
    j++;
  }
  strcpy(temp2, (getenv("PATH")));
  strcpy(PATH, strcat(temp2, temp));
  int error;
  error = setenv("PATH", PATH, 1);
  if (error != 0)
    printf("Invalid path\n");
}


x86 assembly (clang, -O0):
<changePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbf0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x3f0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x3f0(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1080 <strtok@plt>
lea    -0x3f0(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x5,%eax
mov    %eax,-0xbd4(%rbp)
movl   $0x0,-0xbd8(%rbp)
mov    -0xbd4(%rbp),%eax
mov    %eax,-0xbe0(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xbe0(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1228 <changePath+0xb8>
mov    -0x8(%rbp),%rax
movslq -0xbd4(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0xbd8(%rbp),%rax
mov    %cl,-0x3f0(%rbp,%rax,1)
mov    -0xbd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbd4(%rbp)
mov    -0xbd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbd8(%rbp)
jmp    11c1 <changePath+0x51>
lea    -0x7e0(%rbp),%rax
mov    %rax,-0xbf0(%rbp)
lea    0xdca(%rip),%rdi
call   1030 <getenv@plt>
mov    -0xbf0(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0xbd0(%rbp),%rax
mov    %rax,-0xbe8(%rbp)
lea    -0x7e0(%rbp),%rdi
lea    -0x3f0(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0xbe8(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0xbd0(%rbp),%rsi
lea    0xd78(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %eax,-0xbdc(%rbp)
cmpl   $0x0,-0xbdc(%rbp)
je     12b8 <changePath+0x148>
lea    0xd59(%rip),%rdi
call   1070 <printf@plt>
add    $0xbf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changePath>:
push   %rbp
push   %r14
push   %rbx
sub    $0xbd0,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
add    $0x5,%ebp
mov    %r14,%rdi
call   1070 <strlen@plt>
cmp    %eax,%ebp
jg     11df <changePath+0x6f>
movslq %ebp,%rbp
add    $0xffffffffffffffff,%rbp
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%r14,%rbp,1),%eax
mov    %al,(%rbx)
mov    %r14,%rdi
call   1070 <strlen@plt>
cltq
add    $0x1,%rbx
add    $0x1,%rbp
cmp    %rax,%rbp
jl     11c0 <changePath+0x50>
lea    0xe21(%rip),%r14
mov    %r14,%rdi
call   1030 <getenv@plt>
lea    0x7e0(%rsp),%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
lea    0x3f0(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <setenv@plt>
test   %eax,%eax
je     123f <changePath+0xcf>
lea    0xdd2(%rip),%rdi
call   1050 <puts@plt>
add    $0xbd0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"$PATH:\00"
@.str.1 = [5 x i8] c"PATH\00"
@.str.2 = [14 x i8] c"Invalid path\0A\00"
define void @changePath(i8* %0) {
%2 = alloca i8*
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i8]
%5 = alloca [1000 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%10 = load i8*, i8** %2
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%13 = call i32 @strtok(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 5
store i32 %16, i32* %6
store i32 0, i32* %7
br label %17
17: ; preds = %34, %1
%18 = load i32, i32* %6
%19 = load i8*, i8** %2
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 1
%22 = icmp slt i32 %18, %21
br i1 %22, label %23, label %37
23: ; preds = %17
%24 = load i8*, i8** %2
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %30
store i8 %28, i8* %31
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %34
34: ; preds = %23
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %17
37: ; preds = %17
%38 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%39 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%42 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%44 = call i8* @strcat(i8* %42, i8* %43)
%45 = call i32 @strcpy(i8* %41, i8* %44)
%46 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%47 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %46, i32 1)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %37
%51 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %37
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"$PATH:\00"
@.str.1 = [5 x i8] c"PATH\00"
@str = [13 x i8] c"Invalid path\00"
define void @changePath(i8* %0) {
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%8 = call i32 @strcpy(i8* %5, i8* %0)
%9 = call i32 @strtok(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strlen(i8* %5)
%11 = add i32 %10, 5
%12 = call i32 @strlen(i8* %0)
%13 = icmp sgt i32 %11, %12
br i1 %13, label %27, label %14
14: ; preds = %1
%15 = sext i32 %11 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %23, %16 ]
%18 = phi i64 [ %15, %14 ], [ %22, %16 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %17
store i8 %20, i8* %21
%22 = add nsw i64 %18, 1
%23 = add nuw nsw i64 %17, 1
%24 = call i32 @strlen(i8* %0)
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %18, %25
br i1 %26, label %16, label %27
27: ; preds = %16, %1
%28 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @strcpy(i8* %6, i8* %28)
%30 = call i8* @strcat(i8* %6, i8* %5)
%31 = call i32 @strcpy(i8* %7, i8* %6)
%32 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 1)
%33 = icmp eq i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %27
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %34, %27
ret void
}