#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*/ STDIN_FILENO;
int /*<<< orphan*/ execute(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stdout;
int main(void) {
  int ret;
  char buf[256];
  while (1) {
    printf("root@zOS $ ");
    fflush(stdout);
    ret = read(STDIN_FILENO, buf, 256);
    if (ret < 0) {
      printf("\nshell: read failed\n");
      continue;
    }
    if (ret > 1) {
      buf[ret - 1] = 0;
      execute(buf);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a4 <main+0x64>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
jmp    1152 <main+0x12>
cmpl   $0x1,-0x8(%rbp)
jle    11ca <main+0x8a>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
call   1040 <execute@plt>
jmp    1152 <main+0x12>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
lea    0xe99(%rip),%r14
mov    0x2e72(%rip),%r12
mov    0x2e63(%rip),%r13
mov    %rsp,%rbx
lea    0xe8d(%rip),%r15
jmp    1198 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    (%r12),%edi
call   1070 <fflush@plt>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1190 <main+0x40>
cmp    $0x2,%eax
jb     1198 <main+0x48>
add    $0xffffffff,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
call   1050 <execute@plt>
jmp    1198 <main+0x48>

LLVM IR (-O0):
@.str = [12 x i8] c"root@zOS $ \00"
@stdout = global i32 0
@STDIN_FILENO = global i32 0
@.str.1 = [21 x i8] c"\0Ashell: read failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
store i32 0, i32* %1
br label %4
4: ; preds = %0, %13, %25
%5 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = call i32 @fflush(i32 %6)
%8 = load i32, i32* @STDIN_FILENO
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 256)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %4
15: ; preds = %4
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i32, i32* %2
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%24 = call i32 @execute(i8* %23)
br label %25
25: ; preds = %18, %15
br label %4
}

LLVM IR (-O2):
@.str = [12 x i8] c"root@zOS $ \00"
@stdout = global i32 0
@STDIN_FILENO = global i32 0
@str = [20 x i8] c"\0Ashell: read failed\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %14, %0
%4 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = call i32 @fflush(i32 %5)
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @read(i32 %7, i8* %2, i32 256)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %14
12: ; preds = %3
%13 = icmp ugt i32 %8, 1
br i1 %13, label %15, label %14
14: ; preds = %12, %15, %10
br label %3
15: ; preds = %12
%16 = add nsw i32 %8, -1
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @execute(i8* %2)
br label %14
}