#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*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int *);
int /*<<< orphan*/ unsetenv(char *);
int main(int argc, char *argv[]) {
  int fds[2];
  char buf[1024];
  socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
  snprintf(buf, 1022, "%d", fds[1]);
  setenv("NX_SERVERFD", buf, 1);
  snprintf(buf, 1022, "%d", fds[0]);
  setenv("NX_COMMFD", buf, 1);
  unsetenv("NX_TRUSTED_USER");
  argv++;
  execv(argv[0], argv);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rcx
xor    %edx,%edx
call   1050 <socketpair@plt>
lea    -0x420(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x3fe,%esi
lea    0xe6b(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x420(%rbp),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%ecx
mov    $0x3fe,%esi
lea    0xe38(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x420(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    0xe2d(%rip),%rdi
call   1060 <unsetenv@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execv@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%rbx
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   1050 <socketpair@plt>
mov    0xc(%rsp),%ecx
lea    0xe78(%rip),%r14
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x3fe,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0xe5f(%rip),%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    0x8(%rsp),%ecx
mov    %r15,%rdi
mov    $0x3fe,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0xe43(%rip),%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    0xe39(%rip),%rdi
call   1060 <unsetenv@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1070 <execv@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [12 x i8] c"NX_SERVERFD\00"
@.str.2 = [10 x i8] c"NX_COMMFD\00"
@.str.3 = [16 x i8] c"NX_TRUSTED_USER\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [2 x i32]
%6 = alloca [1024 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%10 = call i32 @socketpair(i32 %7, i32 %8, i32 0, i32* %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @snprintf(i8* %11, i32 1022, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = call i32 @setenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 1)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%19 = load i32, i32* %18
%20 = call i32 @snprintf(i8* %17, i32 1022, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = call i32 @setenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 1)
%23 = call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%24 = load i8**, i8*** %4
%25 = getelementptr inbounds i8*, i8** %24, i32 1
store i8** %25, i8*** %4
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %4
%30 = call i32 @execv(i8* %28, i8** %29)
ret i32 0
}

LLVM IR (-O2):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [12 x i8] c"NX_SERVERFD\00"
@.str.2 = [10 x i8] c"NX_COMMFD\00"
@.str.3 = [16 x i8] c"NX_TRUSTED_USER\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i32]
%4 = alloca [1024 x i8]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @socketpair(i32 %7, i32 %8, i32 0, i32* %9)
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @snprintf(i8* %6, i32 1022, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @setenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 1)
%15 = load i32, i32* %9
%16 = call i32 @snprintf(i8* %6, i32 1022, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @setenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 1)
%18 = call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @execv(i8* %20, i8** %19)
ret i32 0
}