#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 */
char **build_argv(char *);
scalar_t__ chdir(char *);
int /*<<< orphan*/ execute_cmd(char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
void process_cmd(char *cmd) {
  char **argv = build_argv(cmd);
  if (argv == NULL || argv[0] == NULL) {
    fprintf(stderr, "Warning: got null argv for command %s\n", cmd);
    return;
  }
  if (!strcmp(argv[0], "cd")) {
    if (argv[1] != NULL) {
      if (chdir(argv[1]) < 0) {
        fprintf(stderr, "cd: %s: ", argv[1]);
        perror(NULL);
      }
    }
  } else {
    execute_cmd(argv);
  }
  free(argv);
}


x86 assembly (clang, -O0):
<process_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <build_argv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a2 <process_cmd+0x32>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c0 <process_cmd+0x50>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe4a(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1244 <process_cmd+0xd4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe59(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1232 <process_cmd+0xc2>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     122d <process_cmd+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jge    1228 <process_cmd+0xb8>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe10(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
jmp    122d <process_cmd+0xbd>
jmp    123b <process_cmd+0xcb>
mov    -0x10(%rbp),%rdi
call   1080 <execute_cmd@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_cmd>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1090 <build_argv@plt>
test   %rax,%rax
je     11a6 <process_cmd+0x36>
mov    %rax,%r14
mov    (%rax),%rdi
test   %rdi,%rdi
je     11a6 <process_cmd+0x36>
lea    0xe94(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c5 <process_cmd+0x55>
mov    %r14,%rdi
call   1080 <execute_cmd@plt>
jmp    11d8 <process_cmd+0x68>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <fprintf@plt>
mov    0x8(%r14),%rdi
test   %rdi,%rdi
je     11d8 <process_cmd+0x68>
call   1040 <chdir@plt>
test   %rax,%rax
js     11e7 <process_cmd+0x77>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe2f(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1070 <perror@plt>
jmp    11d8 <process_cmd+0x68>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Warning: got null argv for command %s\0A\00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [9 x i8] c"cd: %s: \00"
define void @process_cmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i8**
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8** @build_argv(i8* %4)
store i8** %5, i8*** %3
%6 = load i8**, i8*** %3
%7 = icmp eq i8** %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = load i8**, i8*** %3
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8, %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %49
17: ; preds = %8
%18 = load i8**, i8*** %3
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %43, label %23
23: ; preds = %17
%24 = load i8**, i8*** %3
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %42
28: ; preds = %23
%29 = load i8**, i8*** %3
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i64 @chdir(i8* %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %3
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = call i32 @perror(i32* null)
br label %41
41: ; preds = %34, %28
br label %42
42: ; preds = %41, %23
br label %46
43: ; preds = %17
%44 = load i8**, i8*** %3
%45 = call i32 @execute_cmd(i8** %44)
br label %46
46: ; preds = %43, %42
%47 = load i8**, i8*** %3
%48 = call i32 @free(i8** %47)
br label %49
49: ; preds = %46, %13
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Warning: got null argv for command %s\0A\00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [9 x i8] c"cd: %s: \00"
define void @process_cmd(i8* %0) {
%2 = tail call i8** @build_argv(i8* %0)
%3 = icmp eq i8** %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4, %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %29
10: ; preds = %4
%11 = tail call i32 @strcmp(i8* %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = getelementptr inbounds i8*, i8** %2, i64 1
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = tail call i64 @chdir(i8* %15)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %14
%23 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = tail call i32 @perror(i32* null)
br label %27
25: ; preds = %10
%26 = tail call i32 @execute_cmd(i8** %2)
br label %27
27: ; preds = %13, %20, %17, %25
%28 = tail call i32 @free(i8** %2)
br label %29
29: ; preds = %27, %7
ret void
}