#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*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
char *strchr(char const *, char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int cds(const char *p) {
  char path[256];
  char *start;
  char *end;
  int res;
  memset(path, '\0', 256);
  start = strchr(p, ' ');
  end = strchr(p, '\n');
  if (!start || !end) {
    printf("can't support this format \n");
    return 1;
  }
  strncpy(path, p + 3, end - start - 1);
  res = chdir(path);
  if (res != 0)
    printf("%s is nod a path,please check again \n", path);
  return res;
}


x86 assembly (clang, -O0):
<cds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x118(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     11b8 <cds+0x68>
cmpq   $0x0,-0x120(%rbp)
jne    11d2 <cds+0x82>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123a <cds+0xea>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x3,%rsi
mov    -0x120(%rbp),%rax
mov    -0x118(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     1231 <cds+0xe1>
lea    -0x110(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cds>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    %r14,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rbx,%rbx
je     11dc <cds+0x7c>
test   %rax,%rax
je     11dc <cds+0x7c>
add    $0x3,%r14
not    %ebx
add    %ebx,%eax
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <chdir@plt>
test   %eax,%eax
je     11ef <cds+0x8f>
mov    %eax,%ebx
lea    0xe30(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    11f1 <cds+0x91>
lea    0xe43(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    11f1 <cds+0x91>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"can't support this format \0A\00"
@.str.1 = [38 x i8] c"%s is nod a path,please check again \0A\00"
define i32 @cds(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i8 signext 0, i32 256)
%10 = load i8*, i8** %3
%11 = call i8* @strchr(i8* %10, i8 signext 32)
store i8* %11, i8** %5
%12 = load i8*, i8** %3
%13 = call i8* @strchr(i8* %12, i8 signext 10)
store i8* %13, i8** %6
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %16, %1
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %42
21: ; preds = %16
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 3
%25 = load i8*, i8** %6
%26 = load i8*, i8** %5
%27 = ptrtoint i8* %25 to i64
%28 = ptrtoint i8* %26 to i64
%29 = sub i64 %27, %28
%30 = sub nsw i64 %29, 1
%31 = trunc i64 %30 to i32
%32 = call i32 @strncpy(i8* %22, i8* %24, i32 %31)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%34 = call i32 @chdir(i8* %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %21
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %21
%41 = load i32, i32* %7
store i32 %41, i32* %2
br label %42
42: ; preds = %40, %19
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@.str.1 = [38 x i8] c"%s is nod a path,please check again \0A\00"
@str = [27 x i8] c"can't support this format \00"
define i32 @cds(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i8 signext 0, i32 256)
%5 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%6 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%7 = icmp ne i8* %5, null
%8 = icmp ne i8* %6, null
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %24
12: ; preds = %1
%13 = getelementptr inbounds i8, i8* %0, i64 3
%14 = ptrtoint i8* %6 to i64
%15 = ptrtoint i8* %5 to i64
%16 = xor i64 %15, -1
%17 = add i64 %14, %16
%18 = trunc i64 %17 to i32
%19 = call i32 @strncpy(i8* %3, i8* %13, i32 %18)
%20 = call i32 @chdir(i8* %3)
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %12
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %24
24: ; preds = %12, %22, %10
%25 = phi i32 [ 1, %10 ], [ %20, %22 ], [ 0, %12 ]
ret i32 %25
}