#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *get_current_dir_name();
int /*<<< orphan*/ run_test(char *, int, char **);
int strcmp(char *, char *);
int test_cddash(int argc, char **argv) {
  char *args[] = {"./shell", NULL};
  char *old_dir_name, *new_dir_name;
  int result;
  old_dir_name = get_current_dir_name();
  run_test("cd /usr\ncd -\nexit\n", 1, args);
  new_dir_name = get_current_dir_name();
  result = strcmp(old_dir_name, new_dir_name);
  chdir(old_dir_name);
  free(old_dir_name);
  free(new_dir_name);
  do {
    if (result)
      exit(EXIT_FAILURE);
  } while (0);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<test_cddash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c8a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c87(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <get_current_dir_name@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdx
lea    0xe6d(%rip),%rdi
mov    $0x1,%esi
call   1060 <run_test@plt>
mov    $0x0,%al
call   1070 <get_current_dir_name@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x34(%rbp)
je     11f3 <test_cddash+0x93>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11f8 <test_cddash+0x98>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_cddash>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movaps 0x2c91(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1070 <get_current_dir_name@plt>
mov    %rax,%rbx
lea    0xe84(%rip),%rdi
mov    %rsp,%rdx
mov    $0x1,%esi
call   1060 <run_test@plt>
xor    %eax,%eax
call   1070 <get_current_dir_name@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <chdir@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
jne    11d6 <test_cddash+0x76>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"./shell\00"
@__const.test_cddash.args = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [19 x i8] c"cd /usr\0Acd -\0Aexit\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @test_cddash(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [2 x i8*]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = bitcast [2 x i8*]* %5 to i8*
%10 = call i8* (...) @get_current_dir_name()
store i8* %10, i8** %6
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%12 = call i32 @run_test(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 1, i8** %11)
%13 = call i8* (...) @get_current_dir_name()
store i8* %13, i8** %7
%14 = load i8*, i8** %6
%15 = load i8*, i8** %7
%16 = call i32 @strcmp(i8* %14, i8* %15)
store i32 %16, i32* %8
%17 = load i8*, i8** %6
%18 = call i32 @chdir(i8* %17)
%19 = load i8*, i8** %6
%20 = call i32 @free(i8* %19)
%21 = load i8*, i8** %7
%22 = call i32 @free(i8* %21)
br label %23
23: ; preds = %2
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %23
br label %30
30: ; preds = %29
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}

LLVM IR (-O2):
@.str = [8 x i8] c"./shell\00"
@__const.test_cddash.args = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [19 x i8] c"cd /usr\0Acd -\0Aexit\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @test_cddash(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i8*]
%4 = bitcast [2 x i8*]* %3 to i8*
%5 = tail call i8* (...) @get_current_dir_name()
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%7 = call i32 @run_test(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 1, i8** %6)
%8 = call i8* (...) @get_current_dir_name()
%9 = call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(1) %8)
%10 = call i32 @chdir(i8* %5)
%11 = call i32 @free(i8* %5)
%12 = call i32 @free(i8* %8)
%13 = icmp eq i32 %9, 0
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}