#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ R_OK;
int access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ error(int);
int /*<<< orphan*/ free(char *);
int load(int /*<<< orphan*/ *, char **, size_t *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ respond(int, char *, char *, size_t);
scalar_t__ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
void interpret(const char *path, const char *query) {
  if (access(path, R_OK) == -1) {
    error(403);
    return;
  }
  char *format =
      "QUERY_STRING=\"%s\" REDIRECT_STATUS=200 SCRIPT_FILENAME=\"%s\" php-cgi";
  char command[strlen(format) + (strlen(path) - 2) + (strlen(query) - 2) + 1];
  if (sprintf(command, format, query, path) < 0) {
    error(500);
    return;
  }
  FILE *file = popen(command, "r");
  if (file == NULL) {
    error(500);
    return;
  }
  char *content;
  size_t length;
  if (load(file, &content, &length) == false) {
    error(500);
    return;
  }
  pclose(file);
  char *haystack = content;
  char *needle = strstr(haystack, "\r\n\r\n");
  if (needle == NULL) {
    free(content);
    error(500);
    return;
  }
  char headers[needle + 2 - haystack + 1];
  strncpy(headers, content, needle + 2 - haystack);
  headers[needle + 2 - haystack] = '\0';
  respond(200, headers, needle + 4, length - (needle - haystack + 4));
  free(content);
}


x86 assembly (clang, -O0):
<interpret>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
jne    11ed <interpret+0x3d>
mov    $0x193,%edi
call   1080 <error@plt>
jmp    13cf <interpret+0x21f>
lea    0xe0c(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x78(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    -0x3(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x20(%rbp)
lea    0xc(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x68(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
call   10c0 <sprintf@plt>
cmp    $0x0,%rax
jge    1280 <interpret+0xd0>
mov    $0x1f4,%edi
call   1080 <error@plt>
movl   $0x1,-0x2c(%rbp)
jmp    13c8 <interpret+0x218>
mov    -0x68(%rbp),%rdi
lea    0xdb8(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12b5 <interpret+0x105>
mov    $0x1f4,%edi
call   1080 <error@plt>
movl   $0x1,-0x2c(%rbp)
jmp    13c8 <interpret+0x218>
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   10b0 <load@plt>
cmp    $0x0,%eax
jne    12e5 <interpret+0x135>
mov    $0x1f4,%edi
call   1080 <error@plt>
movl   $0x1,-0x2c(%rbp)
jmp    13c8 <interpret+0x218>
mov    -0x38(%rbp),%rdi
call   1070 <pclose@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
lea    0xd44(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1334 <interpret+0x184>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1f4,%edi
call   1080 <error@plt>
movl   $0x1,-0x2c(%rbp)
jmp    13c8 <interpret+0x218>
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%rax
sub    %rax,%rcx
mov    %rcx,%rax
add    $0x3,%rax
add    $0x12,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x80(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x60(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x58(%rbp),%rax
add    $0x2,%rax
mov    -0x50(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x80(%rbp),%rsi
mov    -0x58(%rbp),%rax
add    $0x2,%rax
mov    -0x50(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,(%rsi,%rax,1)
mov    -0x58(%rbp),%rdx
add    $0x4,%rdx
mov    -0x48(%rbp),%rcx
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp),%rdi
sub    %rdi,%rax
add    $0x4,%rax
sub    %rax,%rcx
mov    $0xc8,%edi
call   1050 <respond@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpret>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
je     12d6 <interpret+0x126>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rsp,%r12
add    %rbx,%rax
add    $0x4e,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
call   10c0 <sprintf@plt>
test   %rax,%rax
js     12f6 <interpret+0x146>
lea    0xe16(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <popen@plt>
test   %rax,%rax
je     12f6 <interpret+0x146>
mov    %rax,%rbx
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
mov    %rax,%rdi
call   10b0 <load@plt>
test   %eax,%eax
je     12f6 <interpret+0x146>
mov    %rbx,%rdi
call   1070 <pclose@plt>
mov    -0x30(%rbp),%r15
lea    0xdd9(%rip),%rsi
mov    %r15,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     12ee <interpret+0x13e>
mov    %rax,%r14
mov    %rax,%r13
sub    %r15,%r13
lea    0x2(%r13),%rdx
lea    0x12(%r13),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strncpy@plt>
movb   $0x0,0x2(%r13,%rbx,1)
mov    -0x38(%rbp),%rax
sub    %r14,%r15
add    $0x4,%r14
lea    (%r15,%rax,1),%rcx
add    $0xfffffffffffffffc,%rcx
mov    $0xc8,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <respond@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1300 <interpret+0x150>
mov    $0x193,%edi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <error@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1f4,%edi
call   1080 <error@plt>
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@R_OK = global i32 0
@.str = [67 x i8] c"QUERY_STRING=\22%s\22 REDIRECT_STATUS=200 SCRIPT_FILENAME=\22%s\22 php-cgi\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"\0D\0A\0D\0A\00"
define void @interpret(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%15 = load i8*, i8** %3
%16 = load i32, i32* @R_OK
%17 = call i32 @access(i8* %15, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @error(i32 403)
br label %107
21: ; preds = %2
store i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8** %5
%22 = load i8*, i8** %5
%23 = call i64 @strlen(i8* %22)
%24 = load i8*, i8** %3
%25 = call i64 @strlen(i8* %24)
%26 = sub nsw i64 %25, 2
%27 = add nsw i64 %23, %26
%28 = load i8*, i8** %4
%29 = call i64 @strlen(i8* %28)
%30 = sub nsw i64 %29, 2
%31 = add nsw i64 %27, %30
%32 = add nsw i64 %31, 1
%33 = call i8* @llvm.stacksave()
store i8* %33, i8** %6
%34 = alloca i8, i64 %32
store i64 %32, i64* %7
%35 = load i8*, i8** %5
%36 = load i8*, i8** %4
%37 = load i8*, i8** %3
%38 = call i64 @sprintf(i8* %34, i8* %35, i8* %36, i8* %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %21
%41 = call i32 @error(i32 500)
store i32 1, i32* %8
br label %104
42: ; preds = %21
%43 = call i32* @popen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %43, i32** %9
%44 = load i32*, i32** %9
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @error(i32 500)
store i32 1, i32* %8
br label %104
48: ; preds = %42
%49 = load i32*, i32** %9
%50 = call i32 @load(i32* %49, i8** %10, i64* %11)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @error(i32 500)
store i32 1, i32* %8
br label %104
54: ; preds = %48
%55 = load i32*, i32** %9
%56 = call i32 @pclose(i32* %55)
%57 = load i8*, i8** %10
store i8* %57, i8** %12
%58 = load i8*, i8** %12
%59 = call i8* @strstr(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %59, i8** %13
%60 = load i8*, i8** %13
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %66
62: ; preds = %54
%63 = load i8*, i8** %10
%64 = call i32 @free(i8* %63)
%65 = call i32 @error(i32 500)
store i32 1, i32* %8
br label %104
66: ; preds = %54
%67 = load i8*, i8** %13
%68 = getelementptr inbounds i8, i8* %67, i64 2
%69 = load i8*, i8** %12
%70 = ptrtoint i8* %68 to i64
%71 = ptrtoint i8* %69 to i64
%72 = sub i64 %70, %71
%73 = add nsw i64 %72, 1
%74 = alloca i8, i64 %73
store i64 %73, i64* %14
%75 = load i8*, i8** %10
%76 = load i8*, i8** %13
%77 = getelementptr inbounds i8, i8* %76, i64 2
%78 = load i8*, i8** %12
%79 = ptrtoint i8* %77 to i64
%80 = ptrtoint i8* %78 to i64
%81 = sub i64 %79, %80
%82 = trunc i64 %81 to i32
%83 = call i32 @strncpy(i8* %74, i8* %75, i32 %82)
%84 = load i8*, i8** %13
%85 = getelementptr inbounds i8, i8* %84, i64 2
%86 = load i8*, i8** %12
%87 = ptrtoint i8* %85 to i64
%88 = ptrtoint i8* %86 to i64
%89 = sub i64 %87, %88
%90 = getelementptr inbounds i8, i8* %74, i64 %89
store i8 0, i8* %90
%91 = load i8*, i8** %13
%92 = getelementptr inbounds i8, i8* %91, i64 4
%93 = load i64, i64* %11
%94 = load i8*, i8** %13
%95 = load i8*, i8** %12
%96 = ptrtoint i8* %94 to i64
%97 = ptrtoint i8* %95 to i64
%98 = sub i64 %96, %97
%99 = add nsw i64 %98, 4
%100 = sub i64 %93, %99
%101 = call i32 @respond(i32 200, i8* %74, i8* %92, i64 %100)
%102 = load i8*, i8** %10
%103 = call i32 @free(i8* %102)
store i32 0, i32* %8
br label %104
104: ; preds = %66, %62, %52, %46, %40
%105 = load i8*, i8** %6
%106 = load i32, i32* %8
switch i32 %106, label %108 [
i32 0, label %107
i32 1, label %107
]
107: ; preds = %19, %104, %104
ret void
108: ; preds = %104
unreachable
}

LLVM IR (-O2):
@R_OK = global i32 0
@.str = [67 x i8] c"QUERY_STRING=\22%s\22 REDIRECT_STATUS=200 SCRIPT_FILENAME=\22%s\22 php-cgi\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"\0D\0A\0D\0A\00"
define void @interpret(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = load i32, i32* @R_OK
%6 = tail call i32 @access(i8* %0, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @error(i32 403)
br label %62
10: ; preds = %2
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%13 = add i64 %11, 63
%14 = add i64 %13, %12
%15 = tail call i8* @llvm.stacksave()
%16 = alloca i8, i64 %14
%17 = call i64 @sprintf(i8* %16, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @error(i32 500)
br label %61
21: ; preds = %10
%22 = call i32* @popen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @error(i32 500)
br label %61
26: ; preds = %21
%27 = bitcast i8** %3 to i8*
%28 = bitcast i64* %4 to i8*
%29 = call i32 @load(i32* %22, i8** %3, i64* %4)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @error(i32 500)
br label %60
33: ; preds = %26
%34 = call i32 @pclose(i32* %22)
%35 = load i8*, i8** %3
%36 = call i8* @strstr(i8* dereferenceable(1) %35, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = call i32 @free(i8* %35)
%40 = call i32 @error(i32 500)
br label %60
41: ; preds = %33
%42 = getelementptr inbounds i8, i8* %36, i64 2
%43 = ptrtoint i8* %42 to i64
%44 = ptrtoint i8* %35 to i64
%45 = sub i64 %43, %44
%46 = add nsw i64 %45, 1
%47 = alloca i8, i64 %46
%48 = trunc i64 %45 to i32
%49 = call i32 @strncpy(i8* %47, i8* %35, i32 %48)
%50 = getelementptr inbounds i8, i8* %47, i64 %45
store i8 0, i8* %50
%51 = getelementptr inbounds i8, i8* %36, i64 4
%52 = load i64, i64* %4
%53 = ptrtoint i8* %36 to i64
%54 = add i64 %44, -4
%55 = sub i64 %54, %53
%56 = add i64 %55, %52
%57 = call i32 @respond(i32 200, i8* %47, i8* %51, i64 %56)
%58 = load i8*, i8** %3
%59 = call i32 @free(i8* %58)
br label %60
60: ; preds = %38, %41, %31
br label %61
61: ; preds = %24, %60, %19
br label %62
62: ; preds = %61, %8
ret void
}