#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 */
typedef int ssize_t;

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ process_cmd_line(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int main(void) {
  char *line = NULL;
  size_t buf_sz = 0;
  ssize_t line_len = 0;
  printf("fsh: > ");
  errno = 0;
  while ((line_len = getline(&line, &buf_sz, stdin)) != -1) {
    if (line_len > 0 && line[line_len - 1] == '\n') {
      line[line_len - 1] = '\0';
      line_len--;
    }
    if (line_len > 0 && line[line_len - 1] == '\r') {
      line[line_len - 1] = '\0';
      line_len--;
    }
    if (!strcmp(line, "exit")) {
      break;
    }
    if (line_len > 0) {
      process_cmd_line(line);
    }
    printf("fsh: > ");
    errno = 0;
  }
  if (errno != 0) {
    perror("Error reading line from stdin");
  }
  free(line);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e3f(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     128e <main+0x12e>
cmpl   $0x0,-0x1c(%rbp)
jle    1200 <main+0xa0>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1200 <main+0xa0>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    123e <main+0xde>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    123e <main+0xde>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    125c <main+0xfc>
jmp    128e <main+0x12e>
cmpl   $0x0,-0x1c(%rbp)
jle    126f <main+0x10f>
mov    -0x10(%rbp),%rdi
call   1050 <process_cmd_line@plt>
lea    0xd8a(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d56(%rip),%rax
movq   $0x0,(%rax)
jmp    11a0 <main+0x40>
mov    0x2d43(%rip),%rax
cmpq   $0x0,(%rax)
je     12ab <main+0x14b>
lea    0xd67(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e45(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1279 <main+0x119>
mov    %eax,%ebx
lea    0xe44(%rip),%r13
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    11fe <main+0x9e>
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,(%r14)
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <getline@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1279 <main+0x119>
test   %ebx,%ebx
jle    1250 <main+0xf0>
mov    0x8(%rsp),%rax
lea    -0x1(%rbx),%ecx
cmpb   $0xa,(%rax,%rcx,1)
jne    1230 <main+0xd0>
movb   $0x0,(%rax,%rcx,1)
test   %ecx,%ecx
je     1247 <main+0xe7>
mov    0x8(%rsp),%rax
add    $0xfffffffe,%ebx
mov    %rbx,%rdx
mov    %ebx,%esi
jmp    1237 <main+0xd7>
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rdx
mov    %ecx,%esi
mov    %ebx,%ecx
cmpb   $0xd,(%rax,%rdx,1)
mov    %ecx,%ebx
jne    1250 <main+0xf0>
movb   $0x0,(%rax,%rdx,1)
mov    %esi,%ebx
jmp    1250 <main+0xf0>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1279 <main+0x119>
test   %ebx,%ebx
jle    11d0 <main+0x70>
mov    %rbp,%rdi
call   1050 <process_cmd_line@plt>
jmp    11d0 <main+0x70>
cmpq   $0x0,(%r14)
jne    129a <main+0x13a>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd6c(%rip),%rdi
call   1070 <perror@plt>
jmp    127f <main+0x11f>

LLVM IR (-O0):
@.str = [8 x i8] c"fsh: > \00"
@errno = global i64 0
@stdin = global i32 0
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [30 x i8] c"Error reading line from stdin\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
store i64 0, i64* %3
store i32 0, i32* %4
%5 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* @errno
br label %6
6: ; preds = %61, %0
%7 = load i32, i32* @stdin
%8 = call i32 @getline(i8** %2, i64* %3, i32 %7)
store i32 %8, i32* %4
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %63
10: ; preds = %6
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i8*, i8** %2
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %30
22: ; preds = %13
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 0, i8* %27
%28 = load i32, i32* %4
%29 = add nsw i32 %28, -1
store i32 %29, i32* %4
br label %30
30: ; preds = %22, %13, %10
%31 = load i32, i32* %4
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %50
33: ; preds = %30
%34 = load i8*, i8** %2
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 13
br i1 %41, label %42, label %50
42: ; preds = %33
%43 = load i8*, i8** %2
%44 = load i32, i32* %4
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8 0, i8* %47
%48 = load i32, i32* %4
%49 = add nsw i32 %48, -1
store i32 %49, i32* %4
br label %50
50: ; preds = %42, %33, %30
%51 = load i8*, i8** %2
%52 = call i32 @strcmp(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%53 = icmp ne i32 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %50
br label %63
55: ; preds = %50
%56 = load i32, i32* %4
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i8*, i8** %2
%60 = call i32 @process_cmd_line(i8* %59)
br label %61
61: ; preds = %58, %55
%62 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* @errno
br label %6
63: ; preds = %54, %6
%64 = load i64, i64* @errno
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
%69 = load i8*, i8** %2
%70 = call i32 @free(i8* %69)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"fsh: > \00"
@errno = global i64 0
@stdin = global i32 0
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [30 x i8] c"Error reading line from stdin\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* @errno
%6 = load i32, i32* @stdin
%7 = call i32 @getline(i8** %1, i64* %2, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %48, label %9
9: ; preds = %0, %43
%10 = phi i32 [ %46, %43 ], [ %7, %0 ]
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %34
12: ; preds = %9
%13 = load i8*, i8** %1
%14 = add nsw i32 %10, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %25
19: ; preds = %12
store i8 0, i8* %16
%20 = icmp eq i32 %14, 0
br i1 %20, label %34, label %21
21: ; preds = %19
%22 = load i8*, i8** %1
%23 = add nsw i32 %10, -2
%24 = zext i32 %23 to i64
br label %25
25: ; preds = %21, %12
%26 = phi i64 [ %24, %21 ], [ %15, %12 ]
%27 = phi i32 [ %23, %21 ], [ %14, %12 ]
%28 = phi i8* [ %22, %21 ], [ %13, %12 ]
%29 = phi i32 [ %14, %21 ], [ %10, %12 ]
%30 = getelementptr inbounds i8, i8* %28, i64 %26
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 13
br i1 %32, label %33, label %34
33: ; preds = %25
store i8 0, i8* %30
br label %34
34: ; preds = %9, %33, %25, %19
%35 = phi i32 [ %27, %33 ], [ %29, %25 ], [ 0, %19 ], [ %10, %9 ]
%36 = load i8*, i8** %1
%37 = call i32 @strcmp(i8* dereferenceable(1) %36, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i32 %37, 0
br i1 %38, label %48, label %39
39: ; preds = %34
%40 = icmp sgt i32 %35, 0
br i1 %40, label %41, label %43
41: ; preds = %39
%42 = call i32 @process_cmd_line(i8* %36)
br label %43
43: ; preds = %41, %39
%44 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* @errno
%45 = load i32, i32* @stdin
%46 = call i32 @getline(i8** %1, i64* %2, i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %9
48: ; preds = %43, %34, %0
%49 = load i64, i64* @errno
%50 = icmp eq i64 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %48
%52 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
%54 = load i8*, i8** %1
%55 = call i32 @free(i8* %54)
ret i32 0
}