#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*/ perror(char *);
scalar_t__ strcmp(char *, char *);
int isValidRedirectionAppend(char **tokens) {
  int i = 0, outcount = 0, incount = 0;
  for (i = 0; tokens[i] != NULL; i++) {
    if (strcmp(tokens[i], "<") == 0) {
      if (incount == 0)
        incount++;
      else
        perror("More than one in redirection.\n");
    }
    if (strcmp(tokens[i], ">>") == 0) {
      if (outcount == 0)
        outcount++;
      else
        perror("More than one append redirection.\n");
    }
  }
  if (outcount == 1)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<isValidRedirectionAppend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1204 <isValidRedirectionAppend+0xe4>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe92(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11a6 <isValidRedirectionAppend+0x86>
cmpl   $0x0,-0x1c(%rbp)
jne    1195 <isValidRedirectionAppend+0x75>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a1 <isValidRedirectionAppend+0x81>
lea    0xe66(%rip),%rdi
call   1040 <perror@plt>
jmp    11a6 <isValidRedirectionAppend+0x86>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe68(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11f1 <isValidRedirectionAppend+0xd1>
cmpl   $0x0,-0x18(%rbp)
jne    11e0 <isValidRedirectionAppend+0xc0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ec <isValidRedirectionAppend+0xcc>
lea    0xe3d(%rip),%rdi
call   1040 <perror@plt>
jmp    11f1 <isValidRedirectionAppend+0xd1>
jmp    11f6 <isValidRedirectionAppend+0xd6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <isValidRedirectionAppend+0x28>
cmpl   $0x1,-0x18(%rbp)
jne    121a <isValidRedirectionAppend+0xfa>
movl   $0x1,-0x4(%rbp)
jmp    1221 <isValidRedirectionAppend+0x101>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isValidRedirectionAppend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     11b0 <isValidRedirectionAppend+0x90>
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0xebd(%rip),%r14
lea    0xed7(%rip),%r12
xor    %r15d,%r15d
jmp    1162 <isValidRedirectionAppend+0x42>
nop
mov    %r15d,%r13d
mov    (%rbx),%rdi
add    $0x8,%rbx
mov    %r13d,%r15d
test   %rdi,%rdi
je     11b3 <isValidRedirectionAppend+0x93>
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1178 <isValidRedirectionAppend+0x58>
test   %ebp,%ebp
jne    11a2 <isValidRedirectionAppend+0x82>
mov    $0x1,%ebp
mov    -0x8(%rbx),%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1150 <isValidRedirectionAppend+0x30>
mov    $0x1,%r13d
test   %r15d,%r15d
je     1153 <isValidRedirectionAppend+0x33>
lea    0xe89(%rip),%rdi
call   1040 <perror@plt>
jmp    1153 <isValidRedirectionAppend+0x33>
lea    0xe59(%rip),%rdi
call   1040 <perror@plt>
jmp    1173 <isValidRedirectionAppend+0x53>
xor    %r13d,%r13d
xor    %eax,%eax
cmp    $0x1,%r13d
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"<\00"
@.str.1 = [31 x i8] c"More than one in redirection.\0A\00"
@.str.2 = [3 x i8] c">>\00"
@.str.3 = [35 x i8] c"More than one append redirection.\0A\00"
define i32 @isValidRedirectionAppend(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %4
br label %7
7: ; preds = %49, %1
%8 = load i8**, i8*** %3
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %52
14: ; preds = %7
%15 = load i8**, i8*** %3
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %14
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %30
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
br label %31
31: ; preds = %30, %14
%32 = load i8**, i8*** %3
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %31
%40 = load i32, i32* %5
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %47
45: ; preds = %39
%46 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
br label %48
48: ; preds = %47, %31
br label %49
49: ; preds = %48
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %7
52: ; preds = %7
%53 = load i32, i32* %5
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %56
55: ; preds = %52
store i32 1, i32* %2
br label %57
56: ; preds = %52
store i32 0, i32* %2
br label %57
57: ; preds = %56, %55
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
@.str = [2 x i8] c"<\00"
@.str.1 = [31 x i8] c"More than one in redirection.\0A\00"
@.str.2 = [3 x i8] c">>\00"
@.str.3 = [35 x i8] c"More than one append redirection.\0A\00"
define i32 @isValidRedirectionAppend(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %31, label %4
4: ; preds = %1, %25
%5 = phi i64 [ %27, %25 ], [ 0, %1 ]
%6 = phi i8* [ %29, %25 ], [ %2, %1 ]
%7 = phi i8** [ %28, %25 ], [ %0, %1 ]
%8 = phi i32 [ %17, %25 ], [ 0, %1 ]
%9 = phi i32 [ %26, %25 ], [ 0, %1 ]
%10 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = icmp eq i32 %8, 0
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %12, %14, %4
%17 = phi i32 [ 1, %14 ], [ %8, %4 ], [ 1, %12 ]
%18 = load i8*, i8** %7
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = icmp eq i32 %9, 0
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %21, %16, %23
%26 = phi i32 [ 1, %23 ], [ %9, %16 ], [ 1, %21 ]
%27 = add nuw i64 %5, 1
%28 = getelementptr inbounds i8*, i8** %0, i64 %27
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %4
31: ; preds = %25, %1
%32 = phi i32 [ 0, %1 ], [ %26, %25 ]
%33 = icmp eq i32 %32, 1
%34 = zext i1 %33 to i32
ret i32 %34
}