#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;

/* 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);
scalar_t__ execl(char const *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int get_line(int, char *, int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(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*/ snprintf(char *, char *, char const *);
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, strlen(buf));
    }
  else {
    numchars = get_line(client, buf, strlen(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, strlen(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) {
      snprintf(query_env, "QUERY_STRING=%s", query_string);
      putenv(query_env);
    } else {
      sprintf(length_env, "CONTENT_LENGTH=%d", content_length);
    }
    if (execl(path, path, NULL) < 0) {
      printf("execl error\n");
    }
    printf("<p>come on cgi</p>\n");
    exit(0);
  } else {
    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    $0x7a0,%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    134a <execute_cgi+0xea>
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    0xd46(%rip),%rdi
call   1100 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x751(%rbp)
mov    -0x751(%rbp),%al
test   $0x1,%al
jne    1303 <execute_cgi+0xa3>
jmp    1345 <execute_cgi+0xe5>
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
call   1060 <get_line@plt>
mov    %eax,-0x448(%rbp)
jmp    12bb <execute_cgi+0x5b>
jmp    146a <execute_cgi+0x20a>
mov    -0x4(%rbp),%eax
mov    %eax,-0x774(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x770(%rbp)
lea    -0x420(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x774(%rbp),%edi
mov    -0x770(%rbp),%rsi
mov    %eax,%edx
call   1060 <get_line@plt>
mov    %eax,-0x448(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x448(%rbp)
mov    %al,-0x775(%rbp)
jle    13bc <execute_cgi+0x15c>
lea    -0x420(%rbp),%rsi
lea    0xc7a(%rip),%rdi
call   1100 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x775(%rbp)
mov    -0x775(%rbp),%al
test   $0x1,%al
jne    13cf <execute_cgi+0x16f>
jmp    144b <execute_cgi+0x1eb>
movb   $0x0,-0x411(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xc20(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1409 <execute_cgi+0x1a9>
lea    -0x420(%rbp),%rdi
add    $0x10,%rdi
call   1140 <atoi@plt>
mov    %eax,-0x44c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x784(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x780(%rbp)
lea    -0x420(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x784(%rbp),%edi
mov    -0x780(%rbp),%rsi
mov    %eax,%edx
call   1060 <get_line@plt>
mov    %eax,-0x448(%rbp)
jmp    1387 <execute_cgi+0x127>
cmpl   $0xffffffff,-0x44c(%rbp)
jne    1465 <execute_cgi+0x205>
mov    -0x4(%rbp),%edi
call   1110 <bad_request@plt>
jmp    1708 <execute_cgi+0x4a8>
jmp    146a <execute_cgi+0x20a>
lea    -0x420(%rbp),%rdi
lea    0xb9c(%rip),%rsi
mov    $0x0,%al
call   1150 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x794(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x790(%rbp)
lea    -0x420(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x794(%rbp),%edi
mov    -0x790(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
lea    -0x428(%rbp),%rdi
call   10d0 <pipe@plt>
cmp    $0x0,%rax
jge    14db <execute_cgi+0x27b>
mov    -0x4(%rbp),%edi
call   1130 <cannot_execute@plt>
jmp    1708 <execute_cgi+0x4a8>
lea    -0x430(%rbp),%rdi
call   10d0 <pipe@plt>
cmp    $0x0,%rax
jge    14fe <execute_cgi+0x29e>
mov    -0x4(%rbp),%edi
call   1130 <cannot_execute@plt>
jmp    1708 <execute_cgi+0x4a8>
mov    $0x0,%al
call   1180 <fork@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jge    1523 <execute_cgi+0x2c3>
mov    -0x4(%rbp),%edi
call   1130 <cannot_execute@plt>
jmp    1708 <execute_cgi+0x4a8>
cmpq   $0x0,-0x438(%rbp)
jne    1620 <execute_cgi+0x3c0>
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   10c0 <close@plt>
mov    -0x42c(%rbp),%edi
call   10c0 <close@plt>
lea    -0x550(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xab0(%rip),%rsi
mov    $0x0,%al
call   1150 <sprintf@plt>
lea    -0x550(%rbp),%rdi
call   10f0 <putenv@plt>
mov    -0x18(%rbp),%rdi
lea    0xa6c(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    15cb <execute_cgi+0x36b>
lea    -0x650(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xa83(%rip),%rsi
call   10b0 <snprintf@plt>
lea    -0x650(%rbp),%rdi
call   10f0 <putenv@plt>
jmp    15e6 <execute_cgi+0x386>
lea    -0x750(%rbp),%rdi
mov    -0x44c(%rbp),%edx
lea    0xa69(%rip),%rsi
mov    $0x0,%al
call   1150 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1170 <execl@plt>
cmp    $0x0,%rax
jge    160d <execute_cgi+0x3ad>
lea    0xa52(%rip),%rdi
call   10a0 <printf@plt>
lea    0xa53(%rip),%rdi
call   10a0 <printf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xa50(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    169c <execute_cgi+0x43c>
movl   $0x0,-0x440(%rbp)
mov    -0x440(%rbp),%eax
cmp    -0x44c(%rbp),%eax
jge    1697 <execute_cgi+0x437>
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    1644 <execute_cgi+0x3e4>
jmp    169c <execute_cgi+0x43c>
jmp    16a1 <execute_cgi+0x441>
mov    -0x428(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
call   10e0 <read@plt>
cmp    $0x0,%rax
jle    16dd <execute_cgi+0x47d>
mov    -0x4(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
jmp    16a1 <execute_cgi+0x441>
mov    -0x428(%rbp),%edi
call   10c0 <close@plt>
mov    -0x42c(%rbp),%edi
call   10c0 <close@plt>
mov    -0x438(%rbp),%rdi
lea    -0x43c(%rbp),%rsi
xor    %edx,%edx
call   1120 <waitpid@plt>
add    $0x7a0,%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    0xd75(%rip),%rsi
mov    %rdx,0x18(%rsp)
mov    %rdx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1369 <execute_cgi+0x109>
lea    0x130(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <get_line@plt>
test   %eax,%eax
jle    135c <execute_cgi+0xfc>
mov    %r12,0x20(%rsp)
mov    %r15,0x28(%rsp)
mov    $0xffffffff,%ebp
lea    0x140(%rsp),%rbx
lea    0xd40(%rip),%r14
lea    0x130(%rsp),%r15
lea    0xd11(%rip),%r12
jmp    1319 <execute_cgi+0xb9>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1080 <strlen@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1070 <get_line@plt>
test   %eax,%eax
jle    134d <execute_cgi+0xed>
mov    %r14,%rdi
mov    %r15,%rsi
call   1100 <strcmp@plt>
test   %rax,%rax
je     134d <execute_cgi+0xed>
movb   $0x0,0x13f(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1300 <execute_cgi+0xa0>
mov    %rbx,%rdi
call   1140 <atoi@plt>
mov    %eax,%ebp
jmp    1300 <execute_cgi+0xa0>
cmp    $0xffffffff,%ebp
mov    0x28(%rsp),%r15
mov    0x20(%rsp),%r12
jne    13a9 <execute_cgi+0x149>
mov    %r13d,%edi
call   1110 <bad_request@plt>
jmp    14e6 <execute_cgi+0x286>
lea    0xcb4(%rip),%r14
lea    0x130(%rsp),%rbx
mov    $0xffffffff,%ebp
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1100 <strcmp@plt>
test   %rax,%rax
je     13a9 <execute_cgi+0x149>
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <get_line@plt>
test   %eax,%eax
jg     1380 <execute_cgi+0x120>
movups 0xc64(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movw   $0xa,0x140(%rsp)
lea    0x130(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
lea    0x8(%rsp),%rdi
call   10d0 <pipe@plt>
test   %rax,%rax
js     14de <execute_cgi+0x27e>
lea    0x10(%rsp),%rdi
call   10d0 <pipe@plt>
test   %rax,%rax
js     14de <execute_cgi+0x27e>
xor    %eax,%eax
call   1180 <fork@plt>
test   %rax,%rax
js     14de <execute_cgi+0x27e>
je     14f8 <execute_cgi+0x298>
mov    %rax,%r14
lea    0xc33(%rip),%rsi
mov    0x18(%rsp),%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1468 <execute_cgi+0x208>
test   %ebp,%ebp
jle    1468 <execute_cgi+0x208>
lea    0x30(%rsp),%rbx
nop
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x14(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <write@plt>
add    $0xffffffff,%ebp
jne    1440 <execute_cgi+0x1e0>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0x1,%edx
call   10e0 <read@plt>
test   %rax,%rax
jle    14b8 <execute_cgi+0x258>
lea    0x30(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   10e0 <read@plt>
test   %rax,%rax
jg     1490 <execute_cgi+0x230>
mov    0x8(%rsp),%edi
call   10c0 <close@plt>
mov    0x14(%rsp),%edi
call   10c0 <close@plt>
lea    0x530(%rsp),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1120 <waitpid@plt>
jmp    14e6 <execute_cgi+0x286>
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   1090 <dup2@plt>
mov    0x10(%rsp),%edi
xor    %esi,%esi
call   1090 <dup2@plt>
mov    0x8(%rsp),%edi
call   10c0 <close@plt>
mov    0x14(%rsp),%edi
call   10c0 <close@plt>
lea    0xafc(%rip),%rsi
lea    0x530(%rsp),%r14
mov    %r14,%rdi
mov    0x18(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1150 <sprintf@plt>
mov    %r14,%rdi
call   10f0 <putenv@plt>
lea    0xaad(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1581 <execute_cgi+0x321>
lea    0xad1(%rip),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rdx
call   10b0 <snprintf@plt>
mov    %rbx,%rdi
call   10f0 <putenv@plt>
jmp    1596 <execute_cgi+0x336>
lea    0xac0(%rip),%rsi
lea    0x30(%rsp),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1150 <sprintf@plt>
mov    %r15,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1170 <execl@plt>
test   %rax,%rax
jns    15b4 <execute_cgi+0x354>
lea    0xac3(%rip),%rdi
call   1050 <puts@plt>
lea    0xaa4(%rip),%rdi
call   1050 <puts@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"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 = [13 x i8] c"execl error\0A\00"
@.str.8 = [20 x i8] c"<p>come on cgi</p>\0A\00"
@.str.9 = [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 %43
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 %42
36: ; preds = %34
%37 = load i32, i32* %5
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @get_line(i32 %37, i8* %38, i32 %40)
store i32 %41, i32* %16
br label %27
42: ; preds = %34
br label %79
43: ; preds = %4
%44 = load i32, i32* %5
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @get_line(i32 %44, i8* %45, i32 %47)
store i32 %48, i32* %16
br label %49
49: ; preds = %66, %43
%50 = load i32, i32* %16
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%54 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = icmp ne i64 %54, 0
br label %56
56: ; preds = %52, %49
%57 = phi i1 [ false, %49 ], [ %55, %52 ]
br i1 %57, label %58, label %72
58: ; preds = %56
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 15
store i8 0, i8* %59
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%61 = call i64 @strcasecmp(i8* %60, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 16
%65 = call i32 @atoi(i8* %64)
store i32 %65, i32* %17
br label %66
66: ; preds = %63, %58
%67 = load i32, i32* %5
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%70 = call i32 @strlen(i8* %69)
%71 = call i32 @get_line(i32 %67, i8* %68, i32 %70)
store i32 %71, i32* %16
br label %49
72: ; preds = %56
%73 = load i32, i32* %17
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = load i32, i32* %5
%77 = call i32 @bad_request(i32 %76)
br label %187
78: ; preds = %72
br label %79
79: ; preds = %78, %42
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%81 = call i32 (i8*, i8*, ...) @sprintf(i8* %80, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%82 = load i32, i32* %5
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%85 = call i32 @strlen(i8* %84)
%86 = call i32 @send(i32 %82, i8* %83, i32 %85, i32 0)
%87 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%88 = call i64 @pipe(i32* %87)
%89 = icmp slt i64 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %79
%91 = load i32, i32* %5
%92 = call i32 @cannot_execute(i32 %91)
br label %187
93: ; preds = %79
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%95 = call i64 @pipe(i32* %94)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %93
%98 = load i32, i32* %5
%99 = call i32 @cannot_execute(i32 %98)
br label %187
100: ; preds = %93
%101 = call i64 (...) @fork()
store i64 %101, i64* %12
%102 = icmp slt i64 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %100
%104 = load i32, i32* %5
%105 = call i32 @cannot_execute(i32 %104)
br label %187
106: ; preds = %100
%107 = load i64, i64* %12
%108 = icmp eq i64 %107, 0
br i1 %108, label %109, label %150
109: ; preds = %106
%110 = getelementptr inbounds [2 x i32], [2 x i32]* %10, 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]* %11, i64 0, i64 0
%114 = load i32, i32* %113
%115 = call i32 @dup2(i32 %114, i32 0)
%116 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%117 = load i32, i32* %116
%118 = call i32 @close(i32 %117)
%119 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%120 = load i32, i32* %119
%121 = call i32 @close(i32 %120)
%122 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i64 0, i64 0
%123 = load i8*, i8** %7
%124 = call i32 (i8*, i8*, ...) @sprintf(i8* %122, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %123)
%125 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i64 0, i64 0
%126 = call i32 @putenv(i8* %125)
%127 = load i8*, i8** %7
%128 = call i64 @strcasecmp(i8* %127, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%129 = icmp eq i64 %128, 0
br i1 %129, label %130, label %136
130: ; preds = %109
%131 = getelementptr inbounds [255 x i8], [255 x i8]* %19, i64 0, i64 0
%132 = load i8*, i8** %8
%133 = call i32 @snprintf(i8* %131, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %132)
%134 = getelementptr inbounds [255 x i8], [255 x i8]* %19, i64 0, i64 0
%135 = call i32 @putenv(i8* %134)
br label %140
136: ; preds = %109
%137 = getelementptr inbounds [255 x i8], [255 x i8]* %20, i64 0, i64 0
%138 = load i32, i32* %17
%139 = call i32 (i8*, i8*, ...) @sprintf(i8* %137, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %138)
br label %140
140: ; preds = %136, %130
%141 = load i8*, i8** %6
%142 = load i8*, i8** %6
%143 = call i64 @execl(i8* %141, i8* %142, i32* null)
%144 = icmp slt i64 %143, 0
br i1 %144, label %145, label %147
145: ; preds = %140
%146 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %147
147: ; preds = %145, %140
%148 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%149 = call i32 @exit(i32 0)
unreachable
150: ; preds = %106
%151 = load i8*, i8** %7
%152 = call i64 @strcasecmp(i8* %151, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%153 = icmp eq i64 %152, 0
br i1 %153, label %154, label %169
154: ; preds = %150
store i32 0, i32* %14
br label %155
155: ; preds = %165, %154
%156 = load i32, i32* %14
%157 = load i32, i32* %17
%158 = icmp slt i32 %156, %157
br i1 %158, label %159, label %168
159: ; preds = %155
%160 = load i32, i32* %5
%161 = call i32 @recv(i32 %160, i8* %15, i32 1, i32 0)
%162 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%163 = load i32, i32* %162
%164 = call i32 @write(i32 %163, i8* %15, i32 1)
br label %165
165: ; preds = %159
%166 = load i32, i32* %14
%167 = add nsw i32 %166, 1
store i32 %167, i32* %14
br label %155
168: ; preds = %155
br label %169
169: ; preds = %168, %150
br label %170
170: ; preds = %175, %169
%171 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%172 = load i32, i32* %171
%173 = call i64 @read(i32 %172, i8* %15, i32 1)
%174 = icmp sgt i64 %173, 0
br i1 %174, label %175, label %178
175: ; preds = %170
%176 = load i32, i32* %5
%177 = call i32 @send(i32 %176, i8* %15, i32 1, i32 0)
br label %170
178: ; preds = %170
%179 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%180 = load i32, i32* %179
%181 = call i32 @close(i32 %180)
%182 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%183 = load i32, i32* %182
%184 = call i32 @close(i32 %183)
%185 = load i64, i64* %12
%186 = call i32 @waitpid(i64 %185, i32* %13, i32 0)
br label %187
187: ; preds = %75, %90, %97, %103, %178
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.9 = [5 x i8] c"POST\00"
@str = [19 x i8] c"<p>come on cgi</p>\00"
@str.10 = [12 x i8] c"execl error\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 %27
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 %53, label %23
23: ; preds = %20
%24 = call i32 @strlen(i8* %13)
%25 = call i32 @get_line(i32 %0, i8* %13, i32 %24)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %20, label %53
27: ; preds = %4
%28 = call i32 @strlen(i8* %13)
%29 = call i32 @get_line(i32 %0, i8* %13, i32 %28)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %51
31: ; preds = %27
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 15
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 16
br label %34
34: ; preds = %31, %43
%35 = phi i32 [ -1, %31 ], [ %44, %43 ]
%36 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%37 = icmp eq i64 %36, 0
br i1 %37, label %48, label %38
38: ; preds = %34
store i8 0, i8* %32
%39 = call i64 @strcasecmp(i8* %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @atoi(i8* %33)
br label %43
43: ; preds = %41, %38
%44 = phi i32 [ %42, %41 ], [ %35, %38 ]
%45 = call i32 @strlen(i8* %13)
%46 = call i32 @get_line(i32 %0, i8* %13, i32 %45)
%47 = icmp sgt i32 %46, 0
br i1 %47, label %34, label %48
48: ; preds = %34, %43
%49 = phi i32 [ %35, %34 ], [ %44, %43 ]
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %27, %48
%52 = call i32 @bad_request(i32 %0)
br label %136
53: ; preds = %20, %23, %48
%54 = phi i32 [ %49, %48 ], [ -1, %23 ], [ -1, %20 ]
%55 = call i32 @strlen(i8* %13)
%56 = call i32 @send(i32 %0, i8* %13, i32 %55, i32 0)
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%58 = call i64 @pipe(i32* %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %53
%61 = call i32 @cannot_execute(i32 %0)
br label %136
62: ; preds = %53
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%64 = call i64 @pipe(i32* %63)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = call i32 @cannot_execute(i32 %0)
br label %136
68: ; preds = %62
%69 = call i64 (...) @fork()
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 @cannot_execute(i32 %0)
br label %136
73: ; preds = %68
%74 = icmp eq i64 %69, 0
br i1 %74, label %75, label %106
75: ; preds = %73
%76 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%77 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%78 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%79 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%80 = load i32, i32* %79
%81 = call i32 @dup2(i32 %80, i32 1)
%82 = load i32, i32* %63
%83 = call i32 @dup2(i32 %82, i32 0)
%84 = load i32, i32* %57
%85 = call i32 @close(i32 %84)
%86 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%87 = load i32, i32* %86
%88 = call i32 @close(i32 %87)
%89 = call i32 (i8*, i8*, ...) @sprintf(i8* %76, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%90 = call i32 @putenv(i8* %76)
%91 = call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %75
%94 = call i32 @snprintf(i8* %77, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%95 = call i32 @putenv(i8* %77)
br label %98
96: ; preds = %75
%97 = call i32 (i8*, i8*, ...) @sprintf(i8* %78, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %54)
br label %98
98: ; preds = %96, %93
%99 = call i64 @execl(i8* %1, i8* %1, i32* null)
%100 = icmp slt i64 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %98
%102 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
br label %103
103: ; preds = %101, %98
%104 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%105 = call i32 @exit(i32 0)
unreachable
106: ; preds = %73
%107 = call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%108 = icmp eq i64 %107, 0
%109 = icmp sgt i32 %54, 0
%110 = select i1 %108, i1 %109, i1 false
br i1 %110, label %111, label %120
111: ; preds = %106
%112 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
br label %113
113: ; preds = %111, %113
%114 = phi i32 [ 0, %111 ], [ %118, %113 ]
%115 = call i32 @recv(i32 %0, i8* %9, i32 1, i32 0)
%116 = load i32, i32* %112
%117 = call i32 @write(i32 %116, i8* %9, i32 1)
%118 = add nuw nsw i32 %114, 1
%119 = icmp eq i32 %118, %54
br i1 %119, label %120, label %113
120: ; preds = %113, %106
%121 = load i32, i32* %57
%122 = call i64 @read(i32 %121, i8* %9, i32 1)
%123 = icmp sgt i64 %122, 0
br i1 %123, label %124, label %129
124: ; preds = %120, %124
%125 = call i32 @send(i32 %0, i8* %9, i32 1, i32 0)
%126 = load i32, i32* %57
%127 = call i64 @read(i32 %126, i8* %9, i32 1)
%128 = icmp sgt i64 %127, 0
br i1 %128, label %124, label %129
129: ; preds = %124, %120
%130 = load i32, i32* %57
%131 = call i32 @close(i32 %130)
%132 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%133 = load i32, i32* %132
%134 = call i32 @close(i32 %133)
%135 = call i32 @waitpid(i64 %69, i32* %8, i32 0)
br label %136
136: ; preds = %129, %71, %66, %60, %51
ret void
}