#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ get_cmdline(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ process_cmdline(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int rfd, wfd;
  char cmdline[100];
  if (argc != 3) {
    fprintf(stderr, "Shell: must be called with exactly two arguments.\n");
    exit(1);
  }
  wfd = atoi(argv[1]);
  rfd = atoi(argv[2]);
  if (!wfd || !rfd) {
    fprintf(stderr, "Shell: descriptors must be non-zero: wfd = %d, rfd = %d\n",
            wfd, rfd);
    exit(1);
  }
  printf("\nThis is the Shell. Welcome.\n\n");
  for (;;) {
    printf("Shell> ");
    fflush(stdout);
    get_cmdline(stdin, cmdline, 100);
    process_cmdline(cmdline, wfd, rfd);
  }
  fprintf(stderr, "Shell: reached unreachable point.\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b4 <main+0x44>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e8 <main+0x78>
cmpl   $0x0,-0x14(%rbp)
jne    120f <main+0x9f>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1080 <get_cmdline@plt>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <process_cmdline@plt>
jmp    121b <main+0xab>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x3,%edi
jne    1211 <main+0x91>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
test   %r15d,%r15d
je     1232 <main+0xb2>
test   %ebp,%ebp
je     1232 <main+0xb2>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9f(%rip),%r14
mov    0x2dfc(%rip),%r12
mov    0x2e0d(%rip),%r13
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <printf@plt>
mov    (%r12),%edi
call   1070 <fflush@plt>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1090 <get_cmdline@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1050 <process_cmdline@plt>
jmp    11e0 <main+0x60>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"Shell: must be called with exactly two arguments.\0A\00"
@.str.1 = [57 x i8] c"Shell: descriptors must be non-zero: wfd = %d, rfd = %d\0A\00"
@.str.2 = [31 x i8] c"\0AThis is the Shell. Welcome.\0A\0A\00"
@.str.3 = [8 x i8] c"Shell> \00"
@stdout = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %15
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %26, %15
%30 = load i32, i32* @stderr
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %26
%36 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %37, %35
%38 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32, i32* @stdout
%40 = call i32 @fflush(i32 %39)
%41 = load i32, i32* @stdin
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%43 = call i32 @get_cmdline(i32 %41, i8* %42, i32 100)
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%45 = load i32, i32* %7
%46 = load i32, i32* %6
%47 = call i32 @process_cmdline(i8* %44, i32 %45, i32 %46)
br label %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"Shell: must be called with exactly two arguments.\0A\00"
@.str.1 = [57 x i8] c"Shell: descriptors must be non-zero: wfd = %d, rfd = %d\0A\00"
@.str.3 = [8 x i8] c"Shell> \00"
@stdout = global i32 0
@stdin = global i32 0
@str = [30 x i8] c"\0AThis is the Shell. Welcome.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = icmp ne i32 %13, 0
%18 = icmp ne i32 %16, 0
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %24, label %20
20: ; preds = %10
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %16)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %10
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %26, %24
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
%30 = load i32, i32* @stdin
%31 = call i32 @get_cmdline(i32 %30, i8* %4, i32 100)
%32 = call i32 @process_cmdline(i8* %4, i32 %13, i32 %16)
br label %26
}