#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 */
struct nli {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ check_if_trace(char *);
int /*<<< orphan*/ free(char *);
char *run_all(struct nli *, char *, char *, char *);
char *run_local(struct nli *, char *);
char *run_remote(char *, char *, char *, char *);
char *str_replace(char *, char *, char *);
char *route_command(struct nli *nli, int who, char *rmt, char *cmd, char *buf,
                    char *uq) {
  char *r = NULL;
  switch (who) {
  case 0:
    r = run_local(nli, cmd);
    break;
  case 1:
    r = run_remote(rmt, buf, cmd, uq);
    break;
  case 2:
    r = run_all(nli, cmd, buf, uq);
    if (check_if_trace(cmd)) {
      char *tmp = NULL;
      tmp = str_replace("\n|", "\n ", r);
      if (r)
        free(r);
      r = tmp;
    }
    break;
  }
  return r;
}


x86 assembly (clang, -O0):
<route_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
test   %eax,%eax
je     11bc <route_command+0x5c>
jmp    119a <route_command+0x3a>
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
je     11d2 <route_command+0x72>
jmp    11ab <route_command+0x4b>
mov    -0x44(%rbp),%eax
sub    $0x2,%eax
je     11f0 <route_command+0x90>
jmp    125f <route_command+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <run_local@plt>
mov    %rax,-0x38(%rbp)
jmp    125f <route_command+0xff>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1070 <run_remote@plt>
mov    %rax,-0x38(%rbp)
jmp    125f <route_command+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1080 <run_all@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <check_if_trace@plt>
cmp    $0x0,%eax
je     125a <route_command+0xfa>
movq   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rdx
lea    0xdd2(%rip),%rdi
lea    0xdce(%rip),%rsi
call   1060 <str_replace@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1252 <route_command+0xf2>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    125f <route_command+0xff>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<route_command>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
cmp    $0x2,%esi
je     1184 <route_command+0x24>
cmp    $0x1,%esi
je     11c9 <route_command+0x69>
test   %esi,%esi
jne    11e1 <route_command+0x81>
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <run_local@plt>
mov    %rbx,%rsi
mov    %r8,%rdx
mov    %r9,%rcx
call   1080 <run_all@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <check_if_trace@plt>
test   %eax,%eax
je     11e5 <route_command+0x85>
lea    0xe58(%rip),%rdi
lea    0xe54(%rip),%rsi
mov    %r14,%rdx
call   1060 <str_replace@plt>
mov    %rax,%rbx
test   %r14,%r14
je     11e8 <route_command+0x88>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    11e8 <route_command+0x88>
mov    %rdx,%rdi
mov    %r8,%rsi
mov    %rbx,%rdx
mov    %r9,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <run_remote@plt>
xor    %ebx,%ebx
jmp    11e8 <route_command+0x88>
mov    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.nli = type { i32 }
@.str = [3 x i8] c"\0A|\00"
@.str.1 = [3 x i8] c"\0A \00"
define i8* @route_command(%struct.nli* %0, i32 %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca %struct.nli*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store %struct.nli* %0, %struct.nli** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
store i8* null, i8** %13
%15 = load i32, i32* %8
switch i32 %15, label %46 [
i32 0, label %16
i32 1, label %20
i32 2, label %26
]
16: ; preds = %6
%17 = load %struct.nli*, %struct.nli** %7
%18 = load i8*, i8** %10
%19 = call i8* @run_local(%struct.nli* %17, i8* %18)
store i8* %19, i8** %13
br label %46
20: ; preds = %6
%21 = load i8*, i8** %9
%22 = load i8*, i8** %11
%23 = load i8*, i8** %10
%24 = load i8*, i8** %12
%25 = call i8* @run_remote(i8* %21, i8* %22, i8* %23, i8* %24)
store i8* %25, i8** %13
br label %46
26: ; preds = %6
%27 = load %struct.nli*, %struct.nli** %7
%28 = load i8*, i8** %10
%29 = load i8*, i8** %11
%30 = load i8*, i8** %12
%31 = call i8* @run_all(%struct.nli* %27, i8* %28, i8* %29, i8* %30)
store i8* %31, i8** %13
%32 = load i8*, i8** %10
%33 = call i32 @check_if_trace(i8* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %26
store i8* null, i8** %14
%36 = load i8*, i8** %13
%37 = call i8* @str_replace(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %36)
store i8* %37, i8** %14
%38 = load i8*, i8** %13
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i8*, i8** %13
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %40, %35
%44 = load i8*, i8** %14
store i8* %44, i8** %13
br label %45
45: ; preds = %43, %26
br label %46
46: ; preds = %6, %45, %20, %16
%47 = load i8*, i8** %13
ret i8* %47
}

LLVM IR (-O2):
%struct.nli = type { i32 }
@.str = [3 x i8] c"\0A|\00"
@.str.1 = [3 x i8] c"\0A \00"
define i8* @route_command(%struct.nli* %0, i32 %1, i8* %2, i8* %3, i8* %4, i8* %5) {
switch i32 %1, label %20 [
i32 0, label %7
i32 1, label %9
i32 2, label %11
]
7: ; preds = %6
%8 = tail call i8* @run_local(%struct.nli* %0, i8* %3)
br label %20
9: ; preds = %6
%10 = tail call i8* @run_remote(i8* %2, i8* %4, i8* %3, i8* %5)
br label %20
11: ; preds = %6
%12 = tail call i8* @run_all(%struct.nli* %0, i8* %3, i8* %4, i8* %5)
%13 = tail call i32 @check_if_trace(i8* %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = tail call i8* @str_replace(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%17 = icmp eq i8* %12, null
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @free(i8* %12)
br label %20
20: ; preds = %15, %18, %11, %6, %9, %7
%21 = phi i8* [ null, %6 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %16, %18 ], [ %16, %15 ]
ret i8* %21
}