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

/* Variables and functions */
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strsep(char **, char *);
int check_cd(char *cmd) {
  char *cmdcopy;
  strncpy(cmdcopy, cmd, sizeof(cmd));
  char *cmdname;
  cmdcopy = strsep(&cmdcopy, "\n");
  cmdname = strsep(&cmdcopy, " ");
  if (!(strcmp(cmdname, "cd"))) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<check_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    -0x18(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    119b <check_cd+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    11a2 <check_cd+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_cd>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    0xeb7(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strsep@plt>
mov    %rax,0x8(%rsp)
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strsep@plt>
lea    0xe93(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"cd\00"
define i32 @check_cd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strncpy(i8* %6, i8* %7, i32 8)
%9 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %4
%10 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %1
store i32 1, i32* %2
br label %16
15: ; preds = %1
store i32 0, i32* %2
br label %16
16: ; preds = %15, %14
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"cd\00"
define i32 @check_cd(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i32 @strncpy(i8* undef, i8* %0, i32 8)
%5 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
ret i32 %9
}