#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 access(char *, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
int main(void) {
  printf("\x1b[36mWelcome to \x1b[31mSea Shell\x1b[36m! The most awesome shell "
         "on Earth.\x1b[0m\n");
  printf("\x1b[33m\"Everytime I get sad, I stop beeing sad and be awesome "
         "instead. True story.\" \x1b[31m(\x1b[32mBarney "
         "Stinson\x1b[31m)\x1b[0m\n");
  char *shell = getenv("SHELL");
  if (shell == NULL || strcmp(shell, "/usr/bin/seash") == 0) {
    if (access("/bin/bash", 0) != -1) {
      strcpy(shell, "/bin/bash");
    } else {
      strcpy(shell, "/bin/sh");
    }
  }
  system(shell);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1060 <printf@plt>
lea    0xec9(%rip),%rdi
call   1060 <printf@plt>
lea    0xf34(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11bc <main+0x5c>
mov    -0x10(%rbp),%rdi
lea    0xf1b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11fd <main+0x9d>
lea    0xf14(%rip),%rdi
xor    %esi,%esi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
je     11e8 <main+0x88>
mov    -0x10(%rbp),%rdi
lea    0xef9(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11f8 <main+0x98>
mov    -0x10(%rbp),%rdi
lea    0xeee(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11fd <main+0x9d>
mov    -0x10(%rbp),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xebc(%rip),%rdi
call   1050 <puts@plt>
lea    0xefa(%rip),%rdi
call   1050 <puts@plt>
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a4 <main+0x44>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11cb <main+0x6b>
lea    0xe6a(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
lea    0xe60(%rip),%rsi
cmovne %r14,%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [75 x i8] c"\1B[36mWelcome to \1B[31mSea Shell\1B[36m! The most awesome shell on Earth.\1B[0m\0A\00"
@.str.1 = [119 x i8] c"\1B[33m\22Everytime I get sad, I stop beeing sad and be awesome instead. True story.\22 \1B[31m(\1B[32mBarney Stinson\1B[31m)\1B[0m\0A\00"
@.str.2 = [6 x i8] c"SHELL\00"
@.str.3 = [15 x i8] c"/usr/bin/seash\00"
@.str.4 = [10 x i8] c"/bin/bash\00"
@.str.5 = [8 x i8] c"/bin/sh\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.1, i64 0, i64 0))
%5 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %8, %0
%13 = call i32 @access(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 0)
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %21
18: ; preds = %12
%19 = load i8*, i8** %2
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %21
21: ; preds = %18, %15
br label %22
22: ; preds = %21, %8
%23 = load i8*, i8** %2
%24 = call i32 @system(i8* %23)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [6 x i8] c"SHELL\00"
@.str.3 = [15 x i8] c"/usr/bin/seash\00"
@.str.4 = [10 x i8] c"/bin/bash\00"
@.str.5 = [8 x i8] c"/bin/sh\00"
@str = [74 x i8] c"\1B[36mWelcome to \1B[31mSea Shell\1B[36m! The most awesome shell on Earth.\1B[0m\00"
@str.6 = [118 x i8] c"\1B[33m\22Everytime I get sad, I stop beeing sad and be awesome instead. True story.\22 \1B[31m(\1B[32mBarney Stinson\1B[31m)\1B[0m\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([118 x i8], [118 x i8]* @str.6, i64 0, i64 0))
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5, %0
%9 = tail call i32 @access(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 0)
%10 = icmp eq i32 %9, -1
%11 = select i1 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0)
%12 = tail call i32 @strcpy(i8* %3, i8* %11)
br label %13
13: ; preds = %8, %5
%14 = tail call i32 @system(i8* %3)
ret i32 0
}