#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*/ EXIT_FAILURE;
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int promptAndParse(char *cmd, char **upstream, char **downstream) {
  int i;
  int parseDownstream;
  printf("ashish> ");
  if (fgets(cmd, PATH_MAX, stdin) == NULL) {
    do {
      perror("fgets");
      exit(EXIT_FAILURE);
    } while (0);
  }
  printf("Before tokenizing = %s\n", cmd);
  i = 0;
  upstream[i] = strtok(cmd, " \t\n");
  printf("upstream[%d] = %s\n", i, upstream[i]);
  i++;
  while ((upstream[i] = strtok(NULL, " \t\n"))) {
    if (strcmp(upstream[i], "|") == 0) {
      upstream[i] = NULL;
      parseDownstream = 1;
      i = 0;
      break;
    }
    printf("upstream[%d] = %s\n", i, upstream[i]);
    i++;
  }
  downstream[0] = NULL;
  if (parseDownstream) {
    while ((downstream[i] = strtok(NULL, " \t\n"))) {
      printf("downstream[%d] = %s\n", i, downstream[i]);
      i++;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<promptAndParse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11c6 <promptAndParse+0x66>
jmp    11ac <promptAndParse+0x4c>
lea    0xe56(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf8(%rip),%rsi
call   1070 <strtok@plt>
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
je     12ba <promptAndParse+0x15a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xde1(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    128f <promptAndParse+0x12f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    12ba <promptAndParse+0x15a>
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1224 <promptAndParse+0xc4>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpl   $0x0,-0x20(%rbp)
je     132a <promptAndParse+0x1ca>
jmp    12d4 <promptAndParse+0x174>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd48(%rip),%rsi
call   1070 <strtok@plt>
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
je     1325 <promptAndParse+0x1c5>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12d4 <promptAndParse+0x174>
jmp    132a <promptAndParse+0x1ca>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<promptAndParse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1040 <fgets@plt>
test   %rax,%rax
je     12ce <promptAndParse+0x16e>
lea    0xe63(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe6a(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strtok@plt>
mov    %rax,(%r15)
lea    0xe59(%rip),%rdi
xor    %esi,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <strtok@plt>
mov    %rax,0x8(%r15)
mov    $0x1,%ebx
test   %rax,%rax
je     125e <promptAndParse+0xfe>
lea    0xe41(%rip),%r12
lea    0xe23(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1254 <promptAndParse+0xf4>
mov    (%r15,%rbx,8),%rdx
lea    0xe00(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x1(%rbx),%r13
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <strtok@plt>
mov    %rax,0x8(%r15,%rbx,8)
mov    %r13,%rbx
test   %rax,%rax
jne    1210 <promptAndParse+0xb0>
mov    %r13d,%ebx
jmp    125e <promptAndParse+0xfe>
movq   $0x0,(%r15,%rbx,8)
xor    %ebx,%ebx
movq   $0x0,(%r14)
lea    0xdbb(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     12ba <promptAndParse+0x15a>
lea    0xdbd(%rip),%r15
lea    0xd9d(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x1(%rbx),%rbp
xor    %edi,%edi
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,0x8(%r14,%rbx,8)
mov    %rbp,%rbx
test   %rax,%rax
jne    1290 <promptAndParse+0x130>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd34(%rip),%rdi
call   1060 <perror@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"ashish> \00"
@PATH_MAX = global i32 0
@stdin = global i32 0
@.str.1 = [6 x i8] c"fgets\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"Before tokenizing = %s\0A\00"
@.str.3 = [4 x i8] c" \09\0A\00"
@.str.4 = [19 x i8] c"upstream[%d] = %s\0A\00"
@.str.5 = [2 x i8] c"|\00"
@.str.6 = [21 x i8] c"downstream[%d] = %s\0A\00"
define i32 @promptAndParse(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %4
%11 = load i32, i32* @PATH_MAX
%12 = load i32, i32* @stdin
%13 = call i32* @fgets(i8* %10, i32 %11, i32 %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %3
br label %16
16: ; preds = %15
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; No predecessors!
br label %21
21: ; preds = %20, %3
%22 = load i8*, i8** %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 0, i32* %7
%24 = load i8*, i8** %4
%25 = call i8* @strtok(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%26 = load i8**, i8*** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
store i8* %25, i8** %29
%30 = load i32, i32* %7
%31 = load i8**, i8*** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %30, i8* %35)
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %39
39: ; preds = %59, %21
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%41 = load i8**, i8*** %5
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
store i8* %40, i8** %44
%45 = icmp ne i8* %40, null
br i1 %45, label %46, label %69
46: ; preds = %39
%47 = load i8**, i8*** %5
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %46
%55 = load i8**, i8*** %5
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
store i8* null, i8** %58
store i32 1, i32* %8
store i32 0, i32* %7
br label %69
59: ; preds = %46
%60 = load i32, i32* %7
%61 = load i8**, i8*** %5
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %60, i8* %65)
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
br label %39
69: ; preds = %54, %39
%70 = load i8**, i8*** %6
%71 = getelementptr inbounds i8*, i8** %70, i64 0
store i8* null, i8** %71
%72 = load i32, i32* %8
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %93
74: ; preds = %69
br label %75
75: ; preds = %82, %74
%76 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%77 = load i8**, i8*** %6
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
store i8* %76, i8** %80
%81 = icmp ne i8* %76, null
br i1 %81, label %82, label %92
82: ; preds = %75
%83 = load i32, i32* %7
%84 = load i8**, i8*** %6
%85 = load i32, i32* %7
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8*, i8** %84, i64 %86
%88 = load i8*, i8** %87
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %83, i8* %88)
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %75
92: ; preds = %75
br label %93
93: ; preds = %92, %69
ret i32 1
}

LLVM IR (-O2):
@.str = [9 x i8] c"ashish> \00"
@PATH_MAX = global i32 0
@stdin = global i32 0
@.str.1 = [6 x i8] c"fgets\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"Before tokenizing = %s\0A\00"
@.str.3 = [4 x i8] c" \09\0A\00"
@.str.4 = [19 x i8] c"upstream[%d] = %s\0A\00"
@.str.5 = [2 x i8] c"|\00"
@.str.6 = [21 x i8] c"downstream[%d] = %s\0A\00"
define i32 @promptAndParse(i8* %0, i8** nocapture %1, i8** nocapture writeonly %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @PATH_MAX
%6 = load i32, i32* @stdin
%7 = tail call i32* @fgets(i8* %0, i32 %5, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %3
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%15 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i8* %15, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 0, i8* %15)
%17 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = getelementptr inbounds i8*, i8** %1, i64 1
store i8* %17, i8** %18
%19 = icmp eq i8* %17, null
br i1 %19, label %37, label %20
20: ; preds = %13, %27
%21 = phi i64 [ %31, %27 ], [ 1, %13 ]
%22 = phi i8** [ %33, %27 ], [ %18, %13 ]
%23 = phi i8* [ %32, %27 ], [ %17, %13 ]
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i8* null, i8** %22
br label %37
27: ; preds = %20
%28 = load i8*, i8** %22
%29 = trunc i64 %21 to i32
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %29, i8* %28)
%31 = add nuw i64 %21, 1
%32 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%33 = getelementptr inbounds i8*, i8** %1, i64 %31
store i8* %32, i8** %33
%34 = icmp eq i8* %32, null
br i1 %34, label %35, label %20
35: ; preds = %27
%36 = and i64 %31, 4294967295
br label %37
37: ; preds = %35, %13, %26
%38 = phi i64 [ 0, %26 ], [ 1, %13 ], [ %36, %35 ]
store i8* null, i8** %2
%39 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%40 = getelementptr inbounds i8*, i8** %2, i64 %38
store i8* %39, i8** %40
%41 = icmp eq i8* %39, null
br i1 %41, label %51, label %42
42: ; preds = %37, %42
%43 = phi i64 [ %47, %42 ], [ %38, %37 ]
%44 = phi i8* [ %48, %42 ], [ %39, %37 ]
%45 = trunc i64 %43 to i32
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %45, i8* %44)
%47 = add nuw i64 %43, 1
%48 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%49 = getelementptr inbounds i8*, i8** %2, i64 %47
store i8* %48, i8** %49
%50 = icmp eq i8* %48, null
br i1 %50, label %51, label %42
51: ; preds = %42, %37
ret i32 1
}