#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 */
scalar_t__ check_cd(char *);
scalar_t__ check_exit(char *);
int run_cd(char *, char *, int *, int);
int run_exec(char *, char *, int *, int);
int run_exit(char *, char *, int *, int);
char *strip_spaces(char *);
int run(char *cmd, char *filename, int fd[], int oflag) {
  int status;
  cmd = strip_spaces(cmd);
  if (check_cd(cmd)) {
    status = run_cd(cmd, filename, fd, oflag);
  } else if (check_exit(cmd)) {
    status = run_exit(cmd, filename, fd, oflag);
  } else {
    status = run_exec(cmd, filename, fd, oflag);
  }
  return status;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strip_spaces@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <check_cd@plt>
cmp    $0x0,%rax
je     11b3 <run+0x53>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1080 <run_cd@plt>
mov    %eax,-0x20(%rbp)
jmp    11fe <run+0x9e>
mov    -0x8(%rbp),%rdi
call   1040 <check_exit@plt>
cmp    $0x0,%rax
je     11e2 <run+0x82>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <run_exit@plt>
mov    %eax,-0x20(%rbp)
jmp    11f9 <run+0x99>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1050 <run_exec@plt>
mov    %eax,-0x20(%rbp)
jmp    11fe <run+0x9e>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
call   1060 <strip_spaces@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <check_cd@plt>
test   %rax,%rax
je     11a0 <run+0x40>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <run_cd@plt>
mov    %rbx,%rdi
call   1040 <check_exit@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
add    $0x8,%rsp
test   %rax,%rax
je     11c8 <run+0x68>
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <run_exit@plt>
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <run_exec@plt>

LLVM IR (-O0):
define i32 @run(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = call i8* @strip_spaces(i8* %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = call i64 @check_cd(i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = load i32*, i32** %7
%19 = load i32, i32* %8
%20 = call i32 @run_cd(i8* %16, i8* %17, i32* %18, i32 %19)
store i32 %20, i32* %9
br label %38
21: ; preds = %4
%22 = load i8*, i8** %5
%23 = call i64 @check_exit(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = load i32*, i32** %7
%29 = load i32, i32* %8
%30 = call i32 @run_exit(i8* %26, i8* %27, i32* %28, i32 %29)
store i32 %30, i32* %9
br label %37
31: ; preds = %21
%32 = load i8*, i8** %5
%33 = load i8*, i8** %6
%34 = load i32*, i32** %7
%35 = load i32, i32* %8
%36 = call i32 @run_exec(i8* %32, i8* %33, i32* %34, i32 %35)
store i32 %36, i32* %9
br label %37
37: ; preds = %31, %25
br label %38
38: ; preds = %37, %15
%39 = load i32, i32* %9
ret i32 %39
}

LLVM IR (-O2):
define i32 @run(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = tail call i8* @strip_spaces(i8* %0)
%6 = tail call i64 @check_cd(i8* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @run_cd(i8* %5, i8* %1, i32* %2, i32 %3)
br label %17
10: ; preds = %4
%11 = tail call i64 @check_exit(i8* %5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @run_exit(i8* %5, i8* %1, i32* %2, i32 %3)
br label %17
15: ; preds = %10
%16 = tail call i32 @run_exec(i8* %5, i8* %1, i32* %2, i32 %3)
br label %17
17: ; preds = %13, %15, %8
%18 = phi i32 [ %9, %8 ], [ %14, %13 ], [ %16, %15 ]
ret i32 %18
}