#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 */
typedef int ssize_t;
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ free(char *);
scalar_t__ pipe(int *);
int read(int, char *, int);
char *str_concat(char *, char *);
char *str_concatn(char *, char *, char *);
char *str_find(char *, char *, char *);
char *strdup(char *);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
char *preprocBackticks(char *line) {
  char *result = strdup("");
  char *scan = line;
  while (*scan != 0) {
    char *nextBacktick = str_find(scan, "`", "'");
    if (nextBacktick == NULL) {
      char *newline = str_concat(result, scan);
      free(result);
      result = newline;
      break;
    };
    char *newline = str_concatn(result, scan, nextBacktick);
    free(result);
    result = newline;
    scan = nextBacktick + 1;
    nextBacktick = str_find(scan, "`", "'");
    if (nextBacktick == NULL) {
      break;
    };
    *nextBacktick = 0;
    char *subcommand = scan;
    scan = nextBacktick + 1;
    int pipefd[2];
    if (pipe(pipefd) != 0) {
      continue;
    };
    pid_t pid = fork();
    if (pid == -1) {
      continue;
    } else if (pid == 0) {
      close(pipefd[0]);
      close(1);
      dup(pipefd[1]);
      close(pipefd[1]);
      execl("/proc/self/exe", "sh", "-c", subcommand, NULL);
      exit(1);
    } else {
      close(pipefd[1]);
      char buffer[256];
      while (1) {
        ssize_t sz = read(pipefd[0], buffer, 255);
        if (sz == -1)
          break;
        if (sz == 0)
          break;
        buffer[sz] = 0;
        char *newline = str_concat(result, buffer);
        free(result);
        result = newline;
      };
      close(pipefd[0]);
      waitpid(pid, NULL, 0);
    };
  };
  free(line);
  return result;
}


x86 assembly (clang, -O0):
<preprocBackticks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe1d(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     13fb <preprocBackticks+0x22b>
mov    -0x18(%rbp),%rdi
lea    0xdee(%rip),%rsi
lea    0xde9(%rip),%rdx
call   1030 <str_find@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1254 <preprocBackticks+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10e0 <str_concat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    13fb <preprocBackticks+0x22b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <str_concatn@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd6f(%rip),%rsi
lea    0xd6a(%rip),%rdx
call   1030 <str_find@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12b1 <preprocBackticks+0xe1>
jmp    13fb <preprocBackticks+0x22b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
je     12e4 <preprocBackticks+0x114>
jmp    11f7 <preprocBackticks+0x27>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    12fd <preprocBackticks+0x12d>
jmp    11f7 <preprocBackticks+0x27>
cmpl   $0x0,-0x44(%rbp)
jne    1356 <preprocBackticks+0x186>
mov    -0x40(%rbp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    -0x3c(%rbp),%edi
call   1050 <dup@plt>
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
mov    -0x38(%rbp),%rcx
lea    0xcd0(%rip),%rdi
lea    0xcd8(%rip),%rsi
lea    0xcd4(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10d0 <execl@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
mov    -0x40(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0xff,%edx
call   1090 <read@plt>
mov    %eax,-0x154(%rbp)
cmpl   $0xffffffff,-0x154(%rbp)
jne    138a <preprocBackticks+0x1ba>
jmp    13db <preprocBackticks+0x20b>
cmpl   $0x0,-0x154(%rbp)
jne    139c <preprocBackticks+0x1cc>
jmp    13db <preprocBackticks+0x20b>
movslq -0x154(%rbp),%rax
movb   $0x0,-0x150(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   10e0 <str_concat@plt>
mov    %rax,-0x160(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
mov    -0x160(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    135e <preprocBackticks+0x18e>
mov    -0x40(%rbp),%edi
call   1060 <close@plt>
mov    -0x44(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10a0 <waitpid@plt>
jmp    13f6 <preprocBackticks+0x226>
jmp    11f7 <preprocBackticks+0x27>
mov    -0x8(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<preprocBackticks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r14
lea    0xe18(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,%r13
cmpb   $0x0,(%r14)
mov    %r14,0x8(%rsp)
je     130e <preprocBackticks+0x13e>
lea    0xdf7(%rip),%r15
lea    0xdf2(%rip),%rbx
jmp    1245 <preprocBackticks+0x75>
mov    (%rsp),%edi
call   1060 <close@plt>
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <waitpid@plt>
lea    0xdd3(%rip),%r15
lea    0xdce(%rip),%rbx
add    $0x1,%r14
cmpb   $0x0,(%r14)
mov    %rbp,%r13
je     1329 <preprocBackticks+0x159>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <str_find@plt>
test   %rax,%rax
je     1313 <preprocBackticks+0x143>
mov    %rax,%r12
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1080 <str_concatn@plt>
mov    %rax,%rbp
mov    %r13,%rdi
call   1040 <free@plt>
add    $0x1,%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <str_find@plt>
test   %rax,%rax
je     1329 <preprocBackticks+0x159>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1070 <pipe@plt>
test   %rax,%rax
jne    122d <preprocBackticks+0x5d>
xor    %eax,%eax
call   10f0 <fork@plt>
cmp    $0xffffffff,%eax
je     1226 <preprocBackticks+0x56>
mov    %eax,%r15d
test   %eax,%eax
je     1348 <preprocBackticks+0x178>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
lea    0x10(%rsp),%r12
nop
mov    (%rsp),%edi
mov    %r12,%rsi
mov    $0xff,%edx
call   1090 <read@plt>
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jb     1212 <preprocBackticks+0x42>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbp,%rdi
mov    %r12,%rsi
call   10e0 <str_concat@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %rbx,%rbp
jmp    12d0 <preprocBackticks+0x100>
mov    %r13,%rbp
jmp    1329 <preprocBackticks+0x159>
mov    %r13,%rdi
mov    %r14,%rsi
call   10e0 <str_concat@plt>
mov    %rax,%rbp
mov    %r13,%rdi
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    %rbp,%rax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
call   1050 <dup@plt>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
lea    0xc91(%rip),%rdi
lea    0xc99(%rip),%rsi
lea    0xc95(%rip),%rdx
mov    %r12,%rcx
xor    %r8d,%r8d
call   10d0 <execl@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"`\00"
@.str.2 = [2 x i8] c"'\00"
@.str.3 = [15 x i8] c"/proc/self/exe\00"
@.str.4 = [3 x i8] c"sh\00"
@.str.5 = [3 x i8] c"-c\00"
define i8* @preprocBackticks(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [2 x i32]
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %2
%14 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %3
%15 = load i8*, i8** %2
store i8* %15, i8** %4
br label %16
16: ; preds = %112, %61, %56, %1
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %113
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = call i8* @str_find(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = load i8*, i8** %4
%29 = call i8* @str_concat(i8* %27, i8* %28)
store i8* %29, i8** %6
%30 = load i8*, i8** %3
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %6
store i8* %32, i8** %3
br label %113
33: ; preds = %21
%34 = load i8*, i8** %3
%35 = load i8*, i8** %4
%36 = load i8*, i8** %5
%37 = call i8* @str_concatn(i8* %34, i8* %35, i8* %36)
store i8* %37, i8** %7
%38 = load i8*, i8** %3
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %7
store i8* %40, i8** %3
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 1
store i8* %42, i8** %4
%43 = load i8*, i8** %4
%44 = call i8* @str_find(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %44, i8** %5
%45 = load i8*, i8** %5
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %48
47: ; preds = %33
br label %113
48: ; preds = %33
%49 = load i8*, i8** %5
store i8 0, i8* %49
%50 = load i8*, i8** %4
store i8* %50, i8** %8
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i64 1
store i8* %52, i8** %4
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%54 = call i64 @pipe(i32* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %48
br label %16
57: ; preds = %48
%58 = call i32 (...) @fork()
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %62
61: ; preds = %57
br label %16
62: ; preds = %57
%63 = load i32, i32* %10
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %79
65: ; preds = %62
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%67 = load i32, i32* %66
%68 = call i32 @close(i32 %67)
%69 = call i32 @close(i32 1)
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%71 = load i32, i32* %70
%72 = call i32 @dup(i32 %71)
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%74 = load i32, i32* %73
%75 = call i32 @close(i32 %74)
%76 = load i8*, i8** %8
%77 = call i32 @execl(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %76, i32* null)
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %62
%80 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%81 = load i32, i32* %80
%82 = call i32 @close(i32 %81)
br label %83
83: ; preds = %79, %95
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%85 = load i32, i32* %84
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%87 = call i32 @read(i32 %85, i8* %86, i32 255)
store i32 %87, i32* %12
%88 = load i32, i32* %12
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %91
90: ; preds = %83
br label %105
91: ; preds = %83
%92 = load i32, i32* %12
%93 = icmp eq i32 %92, 0
br i1 %93, label %94, label %95
94: ; preds = %91
br label %105
95: ; preds = %91
%96 = load i32, i32* %12
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 %97
store i8 0, i8* %98
%99 = load i8*, i8** %3
%100 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%101 = call i8* @str_concat(i8* %99, i8* %100)
store i8* %101, i8** %13
%102 = load i8*, i8** %3
%103 = call i32 @free(i8* %102)
%104 = load i8*, i8** %13
store i8* %104, i8** %3
br label %83
105: ; preds = %94, %90
%106 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%107 = load i32, i32* %106
%108 = call i32 @close(i32 %107)
%109 = load i32, i32* %10
%110 = call i32 @waitpid(i32 %109, i32* null, i32 0)
br label %111
111: ; preds = %105
br label %112
112: ; preds = %111
br label %16
113: ; preds = %47, %26, %16
%114 = load i8*, i8** %2
%115 = call i32 @free(i8* %114)
%116 = load i8*, i8** %3
ret i8* %116
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"`\00"
@.str.2 = [2 x i8] c"'\00"
@.str.3 = [15 x i8] c"/proc/self/exe\00"
@.str.4 = [3 x i8] c"sh\00"
@.str.5 = [3 x i8] c"-c\00"
define i8* @preprocBackticks(i8* %0) {
%2 = alloca [2 x i32]
%3 = alloca [256 x i8]
%4 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %62, label %7
7: ; preds = %1
%8 = bitcast [2 x i32]* %2 to i8*
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
br label %12
12: ; preds = %7, %58
%13 = phi i8* [ %4, %7 ], [ %59, %58 ]
%14 = phi i8* [ %0, %7 ], [ %27, %58 ]
%15 = call i8* @str_find(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i8* @str_concat(i8* %13, i8* %14)
%19 = call i32 @free(i8* %13)
br label %62
20: ; preds = %12
%21 = call i8* @str_concatn(i8* %13, i8* %14, i8* %15)
%22 = call i32 @free(i8* %13)
%23 = getelementptr inbounds i8, i8* %15, i64 1
%24 = call i8* @str_find(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %62, label %26
26: ; preds = %20
store i8 0, i8* %24
%27 = getelementptr inbounds i8, i8* %24, i64 1
%28 = call i64 @pipe(i32* %9)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %58
30: ; preds = %26
%31 = call i32 (...) @fork()
switch i32 %31, label %42 [
i32 -1, label %58
i32 0, label %32
]
32: ; preds = %30
%33 = load i32, i32* %9
%34 = call i32 @close(i32 %33)
%35 = call i32 @close(i32 1)
%36 = load i32, i32* %10
%37 = call i32 @dup(i32 %36)
%38 = load i32, i32* %10
%39 = call i32 @close(i32 %38)
%40 = call i32 @execl(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %23, i32* null)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %30
%43 = load i32, i32* %10
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %49, %42
%46 = phi i8* [ %21, %42 ], [ %52, %49 ]
%47 = load i32, i32* %9
%48 = call i32 @read(i32 %47, i8* %11, i32 255)
switch i32 %48, label %49 [
i32 -1, label %54
i32 0, label %54
]
49: ; preds = %45
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %50
store i8 0, i8* %51
%52 = call i8* @str_concat(i8* %46, i8* %11)
%53 = call i32 @free(i8* %46)
br label %45
54: ; preds = %45, %45
%55 = load i32, i32* %9
%56 = call i32 @close(i32 %55)
%57 = call i32 @waitpid(i32 %31, i32* null, i32 0)
br label %58
58: ; preds = %26, %30, %54
%59 = phi i8* [ %21, %26 ], [ %46, %54 ], [ %21, %30 ]
%60 = load i8, i8* %27
%61 = icmp eq i8 %60, 0
br i1 %61, label %62, label %12
62: ; preds = %58, %20, %1, %17
%63 = phi i8* [ %18, %17 ], [ %4, %1 ], [ %59, %58 ], [ %21, %20 ]
%64 = call i32 @free(i8* %0)
ret i8* %63
}