#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*/ eval(char *);
scalar_t__ feof(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free_job();
int /*<<< orphan*/ init_job();
int /*<<< orphan*/ install_signal_handler();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int main(void) {
  init_job();
  install_signal_handler();
  for (;;) {
    printf("> ");
    char cmdline[4096];
    char *ret = fgets(cmdline, 4096, stdin);
    if (ret == NULL) {
      if (ferror(stdin)) {
        perror("fgets");
        free_job();
        return -1;
      }
    }
    if (feof(stdin)) {
      free_job();
      return 0;
    }
    eval(cmdline);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <init_job@plt>
mov    $0x0,%al
call   1080 <install_signal_handler@plt>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1010(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1060 <fgets@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jne    1227 <main+0x97>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1222 <main+0x92>
lea    0xdf9(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1070 <free_job@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1263 <main+0xd3>
jmp    1227 <main+0x97>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     1252 <main+0xc2>
mov    $0x0,%al
call   1070 <free_job@plt>
movl   $0x0,-0x4(%rbp)
jmp    1263 <main+0xd3>
lea    -0x1010(%rbp),%rdi
call   10b0 <eval@plt>
jmp    11b0 <main+0x20>
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
xor    %eax,%eax
call   1040 <init_job@plt>
xor    %eax,%eax
call   1080 <install_signal_handler@plt>
lea    0xe4f(%rip),%r14
mov    0x2e30(%rip),%rbx
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <printf@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0x1000,%esi
call   1060 <fgets@plt>
test   %rax,%rax
jne    11e8 <main+0x58>
mov    (%rbx),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1216 <main+0x86>
mov    (%rbx),%edi
call   1090 <feof@plt>
test   %rax,%rax
jne    11fe <main+0x6e>
mov    %r15,%rdi
call   10b0 <eval@plt>
jmp    11c0 <main+0x30>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <free_job@plt>
mov    %ebx,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xde6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1200 <main+0x70>

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"fgets\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 (...) @init_job()
%5 = call i32 (...) @install_signal_handler()
br label %6
6: ; preds = %27, %0
%7 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i8* @fgets(i8* %8, i32 4096, i32 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %21
13: ; preds = %6
%14 = load i32, i32* @stdin
%15 = call i64 @ferror(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (...) @free_job()
store i32 -1, i32* %1
br label %30
20: ; preds = %13
br label %21
21: ; preds = %20, %6
%22 = load i32, i32* @stdin
%23 = call i64 @feof(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (...) @free_job()
store i32 0, i32* %1
br label %30
27: ; preds = %21
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%29 = call i32 @eval(i8* %28)
br label %6
30: ; preds = %25, %17
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"fgets\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = tail call i32 (...) @init_job()
%3 = tail call i32 (...) @install_signal_handler()
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
br label %5
5: ; preds = %20, %0
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i8* @fgets(i8* %4, i32 4096, i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = load i32, i32* @stdin
%12 = call i64 @ferror(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %22
16: ; preds = %10, %5
%17 = load i32, i32* @stdin
%18 = call i64 @feof(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @eval(i8* %4)
br label %5
22: ; preds = %16, %14
%23 = phi i32 [ -1, %14 ], [ 0, %16 ]
%24 = call i32 (...) @free_job()
ret i32 %23
}