#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *const, char *const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *fd2str(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *const);
int pipe(int *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
char *_backtick(char *const argv[]) {
  int filedes[2];
  pid_t pid;
  int status;
  char *buf = NULL;
  if (pipe(filedes) == -1) {
    perror(argv[0]);
    return NULL;
  }
  switch (pid = fork()) {
  case -1:
    return NULL;
  case 0:
    close(filedes[0]);
    dup2(filedes[1], 1);
    close(filedes[1]);
    execvp(argv[0], argv);
    exit(errno);
    break;
  default:
    close(filedes[1]);
    buf = fd2str(filedes[0]);
    waitpid(pid, &status, 0);
    break;
  }
  return buf;
}


x86 assembly (clang, -O0):
<_backtick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11cf <_backtick+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    126e <_backtick+0xde>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %eax,-0x1c(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0xffffffff,%eax
je     11fc <_backtick+0x6c>
jmp    11ec <_backtick+0x5c>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     1209 <_backtick+0x79>
jmp    1244 <_backtick+0xb4>
movq   $0x0,-0x8(%rbp)
jmp    126e <_backtick+0xde>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <execvp@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <fd2str@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_backtick>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0x4(%rsp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
je     11ed <_backtick+0x5d>
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     11e1 <_backtick+0x51>
mov    %eax,%ebp
test   %eax,%eax
je     11f9 <_backtick+0x69>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1060 <fd2str@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%r14),%rdi
call   1080 <perror@plt>
xor    %ebx,%ebx
jmp    11e1 <_backtick+0x51>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1090 <execvp@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
define i8* @_backtick(i8** %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca [2 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8** %0, i8*** %3
store i8* null, i8** %7
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i8**, i8*** %3
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @perror(i8* %14)
store i8* null, i8** %2
br label %47
16: ; preds = %1
%17 = call i32 (...) @fork()
store i32 %17, i32* %5
switch i32 %17, label %36 [
i32 -1, label %18
i32 0, label %19
]
18: ; preds = %16
store i8* null, i8** %2
br label %47
19: ; preds = %16
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @dup2(i32 %24, i32 1)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = load i8**, i8*** %3
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %3
%33 = call i32 @execvp(i8* %31, i8** %32)
%34 = load i32, i32* @errno
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %16
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i8* @fd2str(i32 %41)
store i8* %42, i8** %7
%43 = load i32, i32* %5
%44 = call i32 @waitpid(i32 %43, i32* %6, i32 0)
br label %45
45: ; preds = %36
%46 = load i8*, i8** %7
store i8* %46, i8** %2
br label %47
47: ; preds = %45, %18, %11
%48 = load i8*, i8** %2
ret i8* %48
}

LLVM IR (-O2):
@errno = global i32 0
define i8* @_backtick(i8** %0) {
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = bitcast [2 x i32]* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %0
%11 = call i32 @perror(i8* %10)
br label %33
12: ; preds = %1
%13 = call i32 (...) @fork()
switch i32 %13, label %26 [
i32 -1, label %33
i32 0, label %14
]
14: ; preds = %12
%15 = load i32, i32* %6
%16 = call i32 @close(i32 %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 @dup2(i32 %18, i32 1)
%20 = load i32, i32* %17
%21 = call i32 @close(i32 %20)
%22 = load i8*, i8** %0
%23 = call i32 @execvp(i8* %22, i8** %0)
%24 = load i32, i32* @errno
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %12
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %6
%31 = call i8* @fd2str(i32 %30)
%32 = call i32 @waitpid(i32 %13, i32* %3, i32 0)
br label %33
33: ; preds = %12, %26, %9
%34 = phi i8* [ null, %9 ], [ %31, %26 ], [ null, %12 ]
ret i8* %34
}