#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 */
struct cmd {
  int dummy;
};

/* Variables and functions */
char gettoken(char **, char *, char **, char **);
int /*<<< orphan*/ panic(char *);
scalar_t__ peek(char **, char *, char *);
struct cmd *redircmd(struct cmd *, char *, char *, int, int);
struct cmd *parseredirs(struct cmd *cmd, char **ps, char *es) {
  int tok;
  char *q, *eq;
  while (peek(ps, es, "<>")) {
    tok = gettoken(ps, es, 0, 0);
    if (gettoken(ps, es, &q, &eq) != 'a')
      panic("missing file for redirection");
    switch (tok) {
    case '<':
      cmd = redircmd(cmd, q, eq, 0x000, 0);
      break;
    case '>':
      cmd = redircmd(cmd, q, eq, 0x001 | 0x200, 1);
      break;
    case '+':
      cmd = redircmd(cmd, q, eq, 0x001 | 0x200, 1);
      break;
    }
  }
  return cmd;
}


x86 assembly (clang, -O0):
<parseredirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe9d(%rip),%rdx
call   1030 <peek@plt>
cmp    $0x0,%rax
je     1259 <parseredirs+0x119>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1040 <gettoken@plt>
movsbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <gettoken@plt>
movsbl %al,%eax
cmp    $0x61,%eax
je     11b9 <parseredirs+0x79>
lea    0xe4f(%rip),%rdi
call   1050 <panic@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x2b,%eax
je     1234 <parseredirs+0xf4>
jmp    11cd <parseredirs+0x8d>
mov    -0x34(%rbp),%eax
sub    $0x3c,%eax
je     11ef <parseredirs+0xaf>
jmp    11de <parseredirs+0x9e>
mov    -0x34(%rbp),%eax
sub    $0x3e,%eax
je     120f <parseredirs+0xcf>
jmp    1254 <parseredirs+0x114>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1060 <redircmd@plt>
mov    %rax,-0x8(%rbp)
jmp    1254 <parseredirs+0x114>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    $0x201,%ecx
mov    $0x1,%r8d
call   1060 <redircmd@plt>
mov    %rax,-0x8(%rbp)
jmp    1254 <parseredirs+0x114>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    $0x201,%ecx
mov    $0x1,%r8d
call   1060 <redircmd@plt>
mov    %rax,-0x8(%rbp)
jmp    1154 <parseredirs+0x14>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseredirs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0xea2(%rip),%rdx
mov    %rsi,%rdi
mov    %r14,%rsi
call   1030 <peek@plt>
test   %rax,%rax
je     120f <parseredirs+0xcf>
lea    0x8(%rsp),%r12
lea    0xe82(%rip),%rbp
jmp    11b3 <parseredirs+0x73>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    %r13,%rdi
mov    $0x201,%ecx
mov    $0x1,%r8d
call   1060 <redircmd@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1030 <peek@plt>
test   %rax,%rax
je     120f <parseredirs+0xcf>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <gettoken@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
lea    0x10(%rsp),%rdx
mov    %r12,%rcx
call   1040 <gettoken@plt>
cmp    $0x61,%al
je     11e8 <parseredirs+0xa8>
lea    0xe20(%rip),%rdi
call   1050 <panic@plt>
movsbl %r15b,%eax
cmp    $0x2b,%eax
je     1180 <parseredirs+0x40>
cmp    $0x3e,%eax
je     1180 <parseredirs+0x40>
cmp    $0x3c,%eax
jne    11a0 <parseredirs+0x60>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    %r13,%rdi
xor    %ecx,%ecx
xor    %r8d,%r8d
jmp    1198 <parseredirs+0x58>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cmd = type { i32 }
@.str = [3 x i8] c"<>\00"
@.str.1 = [29 x i8] c"missing file for redirection\00"
define %struct.cmd* @parseredirs(%struct.cmd* %0, i8** %1, i8* %2) {
%4 = alloca %struct.cmd*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store %struct.cmd* %0, %struct.cmd** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
br label %10
10: ; preds = %44, %3
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %6
%13 = call i64 @peek(i8** %11, i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %45
15: ; preds = %10
%16 = load i8**, i8*** %5
%17 = load i8*, i8** %6
%18 = call signext i8 @gettoken(i8** %16, i8* %17, i8** null, i8** null)
%19 = sext i8 %18 to i32
store i32 %19, i32* %7
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %6
%22 = call signext i8 @gettoken(i8** %20, i8* %21, i8** %8, i8** %9)
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 97
br i1 %24, label %25, label %27
25: ; preds = %15
%26 = call i32 @panic(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %15
%28 = load i32, i32* %7
switch i32 %28, label %44 [
i32 60, label %29
i32 62, label %34
i32 43, label %39
]
29: ; preds = %27
%30 = load %struct.cmd*, %struct.cmd** %4
%31 = load i8*, i8** %8
%32 = load i8*, i8** %9
%33 = call %struct.cmd* @redircmd(%struct.cmd* %30, i8* %31, i8* %32, i32 0, i32 0)
store %struct.cmd* %33, %struct.cmd** %4
br label %44
34: ; preds = %27
%35 = load %struct.cmd*, %struct.cmd** %4
%36 = load i8*, i8** %8
%37 = load i8*, i8** %9
%38 = call %struct.cmd* @redircmd(%struct.cmd* %35, i8* %36, i8* %37, i32 513, i32 1)
store %struct.cmd* %38, %struct.cmd** %4
br label %44
39: ; preds = %27
%40 = load %struct.cmd*, %struct.cmd** %4
%41 = load i8*, i8** %8
%42 = load i8*, i8** %9
%43 = call %struct.cmd* @redircmd(%struct.cmd* %40, i8* %41, i8* %42, i32 513, i32 1)
store %struct.cmd* %43, %struct.cmd** %4
br label %44
44: ; preds = %27, %39, %34, %29
br label %10
45: ; preds = %10
%46 = load %struct.cmd*, %struct.cmd** %4
ret %struct.cmd* %46
}

LLVM IR (-O2):
%struct.cmd = type { i32 }
@.str = [3 x i8] c"<>\00"
@.str.1 = [29 x i8] c"missing file for redirection\00"
define %struct.cmd* @parseredirs(%struct.cmd* %0, i8** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %4 to i8*
%7 = bitcast i8** %5 to i8*
%8 = call i64 @peek(i8** %1, i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %35, label %10
10: ; preds = %3, %31
%11 = phi %struct.cmd* [ %32, %31 ], [ %0, %3 ]
%12 = call signext i8 @gettoken(i8** %1, i8* %2, i8** null, i8** null)
%13 = sext i8 %12 to i32
%14 = call signext i8 @gettoken(i8** %1, i8* %2, i8** %4, i8** %5)
%15 = icmp eq i8 %14, 97
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = call i32 @panic(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
switch i32 %13, label %31 [
i32 60, label %19
i32 62, label %23
i32 43, label %27
]
19: ; preds = %18
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call %struct.cmd* @redircmd(%struct.cmd* %11, i8* %20, i8* %21, i32 0, i32 0)
br label %31
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = call %struct.cmd* @redircmd(%struct.cmd* %11, i8* %24, i8* %25, i32 513, i32 1)
br label %31
27: ; preds = %18
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = call %struct.cmd* @redircmd(%struct.cmd* %11, i8* %28, i8* %29, i32 513, i32 1)
br label %31
31: ; preds = %18, %27, %23, %19
%32 = phi %struct.cmd* [ %11, %18 ], [ %30, %27 ], [ %26, %23 ], [ %22, %19 ]
%33 = call i64 @peek(i8** %1, i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %10
35: ; preds = %31, %3
%36 = phi %struct.cmd* [ %0, %3 ], [ %32, %31 ]
ret %struct.cmd* %36
}