#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 chdir(char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ strcmp(char *, char *);
void changeDir(char *prePipe, char **argvPre) {
  int error;
  if (strcmp(prePipe, "cd") == 0) {
    error = chdir("/home");
  } else {
    error = chdir(argvPre[1]);
  }
  if (error != 0) {
    perror("invalid path");
  }
}


x86 assembly (clang, -O0):
<changeDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    116e <changeDir+0x3e>
lea    0xea2(%rip),%rdi
call   1030 <chdir@plt>
mov    %eax,-0x14(%rbp)
jmp    117e <changeDir+0x4e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <chdir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1194 <changeDir+0x64>
lea    0xe7a(%rip),%rdi
call   1050 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeDir>:
push   %rbx
mov    %rsi,%rbx
lea    0xec5(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     114b <changeDir+0x1b>
mov    0x8(%rbx),%rdi
jmp    1152 <changeDir+0x22>
lea    0xeb1(%rip),%rdi
call   1030 <chdir@plt>
test   %eax,%eax
jne    115d <changeDir+0x2d>
pop    %rbx
ret
lea    0xea5(%rip),%rdi
pop    %rbx
jmp    1050 <perror@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"cd\00"
@.str.1 = [6 x i8] c"/home\00"
@.str.2 = [13 x i8] c"invalid path\00"
define void @changeDir(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%6 = load i8*, i8** %3
%7 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @chdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %10, i32* %5
br label %16
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @chdir(i8* %14)
store i32 %15, i32* %5
br label %16
16: ; preds = %11, %9
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"cd\00"
@.str.1 = [6 x i8] c"/home\00"
@.str.2 = [13 x i8] c"invalid path\00"
define void @changeDir(i8* %0, i8** nocapture %1) {
%3 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
br label %8
8: ; preds = %2, %5
%9 = phi i8* [ %7, %5 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %2 ]
%10 = tail call i32 @chdir(i8* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
ret void
}