#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 */
char *dash_exec_scmd(char **, int, int, char *);
char *dashp_fio(char *);
char *dashp_pip(char *, char *, char *);
char *extract_host(char *);
int /*<<< orphan*/ free(char *);
char *join_strings(char **, char *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove_substring(char *, char *);
int /*<<< orphan*/ send_to_host(char *, char *);
char **str_split(char *, char *, int *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int dash_eval(char *line, char *std_input, char *origin) {
  if (line == NULL)
    return 1;
  int num_tokens;
  char **tokens = str_split(line, " ", &num_tokens);
  char *token;
  int i;
  int remote_pipe_pos = -1;
  for (i = 0; i < num_tokens; i++) {
    if (strcmp(tokens[i], "~|") == 0) {
      remote_pipe_pos = i;
      break;
    }
  }
  if (remote_pipe_pos == -1) {
    char *msg_data =
        dash_exec_scmd(tokens, remote_pipe_pos + 1, num_tokens, std_input);
    if (std_input == NULL) {
      printf("%s", msg_data);
      return 1;
    } else {
      char *fio_msg = dashp_fio(msg_data);
      send_to_host(fio_msg, origin);
      return 1;
    }
  } else {
    char *subcommand =
        join_strings(tokens, " ", remote_pipe_pos + 1, num_tokens);
    char *remotehost = extract_host(subcommand);
    char *maincommand = join_strings(tokens, " ", 0, remote_pipe_pos);
    char *msg_data = dash_exec_scmd(tokens, 0, remote_pipe_pos, std_input);
    char *send_msg;
    if (std_input == NULL) {
      char *fin_remote_host = (char *)malloc(strlen(remotehost) + 1);
      strcat(fin_remote_host, remotehost);
      strcat(fin_remote_host, ":");
      remove_substring(subcommand, fin_remote_host);
      free(fin_remote_host);
      subcommand[strlen(subcommand) - 1] = '\0';
      send_msg = dashp_pip(msg_data, "127.0.0.1", subcommand);
    } else {
      send_msg = dashp_pip(msg_data, origin, subcommand);
    }
    send_to_host(send_msg, remotehost);
    printf("Sent");
    return 2;
  }
}


x86 assembly (clang, -O0):
<dash_eval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120e <dash_eval+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    141c <dash_eval+0x23c>
mov    -0x10(%rbp),%rdi
lea    0xde7(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   10a0 <str_split@plt>
mov    %rax,-0x30(%rbp)
movl   $0xffffffff,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1280 <dash_eval+0xa0>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdaf(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    126d <dash_eval+0x8d>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    1280 <dash_eval+0xa0>
jmp    1272 <dash_eval+0x92>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1234 <dash_eval+0x54>
cmpl   $0xffffffff,-0x40(%rbp)
jne    12f3 <dash_eval+0x113>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%esi
add    $0x1,%esi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <dash_exec_scmd@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12cd <dash_eval+0xed>
mov    -0x48(%rbp),%rsi
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    141c <dash_eval+0x23c>
mov    -0x48(%rbp),%rdi
call   10d0 <dashp_fio@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <send_to_host@plt>
movl   $0x1,-0x4(%rbp)
jmp    141c <dash_eval+0x23c>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%edx
add    $0x1,%edx
mov    -0x24(%rbp),%ecx
lea    0xcf9(%rip),%rsi
call   10c0 <join_strings@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1100 <extract_host@plt>
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%ecx
lea    0xcd5(%rip),%rsi
xor    %edx,%edx
call   10c0 <join_strings@plt>
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%edx
mov    -0x18(%rbp),%rcx
xor    %esi,%esi
call   1040 <dash_exec_scmd@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    13e5 <dash_eval+0x205>
mov    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x60(%rbp),%rsi
call   10e0 <strcat@plt>
mov    -0x80(%rbp),%rdi
lea    0xc82(%rip),%rsi
call   10e0 <strcat@plt>
mov    -0x58(%rbp),%rdi
mov    -0x80(%rbp),%rsi
call   1080 <remove_substring@plt>
mov    -0x80(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x70(%rbp),%rdi
mov    -0x58(%rbp),%rdx
lea    0xc33(%rip),%rsi
call   10f0 <dashp_pip@plt>
mov    %rax,-0x78(%rbp)
jmp    13fa <dash_eval+0x21a>
mov    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x58(%rbp),%rdx
call   10f0 <dashp_pip@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x60(%rbp),%rsi
call   1070 <send_to_host@plt>
lea    0xc06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dash_eval>:
test   %rdi,%rdi
je     126d <dash_eval+0x8d>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r13
lea    0xdff(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10a0 <str_split@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%edx
test   %edx,%edx
jle    123f <dash_eval+0x5f>
xor    %ebp,%ebp
lea    0xde3(%rip),%r15
nop
mov    (%rbx,%rbp,8),%rdi
mov    %r15,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1273 <dash_eval+0x93>
add    $0x1,%rbp
movslq 0x4(%rsp),%rdx
cmp    %rdx,%rbp
jl     1220 <dash_eval+0x40>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r13,%rcx
call   1040 <dash_exec_scmd@plt>
test   %r13,%r13
je     1345 <dash_eval+0x165>
mov    %rax,%rdi
call   10d0 <dashp_fio@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <send_to_host@plt>
jmp    1356 <dash_eval+0x176>
mov    $0x1,%eax
ret
lea    0x1(%rbp),%edx
mov    0x4(%rsp),%ecx
lea    0xd7f(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <join_strings@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1100 <extract_host@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%r12
xor    %edx,%edx
mov    %ebp,%ecx
call   10c0 <join_strings@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
mov    %r13,%rcx
call   1040 <dash_exec_scmd@plt>
mov    %rax,%rbx
test   %r13,%r13
jne    1317 <dash_eval+0x137>
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
call   10e0 <strcat@plt>
lea    0xd23(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <strcat@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1080 <remove_substring@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
lea    0xcf3(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   10f0 <dashp_pip@plt>
mov    %rax,%rdi
mov    %r12,%rsi
call   1070 <send_to_host@plt>
lea    0xcdd(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x2,%eax
jmp    135b <dash_eval+0x17b>
lea    0xcb9(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"~|\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [10 x i8] c"127.0.0.1\00"
@.str.5 = [5 x i8] c"Sent\00"
define i32 @dash_eval(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%21 = load i8*, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %3
store i32 1, i32* %4
br label %118
24: ; preds = %3
%25 = load i8*, i8** %5
%26 = call i8** @str_split(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %8)
store i8** %26, i8*** %9
store i32 -1, i32* %12
store i32 0, i32* %11
br label %27
27: ; preds = %42, %24
%28 = load i32, i32* %11
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %45
31: ; preds = %27
%32 = load i8**, i8*** %9
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %31
%40 = load i32, i32* %11
store i32 %40, i32* %12
br label %45
41: ; preds = %31
br label %42
42: ; preds = %41
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %27
45: ; preds = %39, %27
%46 = load i32, i32* %12
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %66
48: ; preds = %45
%49 = load i8**, i8*** %9
%50 = load i32, i32* %12
%51 = add nsw i32 %50, 1
%52 = load i32, i32* %8
%53 = load i8*, i8** %6
%54 = call i8* @dash_exec_scmd(i8** %49, i32 %51, i32 %52, i8* %53)
store i8* %54, i8** %13
%55 = load i8*, i8** %6
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %60
57: ; preds = %48
%58 = load i8*, i8** %13
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %58)
store i32 1, i32* %4
br label %118
60: ; preds = %48
%61 = load i8*, i8** %13
%62 = call i8* @dashp_fio(i8* %61)
store i8* %62, i8** %14
%63 = load i8*, i8** %14
%64 = load i8*, i8** %7
%65 = call i32 @send_to_host(i8* %63, i8* %64)
store i32 1, i32* %4
br label %118
66: ; preds = %45
%67 = load i8**, i8*** %9
%68 = load i32, i32* %12
%69 = add nsw i32 %68, 1
%70 = load i32, i32* %8
%71 = call i8* @join_strings(i8** %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %69, i32 %70)
store i8* %71, i8** %15
%72 = load i8*, i8** %15
%73 = call i8* @extract_host(i8* %72)
store i8* %73, i8** %16
%74 = load i8**, i8*** %9
%75 = load i32, i32* %12
%76 = call i8* @join_strings(i8** %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0, i32 %75)
store i8* %76, i8** %17
%77 = load i8**, i8*** %9
%78 = load i32, i32* %12
%79 = load i8*, i8** %6
%80 = call i8* @dash_exec_scmd(i8** %77, i32 0, i32 %78, i8* %79)
store i8* %80, i8** %18
%81 = load i8*, i8** %6
%82 = icmp eq i8* %81, null
br i1 %82, label %83, label %108
83: ; preds = %66
%84 = load i8*, i8** %16
%85 = call i32 @strlen(i8* %84)
%86 = add nsw i32 %85, 1
%87 = call i64 @malloc(i32 %86)
%88 = inttoptr i64 %87 to i8*
store i8* %88, i8** %20
%89 = load i8*, i8** %20
%90 = load i8*, i8** %16
%91 = call i32 @strcat(i8* %89, i8* %90)
%92 = load i8*, i8** %20
%93 = call i32 @strcat(i8* %92, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%94 = load i8*, i8** %15
%95 = load i8*, i8** %20
%96 = call i32 @remove_substring(i8* %94, i8* %95)
%97 = load i8*, i8** %20
%98 = call i32 @free(i8* %97)
%99 = load i8*, i8** %15
%100 = load i8*, i8** %15
%101 = call i32 @strlen(i8* %100)
%102 = sub nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %99, i64 %103
store i8 0, i8* %104
%105 = load i8*, i8** %18
%106 = load i8*, i8** %15
%107 = call i8* @dashp_pip(i8* %105, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %106)
store i8* %107, i8** %19
br label %113
108: ; preds = %66
%109 = load i8*, i8** %18
%110 = load i8*, i8** %7
%111 = load i8*, i8** %15
%112 = call i8* @dashp_pip(i8* %109, i8* %110, i8* %111)
store i8* %112, i8** %19
br label %113
113: ; preds = %108, %83
%114 = load i8*, i8** %19
%115 = load i8*, i8** %16
%116 = call i32 @send_to_host(i8* %114, i8* %115)
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %4
br label %118
118: ; preds = %113, %60, %57, %23
%119 = load i32, i32* %4
ret i32 %119
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"~|\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [10 x i8] c"127.0.0.1\00"
@.str.5 = [5 x i8] c"Sent\00"
define i32 @dash_eval(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = icmp eq i8* %0, null
br i1 %5, label %60, label %6
6: ; preds = %3
%7 = bitcast i32* %4 to i8*
%8 = call i8** @str_split(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %4)
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %6, %17
%12 = phi i64 [ %18, %17 ], [ 0, %6 ]
%13 = getelementptr inbounds i8*, i8** %8, i64 %12
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %31, label %17
17: ; preds = %11
%18 = add nuw nsw i64 %12, 1
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %11, label %22
22: ; preds = %17, %6
%23 = phi i32 [ %9, %6 ], [ %19, %17 ]
%24 = call i8* @dash_exec_scmd(i8** %8, i32 0, i32 %23, i8* %1)
%25 = icmp eq i8* %1, null
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %58
28: ; preds = %22
%29 = call i8* @dashp_fio(i8* %24)
%30 = call i32 @send_to_host(i8* %29, i8* %2)
br label %58
31: ; preds = %11
%32 = trunc i64 %12 to i32
%33 = add nuw nsw i32 %32, 1
%34 = load i32, i32* %4
%35 = call i8* @join_strings(i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %34)
%36 = call i8* @extract_host(i8* %35)
%37 = call i8* @join_strings(i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0, i32 %32)
%38 = call i8* @dash_exec_scmd(i8** %8, i32 0, i32 %32, i8* %1)
%39 = icmp eq i8* %1, null
br i1 %39, label %40, label %53
40: ; preds = %31
%41 = call i32 @strlen(i8* %36)
%42 = add nsw i32 %41, 1
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to i8*
%45 = call i32 @strcat(i8* %44, i8* %36)
%46 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @remove_substring(i8* %35, i8* %44)
%48 = call i32 @free(i8* %44)
%49 = call i32 @strlen(i8* %35)
%50 = add nsw i32 %49, -1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %35, i64 %51
store i8 0, i8* %52
br label %53
53: ; preds = %31, %40
%54 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), %40 ], [ %2, %31 ]
%55 = call i8* @dashp_pip(i8* %38, i8* %54, i8* %35)
%56 = call i32 @send_to_host(i8* %55, i8* %36)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %58
58: ; preds = %26, %28, %53
%59 = phi i32 [ 2, %53 ], [ 1, %28 ], [ 1, %26 ]
br label %60
60: ; preds = %3, %58
%61 = phi i32 [ %59, %58 ], [ 1, %3 ]
ret i32 %61
}