#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ bad_request(int);
int /*<<< orphan*/ cannot_execute(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execl(char const *, char const *, int /*<<< orphan*/ *);
scalar_t__ fork();
int get_line(int, char *, int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ putenv(char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ strcasecmp(char const *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
void execute_cgi(int fd, const char *path, const char *method,
                 const char *query) {
  char buf[1024];
  int numchars = 1;
  int content_length = -1;
  int cgi_output[2];
  int cgi_input[2];
  pid_t pid;
  int status;
  int i;
  char c;
  buf[0] = 'A';
  buf[1] = '\0';
  if (strcasecmp(method, "GET") == 0) {
    while ((numchars > 0) && strcmp("\n", buf))
      numchars = get_line(fd, buf, sizeof(buf));
  } else {
    numchars = get_line(fd, buf, sizeof(buf));
    while ((numchars > 0) && strcmp("\n", buf)) {
      buf[15] = '\0';
      if (strcasecmp(buf, "Content-Length:") == 0)
        content_length = atoi(&buf[16]);
      numchars = get_line(fd, buf, sizeof(buf));
    }
    if (content_length == -1) {
      bad_request(fd);
      return;
    }
  }
  sprintf(buf, "HTTP/1.0 200 OK\r\n");
  send(fd, buf, strlen(buf), 0);
  if (pipe(cgi_input) < 0) {
    cannot_execute(fd);
    return;
  }
  if (pipe(cgi_output) < 0) {
    cannot_execute(fd);
    return;
  }
  if ((pid = fork()) < 0) {
    cannot_execute(fd);
    return;
  } else if (pid == 0) {
    char meth_env[255];
    char query_env[255];
    char length_env[255];
    close(cgi_output[0]);
    close(cgi_input[1]);
    dup2(cgi_output[1], 1);
    dup2(cgi_input[0], 0);
    sprintf(meth_env, "REQUEST_METHOD=%s", meth_env);
    putenv(meth_env);
    if (strcasecmp(method, "GET") == 0) {
      sprintf(query_env, "QUERY_STRING=%s", query_env);
      putenv(query_env);
    } else {
      sprintf(length_env, "CONTENT_LENGTH=%d", content_length);
      putenv(length_env);
    }
    execl(path, path, NULL);
    _exit(0);
  } else {
    close(cgi_output[1]);
    close(cgi_input[0]);
    if (strcasecmp(method, "POST") == 0) {
      for (i = 0; i < content_length; ++i) {
        recv(fd, &c, 1, 0);
        write(cgi_input[1], &c, i);
      }
    }
    while (read(cgi_output[0], &c, 1) > 0)
      send(fd, &c, 1, 0);
    close(cgi_output[0]);
    close(cgi_input[1]);
    waitpid(pid, &status, 0);
  }
}


x86 assembly (clang, -O0):
<execute_cgi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x770,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x1,-0x424(%rbp)
movl   $0xffffffff,-0x428(%rbp)
ff ff ff
movb   $0x41,-0x420(%rbp)
movb   $0x0,-0x41f(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd79(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1307 <execute_cgi+0xc7>
jmp    129b <execute_cgi+0x5b>
xor    %eax,%eax
cmpl   $0x0,-0x424(%rbp)
mov    %al,-0x751(%rbp)
jle    12d0 <execute_cgi+0x90>
lea    -0x420(%rbp),%rsi
lea    0xd66(%rip),%rdi
call   10f0 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x751(%rbp)
mov    -0x751(%rbp),%al
test   $0x1,%al
jne    12e3 <execute_cgi+0xa3>
jmp    1302 <execute_cgi+0xc2>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <get_line@plt>
mov    %eax,-0x424(%rbp)
jmp    129b <execute_cgi+0x5b>
jmp    13e1 <execute_cgi+0x1a1>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <get_line@plt>
mov    %eax,-0x424(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x424(%rbp)
mov    %al,-0x752(%rbp)
jle    1356 <execute_cgi+0x116>
lea    -0x420(%rbp),%rsi
lea    0xce0(%rip),%rdi
call   10f0 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x752(%rbp)
mov    -0x752(%rbp),%al
test   $0x1,%al
jne    1369 <execute_cgi+0x129>
jmp    13c2 <execute_cgi+0x182>
movb   $0x0,-0x411(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xc86(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    13a3 <execute_cgi+0x163>
lea    -0x420(%rbp),%rdi
add    $0x10,%rdi
call   1130 <atoi@plt>
mov    %eax,-0x428(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <get_line@plt>
mov    %eax,-0x424(%rbp)
jmp    1321 <execute_cgi+0xe1>
cmpl   $0xffffffff,-0x428(%rbp)
jne    13dc <execute_cgi+0x19c>
mov    -0x4(%rbp),%edi
call   1100 <bad_request@plt>
jmp    168d <execute_cgi+0x44d>
jmp    13e1 <execute_cgi+0x1a1>
lea    -0x420(%rbp),%rdi
lea    0xc25(%rip),%rsi
mov    $0x0,%al
call   1140 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x764(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x760(%rbp)
lea    -0x420(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x764(%rbp),%edi
mov    -0x760(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
lea    -0x438(%rbp),%rdi
call   10c0 <pipe@plt>
cmp    $0x0,%rax
jge    1452 <execute_cgi+0x212>
mov    -0x4(%rbp),%edi
call   1120 <cannot_execute@plt>
jmp    168d <execute_cgi+0x44d>
lea    -0x430(%rbp),%rdi
call   10c0 <pipe@plt>
cmp    $0x0,%rax
jge    1475 <execute_cgi+0x235>
mov    -0x4(%rbp),%edi
call   1120 <cannot_execute@plt>
jmp    168d <execute_cgi+0x44d>
mov    $0x0,%al
call   1160 <fork@plt>
mov    %rax,-0x440(%rbp)
cmp    $0x0,%rax
jge    149a <execute_cgi+0x25a>
mov    -0x4(%rbp),%edi
call   1120 <cannot_execute@plt>
jmp    168d <execute_cgi+0x44d>
cmpq   $0x0,-0x440(%rbp)
jne    1589 <execute_cgi+0x349>
mov    -0x430(%rbp),%edi
call   10b0 <close@plt>
mov    -0x434(%rbp),%edi
call   10b0 <close@plt>
mov    -0x42c(%rbp),%edi
mov    $0x1,%esi
call   1090 <dup2@plt>
mov    -0x438(%rbp),%edi
xor    %esi,%esi
call   1090 <dup2@plt>
lea    -0x550(%rbp),%rdi
lea    -0x550(%rbp),%rdx
lea    0xb36(%rip),%rsi
mov    $0x0,%al
call   1140 <sprintf@plt>
lea    -0x550(%rbp),%rdi
call   10e0 <putenv@plt>
mov    -0x18(%rbp),%rdi
lea    0xaf2(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    154a <execute_cgi+0x30a>
lea    -0x650(%rbp),%rdi
lea    -0x650(%rbp),%rdx
lea    0xb06(%rip),%rsi
mov    $0x0,%al
call   1140 <sprintf@plt>
lea    -0x650(%rbp),%rdi
call   10e0 <putenv@plt>
jmp    1571 <execute_cgi+0x331>
lea    -0x750(%rbp),%rdi
mov    -0x428(%rbp),%edx
lea    0xaea(%rip),%rsi
mov    $0x0,%al
call   1140 <sprintf@plt>
lea    -0x750(%rbp),%rdi
call   10e0 <putenv@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1150 <execl@plt>
xor    %edi,%edi
call   1050 <_exit@plt>
mov    -0x42c(%rbp),%edi
call   10b0 <close@plt>
mov    -0x438(%rbp),%edi
call   10b0 <close@plt>
mov    -0x18(%rbp),%rdi
lea    0xab0(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    161c <execute_cgi+0x3dc>
movl   $0x0,-0x448(%rbp)
mov    -0x448(%rbp),%eax
cmp    -0x428(%rbp),%eax
jge    1617 <execute_cgi+0x3d7>
mov    -0x4(%rbp),%edi
lea    -0x449(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x434(%rbp),%edi
mov    -0x448(%rbp),%edx
lea    -0x449(%rbp),%rsi
call   1060 <write@plt>
mov    -0x448(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x448(%rbp)
jmp    15c3 <execute_cgi+0x383>
jmp    161c <execute_cgi+0x3dc>
jmp    1621 <execute_cgi+0x3e1>
mov    -0x430(%rbp),%edi
lea    -0x449(%rbp),%rsi
mov    $0x1,%edx
call   10d0 <read@plt>
cmp    $0x0,%rax
jle    165d <execute_cgi+0x41d>
mov    -0x4(%rbp),%edi
lea    -0x449(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
jmp    1621 <execute_cgi+0x3e1>
mov    -0x430(%rbp),%edi
call   10b0 <close@plt>
mov    -0x434(%rbp),%edi
call   10b0 <close@plt>
mov    -0x440(%rbp),%rdi
lea    -0x444(%rbp),%rsi
xor    %edx,%edx
call   1110 <waitpid@plt>
jmp    168d <execute_cgi+0x44d>
add    $0x770,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_cgi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x628,%rsp
mov    %rdx,%r13
mov    %rsi,%r15
mov    %edi,%r12d
movw   $0x41,0x120(%rsp)
lea    0xd95(%rip),%rsi
mov    %rdx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1334 <execute_cgi+0xf4>
lea    0x120(%rsp),%rsi
mov    %r12d,%edi
mov    $0x400,%edx
call   1070 <get_line@plt>
test   %eax,%eax
jle    1327 <execute_cgi+0xe7>
mov    %r13,0x10(%rsp)
mov    %r15,0x18(%rsp)
mov    $0xffffffff,%ebp
lea    0x130(%rsp),%rbx
lea    0xd6d(%rip),%r13
lea    0x120(%rsp),%r14
lea    0xd3e(%rip),%r15
jmp    12e4 <execute_cgi+0xa4>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1070 <get_line@plt>
test   %eax,%eax
jle    1318 <execute_cgi+0xd8>
mov    %r13,%rdi
mov    %r14,%rsi
call   10f0 <strcmp@plt>
test   %rax,%rax
je     1318 <execute_cgi+0xd8>
movb   $0x0,0x12f(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    12d0 <execute_cgi+0x90>
mov    %rbx,%rdi
call   1130 <atoi@plt>
mov    %eax,%ebp
jmp    12d0 <execute_cgi+0x90>
cmp    $0xffffffff,%ebp
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%r13
jne    1374 <execute_cgi+0x134>
mov    %r12d,%edi
call   1100 <bad_request@plt>
jmp    14c4 <execute_cgi+0x284>
lea    0xce9(%rip),%r14
lea    0x120(%rsp),%rbx
mov    $0xffffffff,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10f0 <strcmp@plt>
test   %rax,%rax
je     1374 <execute_cgi+0x134>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <get_line@plt>
test   %eax,%eax
jg     1350 <execute_cgi+0x110>
movups 0xc99(%rip),%xmm0
movaps %xmm0,0x120(%rsp)
movw   $0xa,0x130(%rsp)
lea    0x120(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
lea    0x8(%rsp),%rdi
call   10c0 <pipe@plt>
test   %rax,%rax
js     14bc <execute_cgi+0x27c>
mov    %rsp,%rdi
call   10c0 <pipe@plt>
test   %rax,%rax
js     14bc <execute_cgi+0x27c>
xor    %eax,%eax
call   1160 <fork@plt>
test   %rax,%rax
js     14bc <execute_cgi+0x27c>
je     14d6 <execute_cgi+0x296>
mov    %rax,%r14
mov    0x4(%rsp),%edi
call   10b0 <close@plt>
mov    0x8(%rsp),%edi
call   10b0 <close@plt>
lea    0xc58(%rip),%rsi
mov    %r13,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1447 <execute_cgi+0x207>
test   %ebp,%ebp
jle    1447 <execute_cgi+0x207>
xor    %ebx,%ebx
lea    0x20(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <write@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1420 <execute_cgi+0x1e0>
mov    (%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0x1,%edx
call   10d0 <read@plt>
test   %rax,%rax
jle    1497 <execute_cgi+0x257>
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
mov    (%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   10d0 <read@plt>
test   %rax,%rax
jg     1470 <execute_cgi+0x230>
mov    (%rsp),%edi
call   10b0 <close@plt>
mov    0xc(%rsp),%edi
call   10b0 <close@plt>
lea    0x520(%rsp),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1110 <waitpid@plt>
jmp    14c4 <execute_cgi+0x284>
mov    %r12d,%edi
call   1120 <cannot_execute@plt>
add    $0x628,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%edi
call   10b0 <close@plt>
mov    0xc(%rsp),%edi
call   10b0 <close@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1090 <dup2@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1090 <dup2@plt>
lea    0xb1f(%rip),%rsi
lea    0x520(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1140 <sprintf@plt>
mov    %rbx,%rdi
call   10e0 <putenv@plt>
lea    0xad5(%rip),%rsi
mov    %r13,%rdi
call   1040 <strcasecmp@plt>
lea    0x20(%rsp),%rbx
test   %rax,%rax
jne    1553 <execute_cgi+0x313>
lea    0xaf4(%rip),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1140 <sprintf@plt>
jmp    1566 <execute_cgi+0x326>
lea    0xaee(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1140 <sprintf@plt>
mov    %rbx,%rdi
call   10e0 <putenv@plt>
mov    %r15,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1150 <execl@plt>
xor    %edi,%edi
call   1050 <_exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"GET\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [16 x i8] c"Content-Length:\00"
@.str.3 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.4 = [18 x i8] c"REQUEST_METHOD=%s\00"
@.str.5 = [16 x i8] c"QUERY_STRING=%s\00"
@.str.6 = [18 x i8] c"CONTENT_LENGTH=%d\00"
@.str.7 = [5 x i8] c"POST\00"
define void @execute_cgi(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca [2 x i32]
%13 = alloca [2 x i32]
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8
%18 = alloca [255 x i8]
%19 = alloca [255 x i8]
%20 = alloca [255 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 1, i32* %10
store i32 -1, i32* %11
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
store i8 65, i8* %21
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 1
store i8 0, i8* %22
%23 = load i8*, i8** %7
%24 = call i64 @strcasecmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %41
26: ; preds = %4
br label %27
27: ; preds = %36, %26
%28 = load i32, i32* %10
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%32 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = icmp ne i64 %32, 0
br label %34
34: ; preds = %30, %27
%35 = phi i1 [ false, %27 ], [ %33, %30 ]
br i1 %35, label %36, label %40
36: ; preds = %34
%37 = load i32, i32* %5
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%39 = call i32 @get_line(i32 %37, i8* %38, i32 1024)
store i32 %39, i32* %10
br label %27
40: ; preds = %34
br label %73
41: ; preds = %4
%42 = load i32, i32* %5
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%44 = call i32 @get_line(i32 %42, i8* %43, i32 1024)
store i32 %44, i32* %10
br label %45
45: ; preds = %62, %41
%46 = load i32, i32* %10
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%50 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %49)
%51 = icmp ne i64 %50, 0
br label %52
52: ; preds = %48, %45
%53 = phi i1 [ false, %45 ], [ %51, %48 ]
br i1 %53, label %54, label %66
54: ; preds = %52
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 15
store i8 0, i8* %55
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%57 = call i64 @strcasecmp(i8* %56, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 16
%61 = call i32 @atoi(i8* %60)
store i32 %61, i32* %11
br label %62
62: ; preds = %59, %54
%63 = load i32, i32* %5
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%65 = call i32 @get_line(i32 %63, i8* %64, i32 1024)
store i32 %65, i32* %10
br label %45
66: ; preds = %52
%67 = load i32, i32* %11
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i32, i32* %5
%71 = call i32 @bad_request(i32 %70)
br label %186
72: ; preds = %66
br label %73
73: ; preds = %72, %40
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%75 = call i32 (i8*, i8*, ...) @sprintf(i8* %74, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%76 = load i32, i32* %5
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%79 = call i32 @strlen(i8* %78)
%80 = call i32 @send(i32 %76, i8* %77, i32 %79, i32 0)
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%82 = call i64 @pipe(i32* %81)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %73
%85 = load i32, i32* %5
%86 = call i32 @cannot_execute(i32 %85)
br label %186
87: ; preds = %73
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%89 = call i64 @pipe(i32* %88)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %87
%92 = load i32, i32* %5
%93 = call i32 @cannot_execute(i32 %92)
br label %186
94: ; preds = %87
%95 = call i64 (...) @fork()
store i64 %95, i64* %14
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %94
%98 = load i32, i32* %5
%99 = call i32 @cannot_execute(i32 %98)
br label %186
100: ; preds = %94
%101 = load i64, i64* %14
%102 = icmp eq i64 %101, 0
br i1 %102, label %103, label %141
103: ; preds = %100
%104 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%105 = load i32, i32* %104
%106 = call i32 @close(i32 %105)
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%108 = load i32, i32* %107
%109 = call i32 @close(i32 %108)
%110 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%111 = load i32, i32* %110
%112 = call i32 @dup2(i32 %111, i32 1)
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%114 = load i32, i32* %113
%115 = call i32 @dup2(i32 %114, i32 0)
%116 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i64 0, i64 0
%117 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i64 0, i64 0
%118 = call i32 (i8*, i8*, ...) @sprintf(i8* %116, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %117)
%119 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i64 0, i64 0
%120 = call i32 @putenv(i8* %119)
%121 = load i8*, i8** %7
%122 = call i64 @strcasecmp(i8* %121, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%123 = icmp eq i64 %122, 0
br i1 %123, label %124, label %130
124: ; preds = %103
%125 = getelementptr inbounds [255 x i8], [255 x i8]* %19, i64 0, i64 0
%126 = getelementptr inbounds [255 x i8], [255 x i8]* %19, i64 0, i64 0
%127 = call i32 (i8*, i8*, ...) @sprintf(i8* %125, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %126)
%128 = getelementptr inbounds [255 x i8], [255 x i8]* %19, i64 0, i64 0
%129 = call i32 @putenv(i8* %128)
br label %136
130: ; preds = %103
%131 = getelementptr inbounds [255 x i8], [255 x i8]* %20, i64 0, i64 0
%132 = load i32, i32* %11
%133 = call i32 (i8*, i8*, ...) @sprintf(i8* %131, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %132)
%134 = getelementptr inbounds [255 x i8], [255 x i8]* %20, i64 0, i64 0
%135 = call i32 @putenv(i8* %134)
br label %136
136: ; preds = %130, %124
%137 = load i8*, i8** %6
%138 = load i8*, i8** %6
%139 = call i32 @execl(i8* %137, i8* %138, i32* null)
%140 = call i32 @_exit(i32 0)
unreachable
141: ; preds = %100
%142 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%143 = load i32, i32* %142
%144 = call i32 @close(i32 %143)
%145 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%146 = load i32, i32* %145
%147 = call i32 @close(i32 %146)
%148 = load i8*, i8** %7
%149 = call i64 @strcasecmp(i8* %148, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%150 = icmp eq i64 %149, 0
br i1 %150, label %151, label %167
151: ; preds = %141
store i32 0, i32* %16
br label %152
152: ; preds = %163, %151
%153 = load i32, i32* %16
%154 = load i32, i32* %11
%155 = icmp slt i32 %153, %154
br i1 %155, label %156, label %166
156: ; preds = %152
%157 = load i32, i32* %5
%158 = call i32 @recv(i32 %157, i8* %17, i32 1, i32 0)
%159 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%160 = load i32, i32* %159
%161 = load i32, i32* %16
%162 = call i32 @write(i32 %160, i8* %17, i32 %161)
br label %163
163: ; preds = %156
%164 = load i32, i32* %16
%165 = add nsw i32 %164, 1
store i32 %165, i32* %16
br label %152
166: ; preds = %152
br label %167
167: ; preds = %166, %141
br label %168
168: ; preds = %173, %167
%169 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%170 = load i32, i32* %169
%171 = call i64 @read(i32 %170, i8* %17, i32 1)
%172 = icmp sgt i64 %171, 0
br i1 %172, label %173, label %176
173: ; preds = %168
%174 = load i32, i32* %5
%175 = call i32 @send(i32 %174, i8* %17, i32 1, i32 0)
br label %168
176: ; preds = %168
%177 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%178 = load i32, i32* %177
%179 = call i32 @close(i32 %178)
%180 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%181 = load i32, i32* %180
%182 = call i32 @close(i32 %181)
%183 = load i64, i64* %14
%184 = call i32 @waitpid(i64 %183, i32* %15, i32 0)
br label %185
185: ; preds = %176
br label %186
186: ; preds = %69, %84, %91, %97, %185
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"GET\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [16 x i8] c"Content-Length:\00"
@.str.3 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.4 = [18 x i8] c"REQUEST_METHOD=%s\00"
@.str.5 = [16 x i8] c"QUERY_STRING=%s\00"
@.str.6 = [18 x i8] c"CONTENT_LENGTH=%d\00"
@.str.7 = [5 x i8] c"POST\00"
define void @execute_cgi(i32 %0, i8* %1, i8* nocapture %2, i8* nocapture readnone %3) {
%5 = alloca [1024 x i8]
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i32
%9 = alloca i8
%10 = alloca [255 x i8]
%11 = alloca [255 x i8]
%12 = alloca [255 x i8]
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = bitcast [2 x i32]* %6 to i8*
%15 = bitcast [2 x i32]* %7 to i8*
%16 = bitcast i32* %8 to i8*
store i8 65, i8* %13
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 1
store i8 0, i8* %17
%18 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %4, %23
%21 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%22 = icmp eq i64 %21, 0
br i1 %22, label %50, label %23
23: ; preds = %20
%24 = call i32 @get_line(i32 %0, i8* %13, i32 1024)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %20, label %50
26: ; preds = %4
%27 = call i32 @get_line(i32 %0, i8* %13, i32 1024)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %48
29: ; preds = %26
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 15
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 16
br label %32
32: ; preds = %29, %41
%33 = phi i32 [ -1, %29 ], [ %42, %41 ]
%34 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%35 = icmp eq i64 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %32
store i8 0, i8* %30
%37 = call i64 @strcasecmp(i8* %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @atoi(i8* %31)
br label %41
41: ; preds = %39, %36
%42 = phi i32 [ %40, %39 ], [ %33, %36 ]
%43 = call i32 @get_line(i32 %0, i8* %13, i32 1024)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %32, label %45
45: ; preds = %32, %41
%46 = phi i32 [ %33, %32 ], [ %42, %41 ]
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %26, %45
%49 = call i32 @bad_request(i32 %0)
br label %134
50: ; preds = %20, %23, %45
%51 = phi i32 [ %46, %45 ], [ -1, %23 ], [ -1, %20 ]
%52 = call i32 @strlen(i8* %13)
%53 = call i32 @send(i32 %0, i8* %13, i32 %52, i32 0)
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%55 = call i64 @pipe(i32* %54)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %50
%58 = call i32 @cannot_execute(i32 %0)
br label %134
59: ; preds = %50
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%61 = call i64 @pipe(i32* %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 @cannot_execute(i32 %0)
br label %134
65: ; preds = %59
%66 = call i64 (...) @fork()
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = call i32 @cannot_execute(i32 %0)
br label %134
70: ; preds = %65
%71 = icmp eq i64 %66, 0
br i1 %71, label %72, label %99
72: ; preds = %70
%73 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%74 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%75 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%76 = load i32, i32* %60
%77 = call i32 @close(i32 %76)
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%82 = load i32, i32* %81
%83 = call i32 @dup2(i32 %82, i32 1)
%84 = load i32, i32* %54
%85 = call i32 @dup2(i32 %84, i32 0)
%86 = call i32 (i8*, i8*, ...) @sprintf(i8* %73, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %73)
%87 = call i32 @putenv(i8* %73)
%88 = call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %72
%91 = call i32 (i8*, i8*, ...) @sprintf(i8* %74, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %74)
br label %94
92: ; preds = %72
%93 = call i32 (i8*, i8*, ...) @sprintf(i8* %75, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %51)
br label %94
94: ; preds = %92, %90
%95 = phi i8* [ %75, %92 ], [ %74, %90 ]
%96 = call i32 @putenv(i8* %95)
%97 = call i32 @execl(i8* %1, i8* %1, i32* null)
%98 = call i32 @_exit(i32 0)
unreachable
99: ; preds = %70
%100 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%101 = load i32, i32* %100
%102 = call i32 @close(i32 %101)
%103 = load i32, i32* %54
%104 = call i32 @close(i32 %103)
%105 = call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
%107 = icmp sgt i32 %51, 0
%108 = select i1 %106, i1 %107, i1 false
br i1 %108, label %109, label %118
109: ; preds = %99
%110 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
br label %111
111: ; preds = %109, %111
%112 = phi i32 [ 0, %109 ], [ %116, %111 ]
%113 = call i32 @recv(i32 %0, i8* %9, i32 1, i32 0)
%114 = load i32, i32* %110
%115 = call i32 @write(i32 %114, i8* %9, i32 %112)
%116 = add nuw nsw i32 %112, 1
%117 = icmp eq i32 %116, %51
br i1 %117, label %118, label %111
118: ; preds = %111, %99
%119 = load i32, i32* %60
%120 = call i64 @read(i32 %119, i8* %9, i32 1)
%121 = icmp sgt i64 %120, 0
br i1 %121, label %122, label %127
122: ; preds = %118, %122
%123 = call i32 @send(i32 %0, i8* %9, i32 1, i32 0)
%124 = load i32, i32* %60
%125 = call i64 @read(i32 %124, i8* %9, i32 1)
%126 = icmp sgt i64 %125, 0
br i1 %126, label %122, label %127
127: ; preds = %122, %118
%128 = load i32, i32* %60
%129 = call i32 @close(i32 %128)
%130 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%131 = load i32, i32* %130
%132 = call i32 @close(i32 %131)
%133 = call i32 @waitpid(i64 %66, i32* %8, i32 0)
br label %134
134: ; preds = %127, %68, %63, %57, %48
ret void
}