#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_APPEND;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
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);
int d_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_RDWR | O_APPEND, S_IRUSR | S_IWUSR)) == -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):
<d_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    124a <d_arrow_right+0xea>
mov    -0x20(%rbp),%rdi
call   1060 <check_path@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ba <d_arrow_right+0x5a>
lea    0xe57(%rip),%rdi
call   1040 <my_putstr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1251 <d_arrow_right+0xf1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
mov    0x2def(%rip),%rax
or     (%rax),%esi
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
mov    0x2dfd(%rip),%rax
or     (%rax),%edx
call   1050 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    1205 <d_arrow_right+0xa5>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1070 <create_file@plt>
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    121c <d_arrow_right+0xbc>
movl   $0x0,-0x4(%rbp)
jmp    1251 <d_arrow_right+0xf1>
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    1245 <d_arrow_right+0xe5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <d_arrow_right+0xf1>
jmp    124a <d_arrow_right+0xea>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_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 <d_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     11f5 <d_arrow_right+0x95>
mov    %rax,%r15
mov    (%r12),%rdi
mov    0x2e44(%rip),%rax
mov    0x2e15(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e1a(%rip),%rax
mov    0x2e23(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1050 <open@plt>
cmp    $0xffffffff,%eax
jne    11d4 <d_arrow_right+0x74>
mov    (%r12),%rdi
call   1070 <create_file@plt>
test   %rbx,%rbx
je     117b <d_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 <d_arrow_right+0x1b>
mov    $0xffffffff,%eax
jmp    117d <d_arrow_right+0x1d>
lea    0xe04(%rip),%rdi
call   1040 <my_putstr@plt>
jmp    117b <d_arrow_right+0x1b>

LLVM IR (-O0):
@.str = [52 x i8] c"bash: syntax error near unexpected token `newline'\0A\00"
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @d_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 %53
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 %54
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_RDWR
%28 = load i32, i32* @O_APPEND
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %30, %31
%33 = call i32 @open(i8* %26, i32 %29, i32 %32)
store i32 %33, i32* %10
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %23
%36 = load i8**, i8*** %7
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = call i32 @create_file(i8* %38)
store i32 %39, i32* %10
br label %40
40: ; preds = %35, %23
%41 = load i8**, i8*** %6
%42 = icmp eq i8** %41, null
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 0, i32* %5
br label %54
44: ; preds = %40
%45 = load i8**, i8*** %6
%46 = load i8**, i8*** %8
%47 = load i8**, i8*** %11
%48 = load i32, i32* %10
%49 = call i32 @my_exec_red(i8** %45, i8** %46, i8** %47, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %52
51: ; preds = %44
store i32 -1, i32* %5
br label %54
52: ; preds = %44
br label %53
53: ; preds = %52, %4
store i32 0, i32* %5
br label %54
54: ; preds = %53, %51, %43, %21
%55 = load i32, i32* %5
ret i32 %55
}

LLVM IR (-O2):
@.str = [52 x i8] c"bash: syntax error near unexpected token `newline'\0A\00"
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @d_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 %31
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 %32
12: ; preds = %7
%13 = load i8*, i8** %1
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_APPEND
%16 = or i32 %15, %14
%17 = load i32, i32* @S_IRUSR
%18 = load i32, i32* @S_IWUSR
%19 = or i32 %18, %17
%20 = tail call i32 @open(i8* %13, i32 %16, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i8*, i8** %1
%24 = tail call i32 @create_file(i8* %23)
br label %25
25: ; preds = %22, %12
%26 = phi i32 [ %24, %22 ], [ %20, %12 ]
%27 = icmp eq i8** %0, null
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = tail call i32 @my_exec_red(i8** %0, i8** %2, i8** %8, i32 %26)
%30 = icmp eq i32 %29, -1
br i1 %30, label %32, label %31
31: ; preds = %28, %4
br label %32
32: ; preds = %28, %25, %31, %10
%33 = phi i32 [ 0, %10 ], [ 0, %31 ], [ 0, %25 ], [ -1, %28 ]
ret i32 %33
}