#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*/ newdir;

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ printf(char *, ...);
char *strsep(char **, char *);
int run_cd(char *cmd) {
  char *cmdname;
  cmd = strsep(&cmd, "\n");
  cmdname = strsep(&cmd, " ");
  chdir(cmd);
  char newdir[256];
  getcwd(newdir, sizeof(newdir));
  printf("Current dir: %s\n", newdir);
  printf("cd should be running now\n");
}


x86 assembly (clang, -O0):
<run_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xeb7(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <chdir@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1050 <getcwd@plt>
lea    -0x120(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_cd>:
push   %rbx
sub    $0x110,%rsp
mov    %rdi,0x8(%rsp)
lea    0xead(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strsep@plt>
mov    %rax,0x8(%rsp)
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strsep@plt>
mov    0x8(%rsp),%rdi
call   1040 <chdir@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1060 <getcwd@plt>
lea    0xe5a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [17 x i8] c"Current dir: %s\0A\00"
@.str.3 = [26 x i8] c"cd should be running now\0A\00"
define i32 @run_cd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [256 x i8]
store i8* %0, i8** %3
%6 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %3
%7 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @chdir(i8* %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = call i32 @getcwd(i8* %10, i32 256)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [17 x i8] c"Current dir: %s\0A\00"
@str = [25 x i8] c"cd should be running now\00"
define i32 @run_cd(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
store i8* %0, i8** %2
%4 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = call i32 @chdir(i8* %6)
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = call i32 @getcwd(i8* %8, i32 256)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
ret i32 undef
}