#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*/ getenv(char *);
int /*<<< orphan*/ run_test(char *, int, char **);
int /*<<< orphan*/ setenv(char *, char *, int /*<<< orphan*/);
int strcmp(int /*<<< orphan*/, char *);
int test_cdhome(int argc, char **argv) {
  char *args[] = {"./shell", NULL};
  char *old_dir_name, *new_dir_name;
  int result;
  setenv("HOME", "/", 0);
  old_dir_name = get_current_dir_name();
  run_test("cd\nexit\n", 1, args);
  new_dir_name = get_current_dir_name();
  result = strcmp(getenv("HOME"), 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_cdhome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c6a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c67(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe5c(%rip),%rdi
lea    0xe5a(%rip),%rsi
xor    %edx,%edx
call   1050 <setenv@plt>
mov    $0x0,%al
call   1090 <get_current_dir_name@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdx
lea    0xe3f(%rip),%rdi
mov    $0x1,%esi
call   1080 <run_test@plt>
mov    $0x0,%al
call   1090 <get_current_dir_name@plt>
mov    %rax,-0x30(%rbp)
lea    0xe1c(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    -0x30(%rbp),%rsi
call   1070 <strcmp@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <chdir@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x0,-0x34(%rbp)
je     1232 <test_cdhome+0xb2>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1237 <test_cdhome+0xb7>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_cdhome>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0x2c6f(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe6c(%rip),%r14
lea    0xe6a(%rip),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1050 <setenv@plt>
xor    %eax,%eax
call   1090 <get_current_dir_name@plt>
mov    %rax,%r15
lea    0xe51(%rip),%rdi
mov    %rsp,%rdx
mov    $0x1,%esi
call   1080 <run_test@plt>
xor    %eax,%eax
call   1090 <get_current_dir_name@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1060 <chdir@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
test   %ebp,%ebp
jne    1219 <test_cdhome+0x99>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

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

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