#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 */
typedef int /*<<< orphan*/ currPos;

/* Variables and functions */
int chdir(char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int executeCdCommand(char *arg) {
  int status = 0;
  char destination[1024], currPos[1024];
  if (getcwd(currPos, sizeof(currPos)) == NULL) {
    perror("getcwd() error");
  }
  strcpy(destination, currPos);
  strcat(destination, "/");
  strcat(destination, arg);
  status = chdir(destination);
  if (status != 0) {
    perror("Error");
    return -1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<executeCdCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x820(%rbp),%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
cmp    $0x0,%rax
jne    118d <executeCdCommand+0x3d>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x420(%rbp),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f4 <executeCdCommand+0xa4>
lea    0xe2e(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <executeCdCommand+0xab>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<executeCdCommand>:
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
test   %rax,%rax
je     11b7 <executeCdCommand+0x67>
lea    0x400(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1040 <chdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    11c5 <executeCdCommand+0x75>
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe42(%rip),%rdi
call   1060 <perror@plt>
jmp    116f <executeCdCommand+0x1f>
lea    0xe45(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    11ac <executeCdCommand+0x5c>

LLVM IR (-O0):
@.str = [15 x i8] c"getcwd() error\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [6 x i8] c"Error\00"
define i32 @executeCdCommand(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 0, i32* %4
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%8 = call i32* @getcwd(i8* %7, i32 1024)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i32 @strcat(i8* %18, i8* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = call i32 @chdir(i8* %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %12
%26 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %28
27: ; preds = %12
store i32 0, i32* %2
br label %28
28: ; preds = %27, %25
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [15 x i8] c"getcwd() error\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [6 x i8] c"Error\00"
define i32 @executeCdCommand(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32* @getcwd(i8* %5, i32 1024)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = call i32 @strcpy(i8* %4, i8* %5)
%12 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @strcat(i8* %4, i8* %0)
%14 = call i32 @chdir(i8* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %10, %16
%19 = phi i32 [ -1, %16 ], [ 0, %10 ]
ret i32 %19
}