#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 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 *, void *);
int /*<<< orphan*/ exit(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 client, const char *path, const char *method,
                 const char *query_string) {
  char buf[1024];
  int cgi_output[2];
  int cgi_input[2];
  pid_t pid;
  int status;
  int i;
  char c;
  int numchars = 1;
  int content_length = -1;
  buf[0] = 'A';
  buf[1] = '\0';
  if (strcasecmp(method, "GET") == 0)
    while ((numchars > 0) && strcmp("\n", buf))
      numchars = get_line(client, buf, sizeof(buf));
  else {
    numchars = get_line(client, 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(client, buf, sizeof(buf));
    }
    if (content_length == -1) {
      bad_request(client);
      return;
    }
  }
  sprintf(buf, "HTTP/1.0 200 OK\r\n");
  send(client, buf, strlen(buf), 0);
  if (pipe(cgi_output) < 0) {
    cannot_execute(client);
    return;
  }
  if (pipe(cgi_input) < 0) {
    cannot_execute(client);
    return;
  }
  if ((pid = fork()) < 0) {
    cannot_execute(client);
    return;
  }
  if (pid == 0) {
    char meth_env[255];
    char query_env[255];
    char length_env[255];
    dup2(cgi_output[1], 1);
    dup2(cgi_input[0], 0);
    close(cgi_output[0]);
    close(cgi_input[1]);
    sprintf(meth_env, "REQUEST_METHOD=%s", method);
    putenv(meth_env);
    if (strcasecmp(method, "GET") == 0) {
      sprintf(query_env, "QUERY_STRING=%s", query_string);
      putenv(query_env);
    } else {
      sprintf(length_env, "CONTENT_LENGTH=%d", content_length);
      putenv(length_env);
    }
    execl(path, path, ((void *)0));
    exit(0);
  } else {
    close(cgi_output[1]);
    close(cgi_input[0]);
    if (strcasecmp(method, "POST") == 0)
      for (i = 0; i < content_length; i++) {
        recv(client, &c, 1, 0);
        write(cgi_input[1], &c, 1);
      }
    while (read(cgi_output[0], &c, 1) > 0)
      send(client, &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,-0x448(%rbp)
movl   $0xffffffff,-0x44c(%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,-0x448(%rbp)
mov    %al,-0x751(%rbp)
jle    12d0 <execute_cgi+0x90>
lea    -0x420(%rbp),%rsi
lea    0xd66(%rip),%rdi
call   10e0 <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   1060 <get_line@plt>
mov    %eax,-0x448(%rbp)
jmp    129b <execute_cgi+0x5b>
jmp    13e1 <execute_cgi+0x1a1>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <get_line@plt>
mov    %eax,-0x448(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x448(%rbp)
mov    %al,-0x752(%rbp)
jle    1356 <execute_cgi+0x116>
lea    -0x420(%rbp),%rsi
lea    0xce0(%rip),%rdi
call   10e0 <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   1120 <atoi@plt>
mov    %eax,-0x44c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <get_line@plt>
mov    %eax,-0x448(%rbp)
jmp    1321 <execute_cgi+0xe1>
cmpl   $0xffffffff,-0x44c(%rbp)
jne    13dc <execute_cgi+0x19c>
mov    -0x4(%rbp),%edi
call   10f0 <bad_request@plt>
jmp    1681 <execute_cgi+0x441>
jmp    13e1 <execute_cgi+0x1a1>
lea    -0x420(%rbp),%rdi
lea    0xc25(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x764(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x760(%rbp)
lea    -0x420(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x764(%rbp),%edi
mov    -0x760(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
lea    -0x428(%rbp),%rdi
call   10b0 <pipe@plt>
cmp    $0x0,%rax
jge    1452 <execute_cgi+0x212>
mov    -0x4(%rbp),%edi
call   1110 <cannot_execute@plt>
jmp    1681 <execute_cgi+0x441>
lea    -0x430(%rbp),%rdi
call   10b0 <pipe@plt>
cmp    $0x0,%rax
jge    1475 <execute_cgi+0x235>
mov    -0x4(%rbp),%edi
call   1110 <cannot_execute@plt>
jmp    1681 <execute_cgi+0x441>
mov    $0x0,%al
call   1160 <fork@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jge    149a <execute_cgi+0x25a>
mov    -0x4(%rbp),%edi
call   1110 <cannot_execute@plt>
jmp    1681 <execute_cgi+0x441>
cmpq   $0x0,-0x438(%rbp)
jne    1583 <execute_cgi+0x343>
mov    -0x424(%rbp),%edi
mov    $0x1,%esi
call   1080 <dup2@plt>
mov    -0x430(%rbp),%edi
xor    %esi,%esi
call   1080 <dup2@plt>
mov    -0x428(%rbp),%edi
call   10a0 <close@plt>
mov    -0x42c(%rbp),%edi
call   10a0 <close@plt>
lea    -0x550(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xb39(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0x550(%rbp),%rdi
call   10d0 <putenv@plt>
mov    -0x18(%rbp),%rdi
lea    0xaf5(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1544 <execute_cgi+0x304>
lea    -0x650(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xb0c(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0x650(%rbp),%rdi
call   10d0 <putenv@plt>
jmp    156b <execute_cgi+0x32b>
lea    -0x750(%rbp),%rdi
mov    -0x44c(%rbp),%edx
lea    0xaf0(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0x750(%rbp),%rdi
call   10d0 <putenv@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1150 <execl@plt>
xor    %edi,%edi
call   1140 <exit@plt>
mov    -0x424(%rbp),%edi
call   10a0 <close@plt>
mov    -0x430(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%rdi
lea    0xab6(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1615 <execute_cgi+0x3d5>
movl   $0x0,-0x440(%rbp)
mov    -0x440(%rbp),%eax
cmp    -0x44c(%rbp),%eax
jge    1610 <execute_cgi+0x3d0>
mov    -0x4(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x42c(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    -0x440(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x440(%rbp)
jmp    15bd <execute_cgi+0x37d>
jmp    1615 <execute_cgi+0x3d5>
jmp    161a <execute_cgi+0x3da>
mov    -0x428(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <read@plt>
cmp    $0x0,%rax
jle    1656 <execute_cgi+0x416>
mov    -0x4(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
jmp    161a <execute_cgi+0x3da>
mov    -0x428(%rbp),%edi
call   10a0 <close@plt>
mov    -0x42c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x438(%rbp),%rdi
lea    -0x43c(%rbp),%rsi
xor    %edx,%edx
call   1100 <waitpid@plt>
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    $0x638,%rsp
mov    %rcx,%r12
mov    %rsi,%r15
mov    %edi,%r13d
movw   $0x41,0x130(%rsp)
lea    0xd95(%rip),%rsi
mov    %rdx,0x18(%rsp)
mov    %rdx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1334 <execute_cgi+0xf4>
lea    0x130(%rsp),%rsi
mov    %r13d,%edi
mov    $0x400,%edx
call   1060 <get_line@plt>
test   %eax,%eax
jle    1327 <execute_cgi+0xe7>
mov    %r12,0x20(%rsp)
mov    %r15,0x28(%rsp)
mov    $0xffffffff,%ebp
lea    0x140(%rsp),%rbx
lea    0xd68(%rip),%r14
lea    0x130(%rsp),%r15
lea    0xd39(%rip),%r12
jmp    12e4 <execute_cgi+0xa4>
nopl   (%rax)
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1060 <get_line@plt>
test   %eax,%eax
jle    1318 <execute_cgi+0xd8>
mov    %r14,%rdi
mov    %r15,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1318 <execute_cgi+0xd8>
movb   $0x0,0x13f(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    12d0 <execute_cgi+0x90>
mov    %rbx,%rdi
call   1120 <atoi@plt>
mov    %eax,%ebp
jmp    12d0 <execute_cgi+0x90>
cmp    $0xffffffff,%ebp
mov    0x28(%rsp),%r15
mov    0x20(%rsp),%r12
jne    1374 <execute_cgi+0x134>
mov    %r13d,%edi
call   10f0 <bad_request@plt>
jmp    14c6 <execute_cgi+0x286>
lea    0xce9(%rip),%r14
lea    0x130(%rsp),%rbx
mov    $0xffffffff,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1374 <execute_cgi+0x134>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <get_line@plt>
test   %eax,%eax
jg     1350 <execute_cgi+0x110>
movups 0xc99(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movw   $0xa,0x140(%rsp)
lea    0x130(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
lea    0x8(%rsp),%rdi
call   10b0 <pipe@plt>
test   %rax,%rax
js     14be <execute_cgi+0x27e>
lea    0x10(%rsp),%rdi
call   10b0 <pipe@plt>
test   %rax,%rax
js     14be <execute_cgi+0x27e>
xor    %eax,%eax
call   1160 <fork@plt>
test   %rax,%rax
js     14be <execute_cgi+0x27e>
je     14d8 <execute_cgi+0x298>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
call   10a0 <close@plt>
mov    0x10(%rsp),%edi
call   10a0 <close@plt>
lea    0xc56(%rip),%rsi
mov    0x18(%rsp),%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1448 <execute_cgi+0x208>
test   %ebp,%ebp
jle    1448 <execute_cgi+0x208>
lea    0x30(%rsp),%r14
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x14(%rsp),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
add    $0xffffffff,%ebp
jne    1420 <execute_cgi+0x1e0>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0x1,%edx
call   10c0 <read@plt>
test   %rax,%rax
jle    1498 <execute_cgi+0x258>
lea    0x30(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    0x8(%rsp),%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   10c0 <read@plt>
test   %rax,%rax
jg     1470 <execute_cgi+0x230>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
mov    0x14(%rsp),%edi
call   10a0 <close@plt>
lea    0x530(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1100 <waitpid@plt>
jmp    14c6 <execute_cgi+0x286>
mov    %r13d,%edi
call   1110 <cannot_execute@plt>
add    $0x638,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1080 <dup2@plt>
mov    0x10(%rsp),%edi
xor    %esi,%esi
call   1080 <dup2@plt>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
mov    0x14(%rsp),%edi
call   10a0 <close@plt>
lea    0xb1c(%rip),%rsi
lea    0x530(%rsp),%r14
mov    %r14,%rdi
mov    0x18(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
mov    %r14,%rdi
call   10d0 <putenv@plt>
lea    0xacd(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
lea    0x30(%rsp),%rbx
test   %rax,%rax
jne    155b <execute_cgi+0x31b>
lea    0xaec(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
jmp    156e <execute_cgi+0x32e>
lea    0xae6(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1130 <sprintf@plt>
mov    %rbx,%rdi
call   10d0 <putenv@plt>
mov    %r15,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1150 <execl@plt>
xor    %edi,%edi
call   1140 <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 [2 x i32]
%11 = alloca [2 x i32]
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8
%16 = alloca i32
%17 = alloca i32
%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* %16
store i32 -1, i32* %17
%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* %16
%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* %16
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* %16
br label %45
45: ; preds = %62, %41
%46 = load i32, i32* %16
%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* %17
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* %16
br label %45
66: ; preds = %52
%67 = load i32, i32* %17
%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 %184
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]* %10, 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 %184
87: ; preds = %73
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %11, 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 %184
94: ; preds = %87
%95 = call i64 (...) @fork()
store i64 %95, i64* %12
%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 %184
100: ; preds = %94
%101 = load i64, i64* %12
%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]* %10, i64 0, i64 1
%105 = load i32, i32* %104
%106 = call i32 @dup2(i32 %105, i32 1)
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%108 = load i32, i32* %107
%109 = call i32 @dup2(i32 %108, i32 0)
%110 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%111 = load i32, i32* %110
%112 = call i32 @close(i32 %111)
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%114 = load i32, i32* %113
%115 = call i32 @close(i32 %114)
%116 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i64 0, i64 0
%117 = load i8*, i8** %7
%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 = load i8*, i8** %8
%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* %17
%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, i8* null)
%140 = call i32 @exit(i32 0)
unreachable
141: ; preds = %100
%142 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%143 = load i32, i32* %142
%144 = call i32 @close(i32 %143)
%145 = getelementptr inbounds [2 x i32], [2 x i32]* %11, 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 %166
151: ; preds = %141
store i32 0, i32* %14
br label %152
152: ; preds = %162, %151
%153 = load i32, i32* %14
%154 = load i32, i32* %17
%155 = icmp slt i32 %153, %154
br i1 %155, label %156, label %165
156: ; preds = %152
%157 = load i32, i32* %5
%158 = call i32 @recv(i32 %157, i8* %15, i32 1, i32 0)
%159 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%160 = load i32, i32* %159
%161 = call i32 @write(i32 %160, i8* %15, i32 1)
br label %162
162: ; preds = %156
%163 = load i32, i32* %14
%164 = add nsw i32 %163, 1
store i32 %164, i32* %14
br label %152
165: ; preds = %152
br label %166
166: ; preds = %165, %141
br label %167
167: ; preds = %172, %166
%168 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%169 = load i32, i32* %168
%170 = call i64 @read(i32 %169, i8* %15, i32 1)
%171 = icmp sgt i64 %170, 0
br i1 %171, label %172, label %175
172: ; preds = %167
%173 = load i32, i32* %5
%174 = call i32 @send(i32 %173, i8* %15, i32 1, i32 0)
br label %167
175: ; preds = %167
%176 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%177 = load i32, i32* %176
%178 = call i32 @close(i32 %177)
%179 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%180 = load i32, i32* %179
%181 = call i32 @close(i32 %180)
%182 = load i64, i64* %12
%183 = call i32 @waitpid(i64 %182, i32* %13, i32 0)
br label %184
184: ; preds = %69, %84, %91, %97, %175
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* %2, i8* %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]* %6, 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]* %7, 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 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%77 = load i32, i32* %76
%78 = call i32 @dup2(i32 %77, i32 1)
%79 = load i32, i32* %60
%80 = call i32 @dup2(i32 %79, i32 0)
%81 = load i32, i32* %54
%82 = call i32 @close(i32 %81)
%83 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%84 = load i32, i32* %83
%85 = call i32 @close(i32 %84)
%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* %2)
%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* %3)
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, i8* 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* %60
%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 1)
%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* %54
%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* %54
%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* %54
%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
}