#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*/ _exit(int);
int close(int);
int errno;
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int pipe(int *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[], char *envp[]) {
  int res;
  int pipes[2];
  if (argc > 2) {
    fprintf(stderr, "Usage: %s <program> [<arg> ...]\n", argv[0]);
    _exit(1);
  }
  res = pipe(pipes);
  if (res == -1) {
    fprintf(stderr, "%s: can't create pipe. Errno=%d (%s).\n", argv[0], errno,
            strerror(errno));
    _exit(1);
  }
  res = close(pipes[0]);
  if (res == -1) {
    fprintf(stderr, "%s: can't close fd. Errno=%d (%s).\n", argv[0], errno,
            strerror(errno));
    _exit(1);
  }
  write(pipes[1], "", 1);
  execve(argv[1], &argv[1], envp);
  fprintf(stderr, "%s: can't execve '%s'. Errno=%d (%s).\n", argv[0], argv[1],
          errno, strerror(errno));
  _exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11bc <main+0x4c>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
lea    -0x24(%rbp),%rdi
call   1060 <pipe@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1228 <main+0xb8>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%ecx
mov    %rax,%r8
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1293 <main+0x123>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%ecx
mov    %rax,%r8
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x20(%rbp),%edi
lea    0xdf5(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
mov    -0x18(%rbp),%rdx
call   1070 <execve@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%r8d
mov    %rax,%r9
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jl     11a3 <main+0x33>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe6e(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    %rdx,%r14
mov    %rsp,%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11d8 <main+0x68>
mov    0x2e26(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%r14
mov    0x2e12(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xe4b(%rip),%rsi
jmp    1208 <main+0x98>
mov    (%rsp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1223 <main+0xb3>
mov    0x2df4(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%r14
mov    0x2de0(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xe40(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    0x4(%rsp),%edi
lea    0xe64(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
lea    0x8(%rbx),%rsi
mov    0x8(%rbx),%rdi
mov    %r14,%rdx
call   1070 <execve@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%r14
mov    0x8(%rbx),%r15
mov    0x2d79(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xdfd(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %ebx,%r8d
mov    %rax,%r9
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s <program> [<arg> ...]\0A\00"
@.str.1 = [39 x i8] c"%s: can't create pipe. Errno=%d (%s).\0A\00"
@errno = global i32 0
@.str.2 = [36 x i8] c"%s: can't close fd. Errno=%d (%s).\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [39 x i8] c"%s: can't execve '%s'. Errno=%d (%s).\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca [2 x i32]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %6
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @_exit(i32 1)
unreachable
19: ; preds = %3
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%21 = call i32 @pipe(i32* %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %34
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %6
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = load i32, i32* @errno
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 %29, i8* %31)
%33 = call i32 @_exit(i32 1)
unreachable
34: ; preds = %19
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %50
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %6
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = load i32, i32* @errno
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %44, i32 %45, i8* %47)
%49 = call i32 @_exit(i32 1)
unreachable
50: ; preds = %34
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%52 = load i32, i32* %51
%53 = call i32 @write(i32 %52, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
%54 = load i8**, i8*** %6
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %6
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8**, i8*** %7
%60 = call i32 @execve(i8* %56, i8** %58, i8** %59)
%61 = load i32, i32* @stderr
%62 = load i8**, i8*** %6
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = load i8**, i8*** %6
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = load i32, i32* @errno
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %64, i8* %67, i32 %68, i8* %70)
%72 = call i32 @_exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s <program> [<arg> ...]\0A\00"
@.str.1 = [39 x i8] c"%s: can't create pipe. Errno=%d (%s).\0A\00"
@errno = global i32 0
@.str.2 = [36 x i8] c"%s: can't close fd. Errno=%d (%s).\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [39 x i8] c"%s: can't execve '%s'. Errno=%d (%s).\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %4 to i8*
%6 = icmp sgt i32 %0, 2
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @_exit(i32 1)
unreachable
12: ; preds = %3
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %19, i8* %20)
%22 = call i32 @_exit(i32 1)
unreachable
23: ; preds = %12
%24 = load i32, i32* %13
%25 = call i32 @close(i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %1
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 %30, i8* %31)
%33 = call i32 @_exit(i32 1)
unreachable
34: ; preds = %23
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @write(i32 %36, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
%38 = getelementptr inbounds i8*, i8** %1, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @execve(i8* %39, i8** %38, i8** %2)
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %1
%43 = load i8*, i8** %38
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* %43, i32 %44, i8* %45)
%47 = call i32 @_exit(i32 1)
unreachable
}