#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 chkred(char *, int *, int *, int *, int *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
char *strtok(char *, char *);
void tokenize(char **arguments, char **fname, char *line, int *inred,
              int *outred, int *append, int *pipe_flag) {
  int i;
  char *token;
  char *separator = " \t\n";
  token = strtok(line, separator);
  i = *inred = *outred = *append = 0;
  *pipe_flag = -1;
  arguments[i++] = token;
  while (token != NULL) {
    token = strtok(NULL, separator);
    switch (chkred(token, inred, outred, append, pipe_flag)) {
    case 1: {
      fname[0] = strtok(NULL, separator);
      if (fname[0] == NULL) {
        printf("ERROR while saving the path for redirection\n");
        exit(141);
      }
      break;
    }
    case 2: {
      fname[1] = strtok(NULL, separator);
      if (fname[1] == NULL) {
        printf("ERROR while saving the path for redirection\n");
        exit(141);
      }
      break;
    }
    case 3: {
      fname[2] = strtok(NULL, separator);
      if (fname[2] == NULL) {
        printf("ERROR while saving the path for redirection\n");
        exit(141);
      }
      break;
    }
    case 4: {
      arguments[i++] = NULL;
      *pipe_flag = i;
      break;
    }
    default:
      arguments[i++] = token;
    }
  }
  arguments[i] = NULL;
  return;
}


x86 assembly (clang, -O0):
<tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x34(%rbp)
mov    0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x40(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
cmpq   $0x0,-0x40(%rbp)
je     132f <tokenize+0x1ef>
mov    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    0x10(%rbp),%r8
call   1040 <chkred@plt>
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0x3,%eax
ja     1310 <tokenize+0x1d0>
mov    -0x50(%rbp),%rax
lea    0xde5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    125f <tokenize+0x11f>
lea    0xdc4(%rip),%rdi
call   1030 <printf@plt>
mov    $0x8d,%edi
call   1060 <exit@plt>
jmp    132a <tokenize+0x1ea>
mov    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    12a1 <tokenize+0x161>
lea    0xd82(%rip),%rdi
call   1030 <printf@plt>
mov    $0x8d,%edi
call   1060 <exit@plt>
jmp    132a <tokenize+0x1ea>
mov    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jne    12e3 <tokenize+0x1a3>
lea    0xd40(%rip),%rdi
call   1030 <printf@plt>
mov    $0x8d,%edi
call   1060 <exit@plt>
jmp    132a <tokenize+0x1ea>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x34(%rbp)
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x34(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    132a <tokenize+0x1ea>
mov    -0x40(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11c9 <tokenize+0x89>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r15
mov    %r8,%r12
mov    %rcx,%rbx
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbp
mov    0x50(%rsp),%r14
lea    0xea5(%rip),%rsi
mov    %rdx,%rdi
call   1050 <strtok@plt>
movl   $0x0,(%r15)
movl   $0x0,(%r12)
movl   $0x0,(%rbx)
movl   $0xffffffff,(%r14)
mov    %rbp,0x8(%rsp)
mov    %rax,0x0(%rbp)
mov    $0x1,%ebp
test   %rax,%rax
je     128f <tokenize+0x14f>
lea    0xe53(%rip),%r14
jmp    11d8 <tokenize+0x98>
nop
xor    %edi,%edi
lea    0xe57(%rip),%rsi
call   1050 <strtok@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
test   %rax,%rax
je     12ae <tokenize+0x16e>
test   %r13,%r13
je     128f <tokenize+0x14f>
xor    %edi,%edi
lea    0xe2f(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    0x50(%rsp),%r8
call   1040 <chkred@plt>
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1230 <tokenize+0xf0>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
xor    %edi,%edi
lea    0xdf7(%rip),%rsi
call   1050 <strtok@plt>
mov    0x10(%rsp),%rcx
mov    %rax,0x8(%rcx)
jmp    11c6 <tokenize+0x86>
nopl   0x0(%rax)
movslq %ebp,%rax
add    $0x1,%ebp
mov    0x8(%rsp),%rcx
mov    %r13,(%rcx,%rax,8)
jmp    11cf <tokenize+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
lea    0xdb7(%rip),%rsi
call   1050 <strtok@plt>
mov    0x10(%rsp),%rcx
mov    %rax,0x10(%rcx)
jmp    11c6 <tokenize+0x86>
nopl   0x0(%rax)
movslq %ebp,%rax
add    $0x1,%ebp
mov    0x8(%rsp),%rcx
movq   $0x0,(%rcx,%rax,8)
mov    0x50(%rsp),%rax
mov    %ebp,(%rax)
jmp    11cf <tokenize+0x8f>
movslq %ebp,%rax
mov    0x8(%rsp),%rcx
movq   $0x0,(%rcx,%rax,8)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x8d,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c" \09\0A\00"
@.str.1 = [45 x i8] c"ERROR while saving the path for redirection\0A\00"
define void @tokenize(i8** %0, i8** %1, i8* %2, i32* %3, i32* %4, i32* %5, i32* %6) {
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
store i8** %0, i8*** %8
store i8** %1, i8*** %9
store i8* %2, i8** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
store i32* %6, i32** %14
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %17
%18 = load i8*, i8** %10
%19 = load i8*, i8** %17
%20 = call i8* @strtok(i8* %18, i8* %19)
store i8* %20, i8** %16
%21 = load i32*, i32** %13
store i32 0, i32* %21
%22 = load i32*, i32** %12
store i32 0, i32* %22
%23 = load i32*, i32** %11
store i32 0, i32* %23
store i32 0, i32* %15
%24 = load i32*, i32** %14
store i32 -1, i32* %24
%25 = load i8*, i8** %16
%26 = load i8**, i8*** %8
%27 = load i32, i32* %15
%28 = add nsw i32 %27, 1
store i32 %28, i32* %15
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
store i8* %25, i8** %30
br label %31
31: ; preds = %97, %7
%32 = load i8*, i8** %16
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %98
34: ; preds = %31
%35 = load i8*, i8** %17
%36 = call i8* @strtok(i8* null, i8* %35)
store i8* %36, i8** %16
%37 = load i8*, i8** %16
%38 = load i32*, i32** %11
%39 = load i32*, i32** %12
%40 = load i32*, i32** %13
%41 = load i32*, i32** %14
%42 = call i32 @chkred(i8* %37, i32* %38, i32* %39, i32* %40, i32* %41)
switch i32 %42, label %90 [
i32 1, label %43
i32 2, label %56
i32 3, label %69
i32 4, label %82
]
43: ; preds = %34
%44 = load i8*, i8** %17
%45 = call i8* @strtok(i8* null, i8* %44)
%46 = load i8**, i8*** %9
%47 = getelementptr inbounds i8*, i8** %46, i64 0
store i8* %45, i8** %47
%48 = load i8**, i8*** %9
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %55
52: ; preds = %43
%53 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%54 = call i32 @exit(i32 141)
unreachable
55: ; preds = %43
br label %97
56: ; preds = %34
%57 = load i8*, i8** %17
%58 = call i8* @strtok(i8* null, i8* %57)
%59 = load i8**, i8*** %9
%60 = getelementptr inbounds i8*, i8** %59, i64 1
store i8* %58, i8** %60
%61 = load i8**, i8*** %9
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %68
65: ; preds = %56
%66 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%67 = call i32 @exit(i32 141)
unreachable
68: ; preds = %56
br label %97
69: ; preds = %34
%70 = load i8*, i8** %17
%71 = call i8* @strtok(i8* null, i8* %70)
%72 = load i8**, i8*** %9
%73 = getelementptr inbounds i8*, i8** %72, i64 2
store i8* %71, i8** %73
%74 = load i8**, i8*** %9
%75 = getelementptr inbounds i8*, i8** %74, i64 2
%76 = load i8*, i8** %75
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %81
78: ; preds = %69
%79 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%80 = call i32 @exit(i32 141)
unreachable
81: ; preds = %69
br label %97
82: ; preds = %34
%83 = load i8**, i8*** %8
%84 = load i32, i32* %15
%85 = add nsw i32 %84, 1
store i32 %85, i32* %15
%86 = sext i32 %84 to i64
%87 = getelementptr inbounds i8*, i8** %83, i64 %86
store i8* null, i8** %87
%88 = load i32, i32* %15
%89 = load i32*, i32** %14
store i32 %88, i32* %89
br label %97
90: ; preds = %34
%91 = load i8*, i8** %16
%92 = load i8**, i8*** %8
%93 = load i32, i32* %15
%94 = add nsw i32 %93, 1
store i32 %94, i32* %15
%95 = sext i32 %93 to i64
%96 = getelementptr inbounds i8*, i8** %92, i64 %95
store i8* %91, i8** %96
br label %97
97: ; preds = %90, %82, %81, %68, %55
br label %31
98: ; preds = %31
%99 = load i8**, i8*** %8
%100 = load i32, i32* %15
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8*, i8** %99, i64 %101
store i8* null, i8** %102
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c" \09\0A\00"
@str.3 = [44 x i8] c"ERROR while saving the path for redirection\00"
define void @tokenize(i8** nocapture writeonly %0, i8** nocapture writeonly %1, i8* %2, i32* %3, i32* %4, i32* %5, i32* %6) {
%8 = tail call i8* @strtok(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %3
store i32 -1, i32* %6
store i8* %8, i8** %0
%9 = icmp eq i8* %8, null
br i1 %9, label %46, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
br label %13
13: ; preds = %10, %43
%14 = phi i32 [ 1, %10 ], [ %44, %43 ]
%15 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @chkred(i8* %15, i32* %3, i32* %4, i32* %5, i32* %6)
switch i32 %16, label %39 [
i32 1, label %17
i32 2, label %23
i32 3, label %29
i32 4, label %35
]
17: ; preds = %13
%18 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %1
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %43
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.3, i64 0, i64 0))
%22 = tail call i32 @exit(i32 141)
unreachable
23: ; preds = %13
%24 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %12
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %43
26: ; preds = %23
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.3, i64 0, i64 0))
%28 = tail call i32 @exit(i32 141)
unreachable
29: ; preds = %13
%30 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %30, i8** %11
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %43
32: ; preds = %29
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.3, i64 0, i64 0))
%34 = tail call i32 @exit(i32 141)
unreachable
35: ; preds = %13
%36 = add nsw i32 %14, 1
%37 = sext i32 %14 to i64
%38 = getelementptr inbounds i8*, i8** %0, i64 %37
store i8* null, i8** %38
store i32 %36, i32* %6
br label %43
39: ; preds = %13
%40 = add nsw i32 %14, 1
%41 = sext i32 %14 to i64
%42 = getelementptr inbounds i8*, i8** %0, i64 %41
store i8* %15, i8** %42
br label %43
43: ; preds = %29, %23, %17, %39, %35
%44 = phi i32 [ %40, %39 ], [ %36, %35 ], [ %14, %29 ], [ %14, %23 ], [ %14, %17 ]
%45 = icmp eq i8* %15, null
br i1 %45, label %46, label %13
46: ; preds = %43, %7
%47 = phi i32 [ 1, %7 ], [ %44, %43 ]
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %0, i64 %48
store i8* null, i8** %49
ret void
}