#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 /*<<< orphan*/ exec(char *, int);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ prompt();
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  char str[256];
  printf("Welcome to psh v%s\n", "0.1");
  while (1) {
    prompt();
    gets(str);
    if (!strlen(str))
      continue;
    if (!exec(str, 1))
      printf("%s: command not found!\n", str);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <prompt@plt>
lea    -0x110(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    11a9 <main+0x59>
jmp    117c <main+0x2c>
lea    -0x110(%rbp),%rdi
mov    $0x1,%esi
call   1070 <exec@plt>
cmp    $0x0,%eax
jne    11d6 <main+0x86>
lea    -0x110(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   1050 <printf@plt>
jmp    117c <main+0x2c>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xe9f(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1050 <printf@plt>
mov    %rsp,%rbx
lea    0xea1(%rip),%r14
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <prompt@plt>
mov    %rbx,%rdi
call   1060 <gets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     1180 <main+0x30>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <exec@plt>
test   %eax,%eax
jne    1180 <main+0x30>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    1180 <main+0x30>

LLVM IR (-O0):
@.str = [20 x i8] c"Welcome to psh v%s\0A\00"
@.str.1 = [4 x i8] c"0.1\00"
@.str.2 = [24 x i8] c"%s: command not found!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %2, %15, %23
%9 = call i32 (...) @prompt()
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = call i32 @gets(i8* %10)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %8
br label %8
16: ; preds = %8
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%18 = call i32 @exec(i8* %17, i32 1)
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %16
br label %8
}

LLVM IR (-O2):
@.str = [20 x i8] c"Welcome to psh v%s\0A\00"
@.str.1 = [4 x i8] c"0.1\00"
@.str.2 = [24 x i8] c"%s: command not found!\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %14, %2
%7 = call i32 (...) @prompt()
%8 = call i32 @gets(i8* %4)
%9 = call i32 @strlen(i8* %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = call i32 @exec(i8* %4, i32 1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %11, %15, %6
br label %6
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %14
}