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

/* Variables and functions */
int execv(char *, char **);
int pipe(int *);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int strlen(char *);
int main(int argc, char *argv[]) {
  int pipe_fds[2];
  char ipc_var[(strlen("CNCIPC"
                       "X"
                       "=DDD"))];
  char *cmd[] = {"httpd", "http_admin", NULL};
  int err;
  if ((err = pipe(pipe_fds))) {
    return err;
  }
  snprintf(ipc_var, sizeof(ipc_var),
           "CNCIPC"
           "I"
           "=%d",
           pipe_fds[0]);
  putenv(ipc_var);
  snprintf(ipc_var, sizeof(ipc_var),
           "CNCIPC"
           "O"
           "=%d",
           pipe_fds[1]);
  putenv(ipc_var);
  return execv("httpd", cmd);
}


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)
lea    0xe93(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2c5e(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c5b(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c58(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
je     11e3 <main+0x93>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    1241 <main+0xf1>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%ecx
lea    0xe26(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x50(%rbp),%rdi
call   1060 <putenv@plt>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%esi
mov    -0x14(%rbp),%ecx
lea    0xe0f(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x50(%rbp),%rdi
call   1060 <putenv@plt>
lea    -0x40(%rbp),%rsi
lea    0xdda(%rip),%rdi
call   1070 <execv@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xe9c(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %rsp,%r15
mov    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2c87(%rip),%rax
mov    %rax,-0x30(%rbp)
movaps 0x2c6c(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <pipe@plt>
test   %eax,%eax
jne    11ef <main+0x9f>
mov    -0x20(%rbp),%ecx
lea    0xe6e(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <putenv@plt>
mov    -0x1c(%rbp),%ecx
lea    0xe5c(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <putenv@plt>
lea    0xe26(%rip),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <execv@plt>
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"CNCIPCX=DDD\00"
@.str.1 = [6 x i8] c"httpd\00"
@.str.2 = [11 x i8] c"http_admin\00"
@__const.main.cmd = [3 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [11 x i8] c"CNCIPCI=%d\00"
@.str.4 = [11 x i8] c"CNCIPCO=%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [3 x i8*]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
%16 = bitcast [3 x i8*]* %9 to i8*
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%18 = call i32 @pipe(i32* %17)
store i32 %18, i32* %10
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = load i32, i32* %10
store i32 %21, i32* %3
store i32 1, i32* %11
br label %35
22: ; preds = %2
%23 = trunc i64 %13 to i32
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @snprintf(i8* %15, i32 %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = call i32 @putenv(i8* %15)
%28 = trunc i64 %13 to i32
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @snprintf(i8* %15, i32 %28, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = call i32 @putenv(i8* %15)
%33 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 0
%34 = call i32 @execv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %33)
store i32 %34, i32* %3
store i32 1, i32* %11
br label %35
35: ; preds = %22, %20
%36 = load i8*, i8** %7
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [12 x i8] c"CNCIPCX=DDD\00"
@.str.1 = [6 x i8] c"httpd\00"
@.str.2 = [11 x i8] c"http_admin\00"
@__const.main.cmd = [3 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [11 x i8] c"CNCIPCI=%d\00"
@.str.4 = [11 x i8] c"CNCIPCO=%d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [3 x i8*]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = bitcast [3 x i8*]* %4 to i8*
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i32, i32* %11
%16 = call i32 @snprintf(i8* %9, i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = call i32 @putenv(i8* %9)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @snprintf(i8* %9, i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = call i32 @putenv(i8* %9)
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%23 = call i32 @execv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %22)
br label %24
24: ; preds = %2, %14
%25 = phi i32 [ %23, %14 ], [ %12, %2 ]
ret i32 %25
}