#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 */

/* Variables and functions */
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execl(char const *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fdprintf(int, char *, ...);
int fork();
int /*<<< orphan*/ http_err(int, int, char *, ...);
int /*<<< orphan*/ http_read_line(int, char *, int);
int /*<<< orphan*/ pipe(int *);
int read(int, char *, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void http_serve_executable(int fd, const char *pn) {
  char buf[1024], headers[4096], *pheaders = headers;
  int pipefd[2], statusprinted = 0, ret, headerslen = 4096;
  pipe(pipefd);
  switch (fork()) {
  case -1:
    http_err(fd, 500, "fork: %s", strerror(errno));
    return;
  case 0:
    signal(SIGPIPE, SIG_DFL);
    signal(SIGCHLD, SIG_DFL);
    dup2(fd, 0);
    close(fd);
    dup2(pipefd[1], 1);
    close(pipefd[0]);
    close(pipefd[1]);
    execl(pn, pn, NULL);
    http_err(1, 500, "execl %s: %s", pn, strerror(errno));
    exit(1);
  default:
    close(pipefd[1]);
    while (1) {
      if (http_read_line(pipefd[0], buf, 1024) < 0) {
        http_err(fd, 500, "Premature end of script headers");
        close(pipefd[0]);
        return;
      }
      if (!*buf)
        break;
      if (!statusprinted && strncasecmp("Status: ", buf, 8) == 0) {
        fdprintf(fd, "HTTP/1.0 %s\r\n%s", buf + 8, headers);
        statusprinted = 1;
      } else if (statusprinted) {
        fdprintf(fd, "%s\r\n", buf);
      } else {
        ret = snprintf(pheaders, headerslen, "%s\r\n", buf);
        pheaders += ret;
        headerslen -= ret;
        if (headerslen == 0) {
          http_err(fd, 500, "Too many script headers");
          close(pipefd[0]);
          return;
        }
      }
    }
    if (statusprinted)
      fdprintf(fd, "\r\n");
    else
      fdprintf(fd, "HTTP/1.0 200 OK\r\n%s\r\n", headers);
    while ((ret = read(pipefd[0], buf, 1024)) > 0) {
      write(fd, buf, ret);
    }
    close(fd);
    close(pipefd[0]);
  }
}


x86 assembly (clang, -O0):
<http_serve_executable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1440,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1410(%rbp),%rax
mov    %rax,-0x1418(%rbp)
movl   $0x0,-0x1424(%rbp)
movl   $0x1000,-0x142c(%rbp)
lea    -0x1420(%rbp),%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   1110 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x1430(%rbp)
sub    $0xffffffff,%eax
je     1260 <http_serve_executable+0x70>
jmp    124d <http_serve_executable+0x5d>
mov    -0x1430(%rbp),%eax
test   %eax,%eax
je     1297 <http_serve_executable+0xa7>
jmp    1353 <http_serve_executable+0x163>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1434(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x1434(%rbp),%edi
mov    %eax,%ecx
mov    $0x1f4,%esi
lea    0xd75(%rip),%rdx
mov    $0x0,%al
call   10d0 <http_err@plt>
jmp    1569 <http_serve_executable+0x379>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
mov    -0x141c(%rbp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    -0x1420(%rbp),%edi
call   1070 <close@plt>
mov    -0x141c(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1100 <execl@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x1440(%rbp)
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x1440(%rbp),%rcx
mov    %eax,%r8d
mov    $0x1,%edi
mov    $0x1f4,%esi
lea    0xcc7(%rip),%rdx
mov    $0x0,%al
call   10d0 <http_err@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x141c(%rbp),%edi
call   1070 <close@plt>
mov    -0x1420(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   10b0 <http_read_line@plt>
cmp    $0x0,%eax
jge    13a4 <http_serve_executable+0x1b4>
mov    -0x4(%rbp),%edi
mov    $0x1f4,%esi
lea    0xc89(%rip),%rdx
mov    $0x0,%al
call   10d0 <http_err@plt>
mov    -0x1420(%rbp),%edi
call   1070 <close@plt>
jmp    1569 <http_serve_executable+0x379>
cmpb   $0x0,-0x410(%rbp)
jne    13b6 <http_serve_executable+0x1c6>
jmp    14d6 <http_serve_executable+0x2e6>
cmpl   $0x0,-0x1424(%rbp)
jne    1416 <http_serve_executable+0x226>
lea    -0x410(%rbp),%rsi
lea    0xc65(%rip),%rdi
mov    $0x8,%edx
call   10c0 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1416 <http_serve_executable+0x226>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rdx
add    $0x8,%rdx
lea    -0x1410(%rbp),%rcx
lea    0xc3f(%rip),%rsi
mov    $0x0,%al
call   1040 <fdprintf@plt>
movl   $0x1,-0x1424(%rbp)
jmp    14d1 <http_serve_executable+0x2e1>
cmpl   $0x0,-0x1424(%rbp)
je     1440 <http_serve_executable+0x250>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rdx
lea    0xc44(%rip),%rsi
mov    $0x0,%al
call   1040 <fdprintf@plt>
jmp    14cc <http_serve_executable+0x2dc>
mov    -0x1418(%rbp),%rdi
mov    -0x142c(%rbp),%esi
lea    -0x410(%rbp),%rcx
lea    0xc1d(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x1428(%rbp)
mov    -0x1428(%rbp),%ecx
mov    -0x1418(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1418(%rbp)
mov    -0x1428(%rbp),%ecx
mov    -0x142c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x142c(%rbp)
cmpl   $0x0,-0x142c(%rbp)
jne    14c7 <http_serve_executable+0x2d7>
mov    -0x4(%rbp),%edi
mov    $0x1f4,%esi
lea    0xb9f(%rip),%rdx
mov    $0x0,%al
call   10d0 <http_err@plt>
mov    -0x1420(%rbp),%edi
call   1070 <close@plt>
jmp    1569 <http_serve_executable+0x379>
jmp    14cc <http_serve_executable+0x2dc>
jmp    14d1 <http_serve_executable+0x2e1>
jmp    135e <http_serve_executable+0x16e>
cmpl   $0x0,-0x1424(%rbp)
je     14f9 <http_serve_executable+0x309>
mov    -0x4(%rbp),%edi
lea    0xb8d(%rip),%rsi
mov    $0x0,%al
call   1040 <fdprintf@plt>
jmp    1511 <http_serve_executable+0x321>
mov    -0x4(%rbp),%edi
lea    -0x1410(%rbp),%rdx
lea    0xb5d(%rip),%rsi
mov    $0x0,%al
call   1040 <fdprintf@plt>
jmp    1516 <http_serve_executable+0x326>
mov    -0x1420(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0x1428(%rbp)
cmp    $0x0,%eax
jle    1556 <http_serve_executable+0x366>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x1428(%rbp),%edx
call   1030 <write@plt>
jmp    1516 <http_serve_executable+0x326>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
mov    -0x1420(%rbp),%edi
call   1070 <close@plt>
add    $0x1440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_serve_executable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1418,%rsp
mov    %rsi,%rbx
mov    %edi,%r13d
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   1110 <fork@plt>
cmp    $0xffffffff,%eax
je     130c <http_serve_executable+0x11c>
test   %eax,%eax
je     13f1 <http_serve_executable+0x201>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x400,%edx
call   10b0 <http_read_line@plt>
test   %eax,%eax
js     1337 <http_serve_executable+0x147>
lea    0x410(%rsp),%r14
mov    $0x1000,%ebp
lea    0x10(%rsp),%rbx
lea    0xe12(%rip),%r15
xor    %r12d,%r12d
jmp    129f <http_serve_executable+0xaf>
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fdprintf@plt>
mov    $0x1,%r12d
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   10b0 <http_read_line@plt>
test   %eax,%eax
js     1337 <http_serve_executable+0x147>
cmpb   $0x0,0x10(%rsp)
je     134f <http_serve_executable+0x15f>
test   %r12d,%r12d
jne    1270 <http_serve_executable+0x80>
lea    0xd80(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   10c0 <strncasecmp@plt>
test   %eax,%eax
je     12e9 <http_serve_executable+0xf9>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1060 <snprintf@plt>
sub    %eax,%ebp
je     13e5 <http_serve_executable+0x1f5>
cltq
add    %rax,%r14
xor    %r12d,%r12d
jmp    1286 <http_serve_executable+0x96>
mov    %r13d,%edi
lea    0xd4c(%rip),%rsi
lea    0x18(%rsp),%rdx
lea    0x410(%rsp),%rcx
xor    %eax,%eax
call   1040 <fdprintf@plt>
jmp    1280 <http_serve_executable+0x90>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xcdf(%rip),%rdx
mov    %r13d,%edi
mov    $0x1f4,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   10d0 <http_err@plt>
jmp    13d3 <http_serve_executable+0x1e3>
lea    0xcd8(%rip),%rdx
mov    %r13d,%edi
mov    $0x1f4,%esi
xor    %eax,%eax
call   10d0 <http_err@plt>
jmp    13ca <http_serve_executable+0x1da>
test   %r12d,%r12d
je     1367 <http_serve_executable+0x177>
lea    0xd1f(%rip),%rsi
mov    %r13d,%edi
xor    %eax,%eax
call   1040 <fdprintf@plt>
jmp    1380 <http_serve_executable+0x190>
lea    0xcf9(%rip),%rsi
lea    0x410(%rsp),%rdx
mov    %r13d,%edi
xor    %eax,%eax
call   1040 <fdprintf@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    13c2 <http_serve_executable+0x1d2>
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
jg     13a0 <http_serve_executable+0x1b0>
mov    %r13d,%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
add    $0x1418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc63(%rip),%rdx
jmp    133e <http_serve_executable+0x14e>
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
mov    0x2bc7(%rip),%rbp
mov    0x0(%rbp),%esi
call   10a0 <signal@plt>
mov    0x2bd8(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%esi
call   10a0 <signal@plt>
mov    %r13d,%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    %r13d,%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1100 <execl@plt>
mov    0x2b70(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xb9b(%rip),%rdx
mov    $0x1,%edi
mov    $0x1f4,%esi
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   10d0 <http_err@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"fork: %s\00"
@errno = global i32 0
@SIGPIPE = global i32 0
@SIG_DFL = global i32 0
@SIGCHLD = global i32 0
@.str.1 = [13 x i8] c"execl %s: %s\00"
@.str.2 = [32 x i8] c"Premature end of script headers\00"
@.str.3 = [9 x i8] c"Status: \00"
@.str.4 = [16 x i8] c"HTTP/1.0 %s\0D\0A%s\00"
@.str.5 = [5 x i8] c"%s\0D\0A\00"
@.str.6 = [24 x i8] c"Too many script headers\00"
@.str.7 = [3 x i8] c"\0D\0A\00"
@.str.8 = [22 x i8] c"HTTP/1.0 200 OK\0D\0A%s\0D\0A\00"
define void @http_serve_executable(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca [4096 x i8]
%7 = alloca i8*
%8 = alloca [2 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
store i8* %12, i8** %7
store i32 0, i32* %9
store i32 4096, i32* %11
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = call i32 (...) @fork()
switch i32 %15, label %49 [
i32 -1, label %16
i32 0, label %21
]
16: ; preds = %2
%17 = load i32, i32* %3
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 (i32, i32, i8*, ...) @http_err(i32 %17, i32 500, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %141
21: ; preds = %2
%22 = load i32, i32* @SIGPIPE
%23 = load i32, i32* @SIG_DFL
%24 = call i32 @signal(i32 %22, i32 %23)
%25 = load i32, i32* @SIGCHLD
%26 = load i32, i32* @SIG_DFL
%27 = call i32 @signal(i32 %25, i32 %26)
%28 = load i32, i32* %3
%29 = call i32 @dup2(i32 %28, i32 0)
%30 = load i32, i32* %3
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @dup2(i32 %33, i32 1)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = load i8*, i8** %4
%42 = load i8*, i8** %4
%43 = call i32 @execl(i8* %41, i8* %42, i32* null)
%44 = load i8*, i8** %4
%45 = load i32, i32* @errno
%46 = call i32 @strerror(i32 %45)
%47 = call i32 (i32, i32, i8*, ...) @http_err(i32 1, i32 500, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %44, i32 %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %2
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
br label %53
53: ; preds = %49, %112
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%55 = load i32, i32* %54
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%57 = call i32 @http_read_line(i32 %55, i8* %56, i32 1024)
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %53
%60 = load i32, i32* %3
%61 = call i32 (i32, i32, i8*, ...) @http_err(i32 %60, i32 500, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
br label %141
65: ; preds = %53
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%67 = load i8, i8* %66
%68 = icmp ne i8 %67, 0
br i1 %68, label %70, label %69
69: ; preds = %65
br label %113
70: ; preds = %65
%71 = load i32, i32* %9
%72 = icmp ne i32 %71, 0
br i1 %72, label %83, label %73
73: ; preds = %70
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%75 = call i32 @strncasecmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %74, i32 8)
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %83
77: ; preds = %73
%78 = load i32, i32* %3
%79 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%80 = getelementptr inbounds i8, i8* %79, i64 8
%81 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%82 = call i32 (i32, i8*, ...) @fdprintf(i32 %78, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %80, i8* %81)
store i32 1, i32* %9
br label %112
83: ; preds = %73, %70
%84 = load i32, i32* %9
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %90
86: ; preds = %83
%87 = load i32, i32* %3
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%89 = call i32 (i32, i8*, ...) @fdprintf(i32 %87, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %88)
br label %111
90: ; preds = %83
%91 = load i8*, i8** %7
%92 = load i32, i32* %11
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%94 = call i32 @snprintf(i8* %91, i32 %92, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %93)
store i32 %94, i32* %10
%95 = load i32, i32* %10
%96 = load i8*, i8** %7
%97 = sext i32 %95 to i64
%98 = getelementptr inbounds i8, i8* %96, i64 %97
store i8* %98, i8** %7
%99 = load i32, i32* %10
%100 = load i32, i32* %11
%101 = sub nsw i32 %100, %99
store i32 %101, i32* %11
%102 = load i32, i32* %11
%103 = icmp eq i32 %102, 0
br i1 %103, label %104, label %110
104: ; preds = %90
%105 = load i32, i32* %3
%106 = call i32 (i32, i32, i8*, ...) @http_err(i32 %105, i32 500, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%108 = load i32, i32* %107
%109 = call i32 @close(i32 %108)
br label %141
110: ; preds = %90
br label %111
111: ; preds = %110, %86
br label %112
112: ; preds = %111, %77
br label %53
113: ; preds = %69
%114 = load i32, i32* %9
%115 = icmp ne i32 %114, 0
br i1 %115, label %116, label %119
116: ; preds = %113
%117 = load i32, i32* %3
%118 = call i32 (i32, i8*, ...) @fdprintf(i32 %117, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %123
119: ; preds = %113
%120 = load i32, i32* %3
%121 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%122 = call i32 (i32, i8*, ...) @fdprintf(i32 %120, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %121)
br label %123
123: ; preds = %119, %116
br label %124
124: ; preds = %130, %123
%125 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%126 = load i32, i32* %125
%127 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%128 = call i32 @read(i32 %126, i8* %127, i32 1024)
store i32 %128, i32* %10
%129 = icmp sgt i32 %128, 0
br i1 %129, label %130, label %135
130: ; preds = %124
%131 = load i32, i32* %3
%132 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%133 = load i32, i32* %10
%134 = call i32 @write(i32 %131, i8* %132, i32 %133)
br label %124
135: ; preds = %124
%136 = load i32, i32* %3
%137 = call i32 @close(i32 %136)
%138 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%139 = load i32, i32* %138
%140 = call i32 @close(i32 %139)
br label %141
141: ; preds = %16, %59, %104, %135
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"fork: %s\00"
@errno = global i32 0
@SIGPIPE = global i32 0
@SIG_DFL = global i32 0
@SIGCHLD = global i32 0
@.str.1 = [13 x i8] c"execl %s: %s\00"
@.str.2 = [32 x i8] c"Premature end of script headers\00"
@.str.3 = [9 x i8] c"Status: \00"
@.str.4 = [16 x i8] c"HTTP/1.0 %s\0D\0A%s\00"
@.str.5 = [5 x i8] c"%s\0D\0A\00"
@.str.6 = [24 x i8] c"Too many script headers\00"
@.str.7 = [3 x i8] c"\0D\0A\00"
@.str.8 = [22 x i8] c"HTTP/1.0 200 OK\0D\0A%s\0D\0A\00"
define void @http_serve_executable(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [4096 x i8]
%5 = alloca [2 x i32]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = bitcast [2 x i32]* %5 to i8*
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = call i32 (...) @fork()
switch i32 %11, label %37 [
i32 -1, label %12
i32 0, label %16
]
12: ; preds = %2
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 (i32, i32, i8*, ...) @http_err(i32 %0, i32 500, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %101
16: ; preds = %2
%17 = load i32, i32* @SIGPIPE
%18 = load i32, i32* @SIG_DFL
%19 = call i32 @signal(i32 %17, i32 %18)
%20 = load i32, i32* @SIGCHLD
%21 = load i32, i32* @SIG_DFL
%22 = call i32 @signal(i32 %20, i32 %21)
%23 = call i32 @dup2(i32 %0, i32 0)
%24 = call i32 @close(i32 %0)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @dup2(i32 %26, i32 1)
%28 = load i32, i32* %9
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %25
%31 = call i32 @close(i32 %30)
%32 = call i32 @execl(i8* %1, i8* %1, i32* null)
%33 = load i32, i32* @errno
%34 = call i32 @strerror(i32 %33)
%35 = call i32 (i32, i32, i8*, ...) @http_err(i32 1, i32 500, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %2
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %9
%42 = call i32 @http_read_line(i32 %41, i8* %6, i32 1024)
%43 = icmp slt i32 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %37
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 8
br label %50
46: ; preds = %75, %37
%47 = call i32 (i32, i32, i8*, ...) @http_err(i32 %0, i32 500, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* %9
%49 = call i32 @close(i32 %48)
br label %101
50: ; preds = %44, %75
%51 = phi i32 [ 4096, %44 ], [ %78, %75 ]
%52 = phi i32 [ 0, %44 ], [ %77, %75 ]
%53 = phi i8* [ %7, %44 ], [ %76, %75 ]
%54 = load i8, i8* %6
%55 = icmp eq i8 %54, 0
%56 = icmp eq i32 %52, 0
br i1 %55, label %82, label %57
57: ; preds = %50
br i1 %56, label %58, label %63
58: ; preds = %57
%59 = call i32 @strncasecmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 8)
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = call i32 (i32, i8*, ...) @fdprintf(i32 %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %45, i8* %7)
br label %75
63: ; preds = %57
%64 = call i32 (i32, i8*, ...) @fdprintf(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %6)
br label %75
65: ; preds = %58
%66 = call i32 @snprintf(i8* %53, i32 %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %53, i64 %67
%69 = sub nsw i32 %51, %66
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %65
%72 = call i32 (i32, i32, i8*, ...) @http_err(i32 %0, i32 500, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%73 = load i32, i32* %9
%74 = call i32 @close(i32 %73)
br label %101
75: ; preds = %63, %65, %61
%76 = phi i8* [ %53, %63 ], [ %68, %65 ], [ %53, %61 ]
%77 = phi i32 [ 1, %63 ], [ 0, %65 ], [ 1, %61 ]
%78 = phi i32 [ %51, %63 ], [ %69, %65 ], [ %51, %61 ]
%79 = load i32, i32* %9
%80 = call i32 @http_read_line(i32 %79, i8* %6, i32 1024)
%81 = icmp slt i32 %80, 0
br i1 %81, label %46, label %50
82: ; preds = %50
br i1 %56, label %85, label %83
83: ; preds = %82
%84 = call i32 (i32, i8*, ...) @fdprintf(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %87
85: ; preds = %82
%86 = call i32 (i32, i8*, ...) @fdprintf(i32 %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %7)
br label %87
87: ; preds = %85, %83
%88 = load i32, i32* %9
%89 = call i32 @read(i32 %88, i8* %6, i32 1024)
%90 = icmp sgt i32 %89, 0
br i1 %90, label %91, label %97
91: ; preds = %87, %91
%92 = phi i32 [ %95, %91 ], [ %89, %87 ]
%93 = call i32 @write(i32 %0, i8* %6, i32 %92)
%94 = load i32, i32* %9
%95 = call i32 @read(i32 %94, i8* %6, i32 1024)
%96 = icmp sgt i32 %95, 0
br i1 %96, label %91, label %97
97: ; preds = %91, %87
%98 = call i32 @close(i32 %0)
%99 = load i32, i32* %9
%100 = call i32 @close(i32 %99)
br label %101
101: ; preds = %97, %71, %46, %12
ret void
}