#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 /*<<< orphan*/ close_or_die(int const);
int /*<<< orphan*/ dup2_or_die(int const, int /*<<< orphan*/);
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
char **split_command(char const *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void execute(const char *cmd, const int rpipe[2], const int wpipe[2]) {
  close_or_die(rpipe[1]);
  close_or_die(wpipe[0]);
  dup2_or_die(rpipe[0], fileno(stdin));
  dup2_or_die(wpipe[1], fileno(stdout));
  char **args = split_command(cmd);
  execvp(args[0], args);
  err(1, "cannot execute %s", args[0]);
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <close_or_die@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <close_or_die@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%esi
call   1070 <dup2_or_die@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1070 <dup2_or_die@plt>
mov    -0x8(%rbp),%rdi
call   1060 <split_command@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <execvp@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
lea    0xe02(%rip),%rsi
call   1040 <err@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x4(%rsi),%edi
call   1050 <close_or_die@plt>
mov    (%r15),%edi
call   1050 <close_or_die@plt>
mov    (%rbx),%ebx
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <dup2_or_die@plt>
mov    0x4(%r15),%ebx
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <dup2_or_die@plt>
mov    %r14,%rdi
call   1060 <split_command@plt>
mov    %rax,%rbx
mov    (%rax),%rdi
mov    %rax,%rsi
call   1080 <execvp@plt>
mov    (%rbx),%rdx
lea    0xe2e(%rip),%rsi
mov    $0x1,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <err@plt>

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
@.str = [18 x i8] c"cannot execute %s\00"
define void @execute(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8**
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%8 = load i32*, i32** %5
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = load i32, i32* %9
%11 = call i32 @close_or_die(i32 %10)
%12 = load i32*, i32** %6
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = call i32 @close_or_die(i32 %14)
%16 = load i32*, i32** %5
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = load i32, i32* %17
%19 = load i32, i32* @stdin
%20 = call i32 @fileno(i32 %19)
%21 = call i32 @dup2_or_die(i32 %18, i32 %20)
%22 = load i32*, i32** %6
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = load i32, i32* @stdout
%26 = call i32 @fileno(i32 %25)
%27 = call i32 @dup2_or_die(i32 %24, i32 %26)
%28 = load i8*, i8** %4
%29 = call i8** @split_command(i8* %28)
store i8** %29, i8*** %7
%30 = load i8**, i8*** %7
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %7
%34 = call i32 @execvp(i8* %32, i8** %33)
%35 = load i8**, i8*** %7
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %37)
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@.str = [18 x i8] c"cannot execute %s\00"
define void @execute(i8* %0, i32* nocapture %1, i32* nocapture %2) {
%4 = getelementptr inbounds i32, i32* %1, i64 1
%5 = load i32, i32* %4
%6 = tail call i32 @close_or_die(i32 %5)
%7 = load i32, i32* %2
%8 = tail call i32 @close_or_die(i32 %7)
%9 = load i32, i32* %1
%10 = load i32, i32* @stdin
%11 = tail call i32 @fileno(i32 %10)
%12 = tail call i32 @dup2_or_die(i32 %9, i32 %11)
%13 = getelementptr inbounds i32, i32* %2, i64 1
%14 = load i32, i32* %13
%15 = load i32, i32* @stdout
%16 = tail call i32 @fileno(i32 %15)
%17 = tail call i32 @dup2_or_die(i32 %14, i32 %16)
%18 = tail call i8** @split_command(i8* %0)
%19 = load i8*, i8** %18
%20 = tail call i32 @execvp(i8* %19, i8** %18)
%21 = load i8*, i8** %18
%22 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %21)
ret void
}