#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_TRUNC;
int O_WRONLY;
scalar_t__ check_built(char **);
char **check_path(char **);
int create_file(char *);
int my_exec_red(char **, char **, char **, int);
int /*<<< orphan*/ my_putstr(char *);
int open(char *, int);
int s_arrow_right(char **comand, char **file, char **env, int point) {
  int fd;
  char **way;
  (void)point;
  if ((check_built(comand)) == 0) {
    way = check_path(env);
    if (file == NULL) {
      my_putstr("bash: syntax error near unexpected token `newline'\n");
      return (0);
    }
    if ((fd = open(file[0], O_WRONLY | O_TRUNC)) == -1)
      fd = create_file(file[0]);
    if (comand == NULL)
      return (0);
    if (my_exec_red(comand, env, way, fd) == -1)
      return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<s_arrow_right>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <check_built@plt>
cmp    $0x0,%rax
jne    1238 <s_arrow_right+0xd8>
mov    -0x20(%rbp),%rdi
call   1060 <check_path@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ba <s_arrow_right+0x5a>
lea    0xe57(%rip),%rdi
call   1040 <my_putstr@plt>
movl   $0x0,-0x4(%rbp)
jmp    123f <s_arrow_right+0xdf>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    0x2e27(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    11f3 <s_arrow_right+0x93>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1070 <create_file@plt>
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120a <s_arrow_right+0xaa>
movl   $0x0,-0x4(%rbp)
jmp    123f <s_arrow_right+0xdf>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%ecx
call   1080 <my_exec_red@plt>
cmp    $0xffffffff,%eax
jne    1233 <s_arrow_right+0xd3>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <s_arrow_right+0xdf>
jmp    1238 <s_arrow_right+0xd8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_arrow_right>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
call   1030 <check_built@plt>
test   %rax,%rax
je     1189 <s_arrow_right+0x29>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   1060 <check_path@plt>
test   %r12,%r12
je     11e3 <s_arrow_right+0x83>
mov    %rax,%r15
mov    (%r12),%rdi
mov    0x2e2c(%rip),%rax
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
jne    11c2 <s_arrow_right+0x62>
mov    (%r12),%rdi
call   1070 <create_file@plt>
test   %rbx,%rbx
je     117b <s_arrow_right+0x1b>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
call   1080 <my_exec_red@plt>
cmp    $0xffffffff,%eax
jne    117b <s_arrow_right+0x1b>
mov    $0xffffffff,%eax
jmp    117d <s_arrow_right+0x1d>
lea    0xe16(%rip),%rdi
call   1040 <my_putstr@plt>
jmp    117b <s_arrow_right+0x1b>

LLVM IR (-O0):
@.str = [52 x i8] c"bash: syntax error near unexpected token `newline'\0A\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
define i32 @s_arrow_right(i8** %0, i8** %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8**
store i8** %0, i8*** %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
%12 = load i32, i32* %9
%13 = load i8**, i8*** %6
%14 = call i64 @check_built(i8** %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %50
16: ; preds = %4
%17 = load i8**, i8*** %8
%18 = call i8** @check_path(i8** %17)
store i8** %18, i8*** %11
%19 = load i8**, i8*** %7
%20 = icmp eq i8** %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @my_putstr(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %51
23: ; preds = %16
%24 = load i8**, i8*** %7
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_TRUNC
%29 = or i32 %27, %28
%30 = call i32 @open(i8* %26, i32 %29)
store i32 %30, i32* %10
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %37
32: ; preds = %23
%33 = load i8**, i8*** %7
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @create_file(i8* %35)
store i32 %36, i32* %10
br label %37
37: ; preds = %32, %23
%38 = load i8**, i8*** %6
%39 = icmp eq i8** %38, null
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 0, i32* %5
br label %51
41: ; preds = %37
%42 = load i8**, i8*** %6
%43 = load i8**, i8*** %8
%44 = load i8**, i8*** %11
%45 = load i32, i32* %10
%46 = call i32 @my_exec_red(i8** %42, i8** %43, i8** %44, i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %49
48: ; preds = %41
store i32 -1, i32* %5
br label %51
49: ; preds = %41
br label %50
50: ; preds = %49, %4
store i32 0, i32* %5
br label %51
51: ; preds = %50, %48, %40, %21
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
@.str = [52 x i8] c"bash: syntax error near unexpected token `newline'\0A\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
define i32 @s_arrow_right(i8** %0, i8** %1, i8** %2, i32 %3) {
%5 = tail call i64 @check_built(i8** %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %28
7: ; preds = %4
%8 = tail call i8** @check_path(i8** %2)
%9 = icmp eq i8** %1, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @my_putstr(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
br label %29
12: ; preds = %7
%13 = load i8*, i8** %1
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_TRUNC
%16 = or i32 %15, %14
%17 = tail call i32 @open(i8* %13, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i8*, i8** %1
%21 = tail call i32 @create_file(i8* %20)
br label %22
22: ; preds = %19, %12
%23 = phi i32 [ %21, %19 ], [ %17, %12 ]
%24 = icmp eq i8** %0, null
br i1 %24, label %29, label %25
25: ; preds = %22
%26 = tail call i32 @my_exec_red(i8** %0, i8** %2, i8** %8, i32 %23)
%27 = icmp eq i32 %26, -1
br i1 %27, label %29, label %28
28: ; preds = %25, %4
br label %29
29: ; preds = %25, %22, %28, %10
%30 = phi i32 [ 0, %10 ], [ 0, %28 ], [ 0, %22 ], [ -1, %25 ]
ret i32 %30
}