#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));
      printf("header: %s \n", buf);
    }
  else {
    numchars = get_line(client, buf, strlen(buf));
    printf("buf: %s\n", buf);
    while ((numchars > 0) && strcmp("\n", buf)) {
      buf[15] = '\0';
      printf("buf:%s \n", buf);
      if (strcasecmp(buf, "Content-Length:") == 0) {
        content_length = atoi(&buf[16]);
      }
      numchars = get_line(client, buf, strlen(buf));
    }
    printf("before bad_request \n");
    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    135f <execute_cgi+0xff>
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    0xd7a(%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    135a <execute_cgi+0xfa>
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)
lea    -0x420(%rbp),%rsi
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    12bb <execute_cgi+0x5b>
jmp    14b7 <execute_cgi+0x257>
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)
lea    -0x420(%rbp),%rsi
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x448(%rbp)
mov    %al,-0x775(%rbp)
jle    13e6 <execute_cgi+0x186>
lea    -0x420(%rbp),%rsi
lea    0xc84(%rip),%rdi
call   1100 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x775(%rbp)
mov    -0x775(%rbp),%al
test   $0x1,%al
jne    13f9 <execute_cgi+0x199>
jmp    148a <execute_cgi+0x22a>
movb   $0x0,-0x411(%rbp)
lea    -0x420(%rbp),%rsi
lea    0xc0c(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    -0x420(%rbp),%rdi
lea    0xc00(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1448 <execute_cgi+0x1e8>
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    13b1 <execute_cgi+0x151>
lea    0xba2(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
cmpl   $0xffffffff,-0x44c(%rbp)
jne    14b2 <execute_cgi+0x252>
mov    -0x4(%rbp),%edi
call   1110 <bad_request@plt>
jmp    1759 <execute_cgi+0x4f9>
jmp    14b7 <execute_cgi+0x257>
lea    -0x420(%rbp),%rdi
lea    0xb83(%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    1528 <execute_cgi+0x2c8>
mov    -0x4(%rbp),%edi
call   1130 <cannot_execute@plt>
jmp    1759 <execute_cgi+0x4f9>
lea    -0x430(%rbp),%rdi
call   10d0 <pipe@plt>
cmp    $0x0,%rax
jge    154b <execute_cgi+0x2eb>
mov    -0x4(%rbp),%edi
call   1130 <cannot_execute@plt>
jmp    1759 <execute_cgi+0x4f9>
mov    $0x0,%al
call   1180 <fork@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jge    1570 <execute_cgi+0x310>
mov    -0x4(%rbp),%edi
call   1130 <cannot_execute@plt>
jmp    1759 <execute_cgi+0x4f9>
cmpq   $0x0,-0x438(%rbp)
jne    1671 <execute_cgi+0x411>
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    0xa97(%rip),%rsi
mov    $0x0,%al
call   1150 <sprintf@plt>
lea    -0x550(%rbp),%rdi
call   10f0 <putenv@plt>
mov    -0x18(%rbp),%rdi
lea    0xa1f(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1618 <execute_cgi+0x3b8>
lea    -0x650(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xa6a(%rip),%rsi
call   10b0 <snprintf@plt>
lea    -0x650(%rbp),%rdi
call   10f0 <putenv@plt>
jmp    1633 <execute_cgi+0x3d3>
lea    -0x750(%rbp),%rdi
mov    -0x44c(%rbp),%edx
lea    0xa50(%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    165c <execute_cgi+0x3fc>
lea    0xa39(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    0xa38(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xa33(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    16ed <execute_cgi+0x48d>
movl   $0x0,-0x440(%rbp)
mov    -0x440(%rbp),%eax
cmp    -0x44c(%rbp),%eax
jge    16e8 <execute_cgi+0x488>
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    1695 <execute_cgi+0x435>
jmp    16ed <execute_cgi+0x48d>
jmp    16f2 <execute_cgi+0x492>
mov    -0x428(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
call   10e0 <read@plt>
cmp    $0x0,%rax
jle    172e <execute_cgi+0x4ce>
mov    -0x4(%rbp),%edi
lea    -0x441(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
jmp    16f2 <execute_cgi+0x492>
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,%r15
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r12d
movw   $0x41,0x130(%rsp)
lea    0xd62(%rip),%rsi
mov    %rdx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1397 <execute_cgi+0x127>
lea    0x130(%rsp),%r13
mov    %r13,%rdi
call   1080 <strlen@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1070 <get_line@plt>
mov    %eax,%ebp
lea    0xd3c(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
test   %ebp,%ebp
jle    1548 <execute_cgi+0x2d8>
mov    %rbx,0x18(%rsp)
mov    %r15,0x20(%rsp)
mov    %r14,0x28(%rsp)
mov    $0xffffffff,%r13d
lea    0xd40(%rip),%r14
lea    0x130(%rsp),%r15
lea    0xd08(%rip),%rbx
lea    0xd0a(%rip),%rbp
jmp    1339 <execute_cgi+0xc9>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1080 <strlen@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1070 <get_line@plt>
test   %eax,%eax
jle    1380 <execute_cgi+0x110>
mov    %r14,%rdi
mov    %r15,%rsi
call   1110 <strcmp@plt>
test   %rax,%rax
je     1380 <execute_cgi+0x110>
movb   $0x0,0x13f(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1320 <execute_cgi+0xb0>
lea    0x140(%rsp),%rdi
call   1150 <atoi@plt>
mov    %eax,%r13d
jmp    1320 <execute_cgi+0xb0>
lea    0xcf7(%rip),%rdi
call   1050 <puts@plt>
cmp    $0xffffffff,%r13d
jne    1408 <execute_cgi+0x198>
jmp    1554 <execute_cgi+0x2e4>
mov    %rbx,0x18(%rsp)
mov    %r15,0x20(%rsp)
mov    %r14,0x28(%rsp)
lea    0xc96(%rip),%r14
lea    0x130(%rsp),%rbx
lea    0xc48(%rip),%r15
mov    $0xffffffff,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1110 <strcmp@plt>
test   %rax,%rax
je     1408 <execute_cgi+0x198>
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <get_line@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
test   %ebp,%ebp
jg     13d0 <execute_cgi+0x160>
movups 0xc24(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movw   $0xa,0x140(%rsp)
lea    0x130(%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   10e0 <pipe@plt>
test   %rax,%rax
js     153e <execute_cgi+0x2ce>
lea    0x10(%rsp),%rdi
call   10e0 <pipe@plt>
test   %rax,%rax
js     153e <execute_cgi+0x2ce>
xor    %eax,%eax
call   1190 <fork@plt>
test   %rax,%rax
js     153e <execute_cgi+0x2ce>
je     156e <execute_cgi+0x2fe>
mov    %rax,%rbp
lea    0xbf3(%rip),%rsi
mov    0x18(%rsp),%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    14c9 <execute_cgi+0x259>
test   %r13d,%r13d
jle    14c9 <execute_cgi+0x259>
lea    0x30(%rsp),%rbx
nop
mov    %r12d,%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,%r13d
jne    14a0 <execute_cgi+0x230>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0x1,%edx
call   10f0 <read@plt>
test   %rax,%rax
jle    1518 <execute_cgi+0x2a8>
lea    0x30(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%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   10f0 <read@plt>
test   %rax,%rax
jg     14f0 <execute_cgi+0x280>
mov    0x8(%rsp),%edi
call   10d0 <close@plt>
mov    0x14(%rsp),%edi
call   10d0 <close@plt>
lea    0x530(%rsp),%rsi
mov    %rbp,%rdi
xor    %edx,%edx
call   1130 <waitpid@plt>
jmp    155c <execute_cgi+0x2ec>
mov    %r12d,%edi
call   1140 <cannot_execute@plt>
jmp    155c <execute_cgi+0x2ec>
lea    0xb2f(%rip),%rdi
call   1050 <puts@plt>
mov    %r12d,%edi
call   1120 <bad_request@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   10d0 <close@plt>
mov    0x14(%rsp),%edi
call   10d0 <close@plt>
lea    0xaa5(%rip),%rsi
lea    0x530(%rsp),%rbx
mov    %rbx,%rdi
mov    0x18(%rsp),%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1160 <sprintf@plt>
mov    %rbx,%rdi
call   1100 <putenv@plt>
lea    0xa37(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    15f9 <execute_cgi+0x389>
lea    0xa7a(%rip),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    0x20(%rsp),%rdx
call   10c0 <snprintf@plt>
mov    %rbx,%rdi
call   1100 <putenv@plt>
jmp    160f <execute_cgi+0x39f>
lea    0xa67(%rip),%rsi
lea    0x30(%rsp),%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1160 <sprintf@plt>
mov    0x28(%rsp),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1180 <execl@plt>
test   %rax,%rax
jns    162f <execute_cgi+0x3bf>
lea    0xa7b(%rip),%rdi
call   1050 <puts@plt>
lea    0xa5c(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1170 <exit@plt>

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

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