#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 O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int countTokens(char **);
int dup(int);
int /*<<< orphan*/ freeArray(char **);
char **myTok(char *, char);
int /*<<< orphan*/ open(char *, int, int /*<<< orphan*/);
char *rmTailSpaces(char *);
int /*<<< orphan*/ runWithPipes(char *);
void prepGusintah(char *process) {
  char *gusintah = rmTailSpaces(process);
  char **gusToks = myTok(process, '>');
  if (countTokens(gusToks) > 1) {
    char **dispToks = myTok(gusToks[1], ' ');
    int saved_stdout = dup(1);
    close(1);
    open(dispToks[0], O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU);
    freeArray(dispToks);
    runWithPipes(gusToks[0]);
    close(1);
    dup(saved_stdout);
  } else {
    runWithPipes(process);
  }
  freeArray(gusToks);
}


x86 assembly (clang, -O0):
<prepGusintah>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <rmTailSpaces@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3e,%esi
call   1080 <myTok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <countTokens@plt>
cmp    $0x1,%eax
jle    1246 <prepGusintah+0xc6>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x20,%esi
call   1080 <myTok@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1,%edi
call   1050 <dup@plt>
mov    %eax,-0x24(%rbp)
mov    $0x1,%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
mov    0x2dbf(%rip),%rax
or     (%rax),%esi
mov    0x2de6(%rip),%rax
or     (%rax),%esi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
call   1090 <open@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <freeArray@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <runWithPipes@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    -0x24(%rbp),%edi
call   1050 <dup@plt>
jmp    124f <prepGusintah+0xcf>
mov    -0x8(%rbp),%rdi
call   1030 <runWithPipes@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <freeArray@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepGusintah>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
call   1070 <rmTailSpaces@plt>
mov    %rbp,%rdi
mov    $0x3e,%esi
call   1080 <myTok@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <countTokens@plt>
cmp    $0x2,%eax
jl     1222 <prepGusintah+0xa2>
mov    0x8(%rbx),%rdi
mov    $0x20,%esi
call   1080 <myTok@plt>
mov    %rax,%rbp
mov    $0x1,%edi
call   1050 <dup@plt>
mov    %eax,%r14d
mov    $0x1,%edi
call   1060 <close@plt>
mov    0x0(%rbp),%rdi
mov    0x2e1c(%rip),%rax
mov    0x2ddd(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e02(%rip),%rax
or     (%rax),%esi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
call   1090 <open@plt>
mov    %rbp,%rdi
call   10a0 <freeArray@plt>
mov    (%rbx),%rdi
call   1030 <runWithPipes@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    %r14d,%edi
call   1050 <dup@plt>
jmp    122a <prepGusintah+0xaa>
mov    %rbp,%rdi
call   1030 <runWithPipes@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    10a0 <freeArray@plt>

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
define void @prepGusintah(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @rmTailSpaces(i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %2
%10 = call i8** @myTok(i8* %9, i8 signext 62)
store i8** %10, i8*** %4
%11 = load i8**, i8*** %4
%12 = call i32 @countTokens(i8** %11)
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %40
14: ; preds = %1
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i8** @myTok(i8* %17, i8 signext 32)
store i8** %18, i8*** %5
%19 = call i32 @dup(i32 1)
store i32 %19, i32* %6
%20 = call i32 @close(i32 1)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_CREAT
%25 = load i32, i32* @O_WRONLY
%26 = or i32 %24, %25
%27 = load i32, i32* @O_TRUNC
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IRWXU
%30 = call i32 @open(i8* %23, i32 %28, i32 %29)
%31 = load i8**, i8*** %5
%32 = call i32 @freeArray(i8** %31)
%33 = load i8**, i8*** %4
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @runWithPipes(i8* %35)
%37 = call i32 @close(i32 1)
%38 = load i32, i32* %6
%39 = call i32 @dup(i32 %38)
br label %43
40: ; preds = %1
%41 = load i8*, i8** %2
%42 = call i32 @runWithPipes(i8* %41)
br label %43
43: ; preds = %40, %14
%44 = load i8**, i8*** %4
%45 = call i32 @freeArray(i8** %44)
ret void
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
define void @prepGusintah(i8* %0) {
%2 = tail call i8* @rmTailSpaces(i8* %0)
%3 = tail call i8** @myTok(i8* %0, i8 signext 62)
%4 = tail call i32 @countTokens(i8** %3)
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %25
6: ; preds = %1
%7 = getelementptr inbounds i8*, i8** %3, i64 1
%8 = load i8*, i8** %7
%9 = tail call i8** @myTok(i8* %8, i8 signext 32)
%10 = tail call i32 @dup(i32 1)
%11 = tail call i32 @close(i32 1)
%12 = load i8*, i8** %9
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_WRONLY
%15 = or i32 %14, %13
%16 = load i32, i32* @O_TRUNC
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IRWXU
%19 = tail call i32 @open(i8* %12, i32 %17, i32 %18)
%20 = tail call i32 @freeArray(i8** %9)
%21 = load i8*, i8** %3
%22 = tail call i32 @runWithPipes(i8* %21)
%23 = tail call i32 @close(i32 1)
%24 = tail call i32 @dup(i32 %10)
br label %27
25: ; preds = %1
%26 = tail call i32 @runWithPipes(i8* %0)
br label %27
27: ; preds = %25, %6
%28 = tail call i32 @freeArray(i8** %3)
ret void
}