#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_FAILURE;
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int pipefd[2];
  pipe(pipefd);
  printf("%d %d\n", pipefd[0], pipefd[1]);
  char *newargv[] = {NULL, "-f", "/home/olekz/soc/test_conn.R", NULL};
  char *newenviron[] = {NULL};
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <file-to-exec>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  newargv[0] = argv[1];
  execve(argv[1], newargv, newenviron);
  perror("execve");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
mov    0x2c48(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c45(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c42(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c3f(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     1211 <main+0xa1>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe28(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1060 <execve@plt>
lea    0xe07(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
call   1040 <pipe@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
movaps 0x2c73(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c57(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
cmp    $0x2,%ebp
jne    11d2 <main+0x72>
mov    0x8(%rbx),%rdi
mov    %rdi,0x10(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <execve@plt>
lea    0xe75(%rip),%rdi
call   1070 <perror@plt>
jmp    11ea <main+0x8a>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe41(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%d %d\0A\00"
@.str.1 = [3 x i8] c"-f\00"
@.str.2 = [28 x i8] c"/home/olekz/soc/test_conn.R\00"
@__const.main.newargv = [4 x i8*] [i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.3 = [26 x i8] c"Usage: %s <file-to-exec>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [7 x i8] c"execve\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [4 x i8*]
%8 = alloca [1 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14)
%16 = bitcast [4 x i8*]* %7 to i8*
%17 = bitcast [1 x i8*]* %8 to i8*
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %28
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 0
store i8* %31, i8** %32
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 0
%37 = getelementptr inbounds [1 x i8*], [1 x i8*]* %8, i64 0, i64 0
%38 = call i32 @execve(i8* %35, i8** %36, i8** %37)
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %d\0A\00"
@.str.1 = [3 x i8] c"-f\00"
@.str.2 = [28 x i8] c"/home/olekz/soc/test_conn.R\00"
@__const.main.newargv = [4 x i8*] [i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.3 = [26 x i8] c"Usage: %s <file-to-exec>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [7 x i8] c"execve\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [4 x i8*]
%5 = alloca [1 x i8*]
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = load i32, i32* %7
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%11 = load i32, i32* %10
%12 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11)
%13 = bitcast [4 x i8*]* %4 to i8*
%14 = bitcast [1 x i8*]* %5 to i8*
%15 = bitcast [1 x i8*]* %5 to i64*
store i64 0, i64* %15
%16 = icmp eq i32 %0, 2
br i1 %16, label %23, label %17
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
store i8* %25, i8** %26
%27 = getelementptr inbounds [1 x i8*], [1 x i8*]* %5, i64 0, i64 0
%28 = call i32 @execve(i8* %25, i8** %26, i8** %27)
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
}