#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*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int cnc_ctrl_ipc_init();
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int execv(char *, char **);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ printf(char *, int, char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (0 == strncmp(getenv("QUERY_STRING"), "run", strlen("run"))) {
    char *arg[] = {"cnc_control", "test", NULL};
    int ipc_fd = cnc_ctrl_ipc_init();
    printf("HTTP/1.1 %d %s\r\n"
           "Content-Type: %s\r\n"
           "Connection: close\r\n"
           "\r\n",
           200, "OK", "text/plain");
    dup2(ipc_fd, STDOUT_FILENO);
    close(STDIN_FILENO);
    dup2(ipc_fd, STDERR_FILENO);
    return execv(arg[0], arg);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,-0x38(%rbp)
lea    0xe61(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%edx
lea    0xe50(%rip),%rsi
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    125f <main+0xdf>
mov    0x2c19(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c16(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c13(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1090 <cnc_ctrl_ipc_init@plt>
mov    %eax,-0x34(%rbp)
lea    0xe20(%rip),%rdi
mov    $0xc8,%esi
lea    0xe4c(%rip),%rdx
lea    0xe48(%rip),%rcx
call   1070 <printf@plt>
mov    -0x34(%rbp),%edi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1080 <close@plt>
mov    -0x34(%rbp),%edi
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10a0 <execv@plt>
mov    %eax,-0x4(%rbp)
jmp    1266 <main+0xe6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe72(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%ebx
lea    0xe71(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1236 <main+0xb6>
mov    0x2c3f(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2c23(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1090 <cnc_ctrl_ipc_init@plt>
mov    %eax,%ebx
lea    0xe41(%rip),%rdi
lea    0xe72(%rip),%rdx
lea    0xe6e(%rip),%rcx
mov    $0xc8,%esi
call   1070 <printf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <dup2@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1080 <close@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <dup2@plt>
lea    0xde3(%rip),%rdi
mov    %rsp,%rsi
call   10a0 <execv@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.1 = [4 x i8] c"run\00"
@.str.2 = [12 x i8] c"cnc_control\00"
@.str.3 = [5 x i8] c"test\00"
@__const.main.arg = [3 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [56 x i8] c"HTTP/1.1 %d %s\0D\0AContent-Type: %s\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.5 = [3 x i8] c"OK\00"
@.str.6 = [11 x i8] c"text/plain\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i8*]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = call i64 @strncmp(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = icmp eq i64 0, %10
br i1 %11, label %12, label %28
12: ; preds = %2
%13 = bitcast [3 x i8*]* %6 to i8*
%14 = call i32 (...) @cnc_ctrl_ipc_init()
store i32 %14, i32* %7
%15 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%16 = load i32, i32* %7
%17 = load i32, i32* @STDOUT_FILENO
%18 = call i32 @dup2(i32 %16, i32 %17)
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %7
%22 = load i32, i32* @STDERR_FILENO
%23 = call i32 @dup2(i32 %21, i32 %22)
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%25 = load i8*, i8** %24
%26 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%27 = call i32 @execv(i8* %25, i8** %26)
store i32 %27, i32* %3
br label %29
28: ; preds = %2
store i32 0, i32* %3
br label %29
29: ; preds = %28, %12
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.1 = [4 x i8] c"run\00"
@.str.2 = [12 x i8] c"cnc_control\00"
@.str.3 = [5 x i8] c"test\00"
@__const.main.arg = [3 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [56 x i8] c"HTTP/1.1 %d %s\0D\0AContent-Type: %s\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.5 = [3 x i8] c"OK\00"
@.str.6 = [11 x i8] c"text/plain\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i8*]
%4 = tail call i32 @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i64 @strncmp(i32 %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = bitcast [3 x i8*]* %3 to i8*
%10 = tail call i32 (...) @cnc_ctrl_ipc_init()
%11 = tail call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%12 = load i32, i32* @STDOUT_FILENO
%13 = tail call i32 @dup2(i32 %10, i32 %12)
%14 = load i32, i32* @STDIN_FILENO
%15 = tail call i32 @close(i32 %14)
%16 = load i32, i32* @STDERR_FILENO
%17 = tail call i32 @dup2(i32 %10, i32 %16)
%18 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%19 = call i32 @execv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %18)
br label %20
20: ; preds = %2, %8
%21 = phi i32 [ %19, %8 ], [ 0, %2 ]
ret i32 %21
}