#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char gettoken(char **, char *, char **, char **);
int /*<<< orphan*/ mkcopy(char *, char *);
scalar_t__ peek(char **, char *, char *);
struct cmd *redircmd(struct cmd *, int /*<<< orphan*/, char);
int /*<<< orphan*/ stderr;
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') {
      fprintf(stderr, "missing file for redirection\n");
      exit(-1);
    }
    switch (tok) {
    case '<':
      cmd = redircmd(cmd, mkcopy(q, eq), '<');
      break;
    case '>':
      cmd = redircmd(cmd, mkcopy(q, eq), '>');
      break;
    }
  }
  return cmd;
}


x86 assembly (clang, -O0):
<parseredirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe7d(%rip),%rdx
call   1030 <peek@plt>
cmp    $0x0,%rax
je     126d <parseredirs+0x10d>
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     11ec <parseredirs+0x8c>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3c,%eax
je     1211 <parseredirs+0xb1>
jmp    1200 <parseredirs+0xa0>
mov    -0x34(%rbp),%eax
sub    $0x3e,%eax
je     123f <parseredirs+0xdf>
jmp    1268 <parseredirs+0x108>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <mkcopy@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    $0x3c,%edx
call   1080 <redircmd@plt>
mov    %rax,-0x8(%rbp)
jmp    1268 <parseredirs+0x108>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <mkcopy@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
mov    $0x3e,%edx
call   1080 <redircmd@plt>
mov    %rax,-0x8(%rbp)
jmp    1174 <parseredirs+0x14>
mov    -0x8(%rbp),%rax
add    $0x50,%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,%r15
lea    0xe82(%rip),%rdx
mov    %rsi,%rdi
mov    %r14,%rsi
call   1030 <peek@plt>
test   %rax,%rax
je     1226 <parseredirs+0xc6>
lea    0x8(%rsp),%r13
lea    0xe62(%rip),%rbp
jmp    11d4 <parseredirs+0x74>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1050 <mkcopy@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    $0x3e,%edx
call   1080 <redircmd@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1030 <peek@plt>
test   %rax,%rax
je     1226 <parseredirs+0xc6>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <gettoken@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %r14,%rsi
lea    0x10(%rsp),%rdx
mov    %r13,%rcx
call   1040 <gettoken@plt>
cmp    $0x61,%al
jne    1238 <parseredirs+0xd8>
movsbl %r12b,%eax
cmp    $0x3e,%eax
je     11a0 <parseredirs+0x40>
cmp    $0x3c,%eax
jne    11c1 <parseredirs+0x61>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1050 <mkcopy@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    $0x3c,%edx
jmp    11b9 <parseredirs+0x59>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.cmd = type { i32 }
@.str = [3 x i8] c"<>\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"missing file for redirection\0A\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 = %43, %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 %44
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 %29
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %15
%30 = load i32, i32* %7
switch i32 %30, label %43 [
i32 60, label %31
i32 62, label %37
]
31: ; preds = %29
%32 = load %struct.cmd*, %struct.cmd** %4
%33 = load i8*, i8** %8
%34 = load i8*, i8** %9
%35 = call i32 @mkcopy(i8* %33, i8* %34)
%36 = call %struct.cmd* @redircmd(%struct.cmd* %32, i32 %35, i8 signext 60)
store %struct.cmd* %36, %struct.cmd** %4
br label %43
37: ; preds = %29
%38 = load %struct.cmd*, %struct.cmd** %4
%39 = load i8*, i8** %8
%40 = load i8*, i8** %9
%41 = call i32 @mkcopy(i8* %39, i8* %40)
%42 = call %struct.cmd* @redircmd(%struct.cmd* %38, i32 %41, i8 signext 62)
store %struct.cmd* %42, %struct.cmd** %4
br label %43
43: ; preds = %29, %37, %31
br label %10
44: ; preds = %10
%45 = load %struct.cmd*, %struct.cmd** %4
ret %struct.cmd* %45
}

LLVM IR (-O2):
%struct.cmd = type { i32 }
@.str = [3 x i8] c"<>\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"missing file for redirection\0A\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 = call signext i8 @gettoken(i8** %1, i8* %2, i8** %4, i8** %5)
%14 = icmp eq i8 %13, 97
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %10
%20 = sext i8 %12 to i32
switch i32 %20, label %31 [
i32 60, label %21
i32 62, label %26
]
21: ; preds = %19
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = call i32 @mkcopy(i8* %22, i8* %23)
%25 = call %struct.cmd* @redircmd(%struct.cmd* %11, i32 %24, i8 signext 60)
br label %31
26: ; preds = %19
%27 = load i8*, i8** %4
%28 = load i8*, i8** %5
%29 = call i32 @mkcopy(i8* %27, i8* %28)
%30 = call %struct.cmd* @redircmd(%struct.cmd* %11, i32 %29, i8 signext 62)
br label %31
31: ; preds = %19, %26, %21
%32 = phi %struct.cmd* [ %11, %19 ], [ %30, %26 ], [ %25, %21 ]
%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
}