#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 *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int get_line(int, char *, int);
int /*<<< orphan*/ headers(int, char const *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, char);
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 *, ...);
int /*<<< orphan*/ stdout;
scalar_t__ strcasecmp(char const *, char *);
scalar_t__ strcmp(char *, 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;
    }
  }
  headers(client, path);
  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, 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(client, &c, 1, 0);
        write(cgi_input[1], &c, 1);
      }
    }
    while (read(cgi_output[0], &c, 1) > 0) {
      send(client, &c, 1, 0);
      printf("%c", c);
    }
    fflush(stdout);
    close(cgi_output[0]);
    close(cgi_input[1]);
    waitpid(pid, &status, 0);
  }
}


x86 assembly (clang, -O0):
<execute_cgi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x760,%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    0xd59(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1327 <execute_cgi+0xc7>
jmp    12bb <execute_cgi+0x5b>
xor    %eax,%eax
cmpl   $0x0,-0x448(%rbp)
mov    %al,-0x751(%rbp)
jle    12f0 <execute_cgi+0x90>
lea    -0x420(%rbp),%rsi
lea    0xd26(%rip),%rdi
call   10e0 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x751(%rbp)
mov    -0x751(%rbp),%al
test   $0x1,%al
jne    1303 <execute_cgi+0xa3>
jmp    1322 <execute_cgi+0xc2>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <get_line@plt>
mov    %eax,-0x448(%rbp)
jmp    12bb <execute_cgi+0x5b>
jmp    1401 <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    1376 <execute_cgi+0x116>
lea    -0x420(%rbp),%rsi
lea    0xca0(%rip),%rdi
call   10e0 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x752(%rbp)
mov    -0x752(%rbp),%al
test   $0x1,%al
jne    1389 <execute_cgi+0x129>
jmp    13e2 <execute_cgi+0x182>
movb   $0x0,-0x411(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xc68(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    13c3 <execute_cgi+0x163>
lea    -0x420(%rbp),%rdi
add    $0x10,%rdi
call   1140 <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    1341 <execute_cgi+0xe1>
cmpl   $0xffffffff,-0x44c(%rbp)
jne    13fc <execute_cgi+0x19c>
mov    -0x4(%rbp),%edi
call   10f0 <bad_request@plt>
jmp    1680 <execute_cgi+0x420>
jmp    1401 <execute_cgi+0x1a1>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1100 <headers@plt>
lea    -0x428(%rbp),%rdi
call   10b0 <pipe@plt>
cmp    $0x0,%rax
jge    1430 <execute_cgi+0x1d0>
mov    -0x4(%rbp),%edi
call   1130 <cannot_execute@plt>
jmp    1680 <execute_cgi+0x420>
lea    -0x430(%rbp),%rdi
call   10b0 <pipe@plt>
cmp    $0x0,%rax
jge    1453 <execute_cgi+0x1f3>
mov    -0x4(%rbp),%edi
call   1130 <cannot_execute@plt>
jmp    1680 <execute_cgi+0x420>
mov    $0x0,%al
call   1180 <fork@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jge    1478 <execute_cgi+0x218>
mov    -0x4(%rbp),%edi
call   1130 <cannot_execute@plt>
jmp    1680 <execute_cgi+0x420>
cmpq   $0x0,-0x438(%rbp)
jne    1561 <execute_cgi+0x301>
mov    -0x424(%rbp),%edi
mov    $0x1,%esi
call   1070 <dup2@plt>
mov    -0x430(%rbp),%edi
xor    %esi,%esi
call   1070 <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    0xb4b(%rip),%rsi
mov    $0x0,%al
call   1150 <sprintf@plt>
lea    -0x550(%rbp),%rdi
call   10d0 <putenv@plt>
mov    -0x18(%rbp),%rdi
lea    0xb17(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1522 <execute_cgi+0x2c2>
lea    -0x650(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xb1e(%rip),%rsi
mov    $0x0,%al
call   1150 <sprintf@plt>
lea    -0x650(%rbp),%rdi
call   10d0 <putenv@plt>
jmp    1549 <execute_cgi+0x2e9>
lea    -0x750(%rbp),%rdi
mov    -0x44c(%rbp),%edx
lea    0xb02(%rip),%rsi
mov    $0x0,%al
call   1150 <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   1170 <execl@plt>
xor    %edi,%edi
call   1160 <exit@plt>
mov    -0x424(%rbp),%edi
call   10a0 <close@plt>
mov    -0x430(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%rdi
lea    0xac8(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    15f3 <execute_cgi+0x393>
movl   $0x0,-0x440(%rbp)
mov    -0x440(%rbp),%eax
cmp    -0x44c(%rbp),%eax
jge    15ee <execute_cgi+0x38e>
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    159b <execute_cgi+0x33b>
jmp    15f3 <execute_cgi+0x393>
jmp    15f8 <execute_cgi+0x398>
mov    -0x428(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <read@plt>
cmp    $0x0,%rax
jle    1647 <execute_cgi+0x3e7>
mov    -0x4(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
lea    0xa19(%rip),%rdi
movsbl -0x441(%rbp),%esi
call   1090 <printf@plt>
jmp    15f8 <execute_cgi+0x398>
mov    0x2992(%rip),%rax
mov    (%rax),%edi
call   1110 <fflush@plt>
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   1120 <waitpid@plt>
add    $0x760,%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,0x230(%rsp)
lea    0xd75(%rip),%rsi
mov    %rdx,0x18(%rsp)
mov    %rdx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1354 <execute_cgi+0xf4>
lea    0x230(%rsp),%rsi
mov    %r13d,%edi
mov    $0x400,%edx
call   1060 <get_line@plt>
test   %eax,%eax
jle    1347 <execute_cgi+0xe7>
mov    %r12,0x20(%rsp)
mov    %r15,0x28(%rsp)
mov    $0xffffffff,%ebp
lea    0x240(%rsp),%rbx
lea    0xd28(%rip),%r15
lea    0x230(%rsp),%r14
lea    0xd1b(%rip),%r12
jmp    1304 <execute_cgi+0xa4>
nopl   (%rax)
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1060 <get_line@plt>
test   %eax,%eax
jle    1338 <execute_cgi+0xd8>
mov    %r15,%rdi
mov    %r14,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1338 <execute_cgi+0xd8>
movb   $0x0,0x23f(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    12f0 <execute_cgi+0x90>
mov    %rbx,%rdi
call   1140 <atoi@plt>
mov    %eax,%ebp
jmp    12f0 <execute_cgi+0x90>
cmp    $0xffffffff,%ebp
mov    0x28(%rsp),%r15
mov    0x20(%rsp),%r12
jne    1394 <execute_cgi+0x134>
mov    %r13d,%edi
call   10f0 <bad_request@plt>
jmp    14d1 <execute_cgi+0x271>
lea    0xca9(%rip),%r14
lea    0x230(%rsp),%rbx
mov    $0xffffffff,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1394 <execute_cgi+0x134>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <get_line@plt>
test   %eax,%eax
jg     1370 <execute_cgi+0x110>
mov    %r13d,%edi
mov    %r15,%rsi
call   1100 <headers@plt>
lea    0x8(%rsp),%rdi
call   10b0 <pipe@plt>
test   %rax,%rax
js     14c9 <execute_cgi+0x269>
lea    0x10(%rsp),%rdi
call   10b0 <pipe@plt>
test   %rax,%rax
js     14c9 <execute_cgi+0x269>
xor    %eax,%eax
call   1180 <fork@plt>
test   %rax,%rax
js     14c9 <execute_cgi+0x269>
je     14e3 <execute_cgi+0x283>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
call   10a0 <close@plt>
mov    0x10(%rsp),%edi
call   10a0 <close@plt>
lea    0xc53(%rip),%rsi
mov    0x18(%rsp),%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1438 <execute_cgi+0x1d8>
test   %ebp,%ebp
jle    1438 <execute_cgi+0x1d8>
lea    0x30(%rsp),%r14
nop
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    1410 <execute_cgi+0x1b0>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0x1,%edx
call   10c0 <read@plt>
test   %rax,%rax
jle    1495 <execute_cgi+0x235>
lea    0x30(%rsp),%rbp
lea    0xbf3(%rip),%r14
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
movsbl 0x30(%rsp),%esi
mov    %r14,%rdi
call   1090 <printf@plt>
mov    0x8(%rsp),%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   10c0 <read@plt>
test   %rax,%rax
jg     1460 <execute_cgi+0x200>
mov    0x2b44(%rip),%rax
mov    (%rax),%edi
call   1110 <fflush@plt>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
mov    0x14(%rsp),%edi
call   10a0 <close@plt>
lea    0x130(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1120 <waitpid@plt>
jmp    14d1 <execute_cgi+0x271>
mov    %r13d,%edi
call   1130 <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   1070 <dup2@plt>
mov    0x10(%rsp),%edi
xor    %esi,%esi
call   1070 <dup2@plt>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
mov    0x14(%rsp),%edi
call   10a0 <close@plt>
lea    0xb01(%rip),%rsi
lea    0x130(%rsp),%r14
mov    %r14,%rdi
mov    0x18(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1150 <sprintf@plt>
mov    %r14,%rdi
call   10d0 <putenv@plt>
lea    0xac2(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
lea    0x30(%rsp),%rbx
test   %rax,%rax
jne    1566 <execute_cgi+0x306>
lea    0xad1(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1150 <sprintf@plt>
jmp    1579 <execute_cgi+0x319>
lea    0xacb(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1150 <sprintf@plt>
mov    %rbx,%rdi
call   10d0 <putenv@plt>
mov    %r15,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1170 <execl@plt>
xor    %edi,%edi
call   1160 <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"REQUEST_METHOD=%s\00"
@.str.4 = [16 x i8] c"QUERY_STRING=%s\00"
@.str.5 = [18 x i8] c"CONTENT_LENGTH=%d\00"
@.str.6 = [5 x i8] c"POST\00"
@.str.7 = [3 x i8] c"%c\00"
@stdout = global i32 0
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 = load i32, i32* %5
%75 = load i8*, i8** %6
%76 = call i32 @headers(i32 %74, i8* %75)
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%78 = call i64 @pipe(i32* %77)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %73
%81 = load i32, i32* %5
%82 = call i32 @cannot_execute(i32 %81)
br label %184
83: ; preds = %73
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%85 = call i64 @pipe(i32* %84)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %83
%88 = load i32, i32* %5
%89 = call i32 @cannot_execute(i32 %88)
br label %184
90: ; preds = %83
%91 = call i64 (...) @fork()
store i64 %91, i64* %12
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %90
%94 = load i32, i32* %5
%95 = call i32 @cannot_execute(i32 %94)
br label %184
96: ; preds = %90
%97 = load i64, i64* %12
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %137
99: ; preds = %96
%100 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%101 = load i32, i32* %100
%102 = call i32 @dup2(i32 %101, i32 1)
%103 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%104 = load i32, i32* %103
%105 = call i32 @dup2(i32 %104, i32 0)
%106 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%107 = load i32, i32* %106
%108 = call i32 @close(i32 %107)
%109 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%110 = load i32, i32* %109
%111 = call i32 @close(i32 %110)
%112 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i64 0, i64 0
%113 = load i8*, i8** %7
%114 = call i32 (i8*, i8*, ...) @sprintf(i8* %112, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %113)
%115 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i64 0, i64 0
%116 = call i32 @putenv(i8* %115)
%117 = load i8*, i8** %7
%118 = call i64 @strcasecmp(i8* %117, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%119 = icmp eq i64 %118, 0
br i1 %119, label %120, label %126
120: ; preds = %99
%121 = getelementptr inbounds [255 x i8], [255 x i8]* %19, i64 0, i64 0
%122 = load i8*, i8** %8
%123 = call i32 (i8*, i8*, ...) @sprintf(i8* %121, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %122)
%124 = getelementptr inbounds [255 x i8], [255 x i8]* %19, i64 0, i64 0
%125 = call i32 @putenv(i8* %124)
br label %132
126: ; preds = %99
%127 = getelementptr inbounds [255 x i8], [255 x i8]* %20, i64 0, i64 0
%128 = load i32, i32* %17
%129 = call i32 (i8*, i8*, ...) @sprintf(i8* %127, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %128)
%130 = getelementptr inbounds [255 x i8], [255 x i8]* %20, i64 0, i64 0
%131 = call i32 @putenv(i8* %130)
br label %132
132: ; preds = %126, %120
%133 = load i8*, i8** %6
%134 = load i8*, i8** %6
%135 = call i32 @execl(i8* %133, i8* %134, i32* null)
%136 = call i32 @exit(i32 0)
unreachable
137: ; preds = %96
%138 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%139 = load i32, i32* %138
%140 = call i32 @close(i32 %139)
%141 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%142 = load i32, i32* %141
%143 = call i32 @close(i32 %142)
%144 = load i8*, i8** %7
%145 = call i64 @strcasecmp(i8* %144, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%146 = icmp eq i64 %145, 0
br i1 %146, label %147, label %162
147: ; preds = %137
store i32 0, i32* %14
br label %148
148: ; preds = %158, %147
%149 = load i32, i32* %14
%150 = load i32, i32* %17
%151 = icmp slt i32 %149, %150
br i1 %151, label %152, label %161
152: ; preds = %148
%153 = load i32, i32* %5
%154 = call i32 @recv(i32 %153, i8* %15, i32 1, i32 0)
%155 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%156 = load i32, i32* %155
%157 = call i32 @write(i32 %156, i8* %15, i32 1)
br label %158
158: ; preds = %152
%159 = load i32, i32* %14
%160 = add nsw i32 %159, 1
store i32 %160, i32* %14
br label %148
161: ; preds = %148
br label %162
162: ; preds = %161, %137
br label %163
163: ; preds = %168, %162
%164 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%165 = load i32, i32* %164
%166 = call i64 @read(i32 %165, i8* %15, i32 1)
%167 = icmp sgt i64 %166, 0
br i1 %167, label %168, label %173
168: ; preds = %163
%169 = load i32, i32* %5
%170 = call i32 @send(i32 %169, i8* %15, i32 1, i32 0)
%171 = load i8, i8* %15
%172 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8 signext %171)
br label %163
173: ; preds = %163
%174 = load i32, i32* @stdout
%175 = call i32 @fflush(i32 %174)
%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, %80, %87, %93, %173
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"REQUEST_METHOD=%s\00"
@.str.4 = [16 x i8] c"QUERY_STRING=%s\00"
@.str.5 = [18 x i8] c"CONTENT_LENGTH=%d\00"
@.str.6 = [5 x i8] c"POST\00"
@.str.7 = [3 x i8] c"%c\00"
@stdout = global i32 0
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 %137
50: ; preds = %20, %23, %45
%51 = phi i32 [ %46, %45 ], [ -1, %23 ], [ -1, %20 ]
%52 = call i32 @headers(i32 %0, i8* %1)
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%54 = call i64 @pipe(i32* %53)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %50
%57 = call i32 @cannot_execute(i32 %0)
br label %137
58: ; preds = %50
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%60 = call i64 @pipe(i32* %59)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = call i32 @cannot_execute(i32 %0)
br label %137
64: ; preds = %58
%65 = call i64 (...) @fork()
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 @cannot_execute(i32 %0)
br label %137
69: ; preds = %64
%70 = icmp eq i64 %65, 0
br i1 %70, label %71, label %98
71: ; preds = %69
%72 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%73 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%74 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%76 = load i32, i32* %75
%77 = call i32 @dup2(i32 %76, i32 1)
%78 = load i32, i32* %59
%79 = call i32 @dup2(i32 %78, i32 0)
%80 = load i32, i32* %53
%81 = call i32 @close(i32 %80)
%82 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%83 = load i32, i32* %82
%84 = call i32 @close(i32 %83)
%85 = call i32 (i8*, i8*, ...) @sprintf(i8* %72, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%86 = call i32 @putenv(i8* %72)
%87 = call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %71
%90 = call i32 (i8*, i8*, ...) @sprintf(i8* %73, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %3)
br label %93
91: ; preds = %71
%92 = call i32 (i8*, i8*, ...) @sprintf(i8* %74, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %51)
br label %93
93: ; preds = %91, %89
%94 = phi i8* [ %74, %91 ], [ %73, %89 ]
%95 = call i32 @putenv(i8* %94)
%96 = call i32 @execl(i8* %1, i8* %1, i32* null)
%97 = call i32 @exit(i32 0)
unreachable
98: ; preds = %69
%99 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%100 = load i32, i32* %99
%101 = call i32 @close(i32 %100)
%102 = load i32, i32* %59
%103 = call i32 @close(i32 %102)
%104 = call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%105 = icmp eq i64 %104, 0
%106 = icmp sgt i32 %51, 0
%107 = select i1 %105, i1 %106, i1 false
br i1 %107, label %108, label %117
108: ; preds = %98
%109 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
br label %110
110: ; preds = %108, %110
%111 = phi i32 [ 0, %108 ], [ %115, %110 ]
%112 = call i32 @recv(i32 %0, i8* %9, i32 1, i32 0)
%113 = load i32, i32* %109
%114 = call i32 @write(i32 %113, i8* %9, i32 1)
%115 = add nuw nsw i32 %111, 1
%116 = icmp eq i32 %115, %51
br i1 %116, label %117, label %110
117: ; preds = %110, %98
%118 = load i32, i32* %53
%119 = call i64 @read(i32 %118, i8* %9, i32 1)
%120 = icmp sgt i64 %119, 0
br i1 %120, label %121, label %128
121: ; preds = %117, %121
%122 = call i32 @send(i32 %0, i8* %9, i32 1, i32 0)
%123 = load i8, i8* %9
%124 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8 signext %123)
%125 = load i32, i32* %53
%126 = call i64 @read(i32 %125, i8* %9, i32 1)
%127 = icmp sgt i64 %126, 0
br i1 %127, label %121, label %128
128: ; preds = %121, %117
%129 = load i32, i32* @stdout
%130 = call i32 @fflush(i32 %129)
%131 = load i32, i32* %53
%132 = call i32 @close(i32 %131)
%133 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%134 = load i32, i32* %133
%135 = call i32 @close(i32 %134)
%136 = call i32 @waitpid(i64 %65, i32* %8, i32 0)
br label %137
137: ; preds = %128, %67, %62, %56, %48
ret void
}