#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 */
scalar_t__ memcmp(unsigned char *, char *, int);
unsigned char *memstr(unsigned char const *, size_t const, unsigned char *,
                      int);
int /*<<< orphan*/ strchr(char *, int);
unsigned char *find_http_req(const unsigned char *data, const size_t len,
                             unsigned char **http, size_t *httplen) {
  unsigned char *req, *le, *blankline, *hosthdr;
  if (len < 40)
    return (unsigned char *)data;
  if (!(req = memstr(data, len, (unsigned char *)"GET ", 4)))
    return (unsigned char *)(data + len - 4);
  if (!(le = memstr(req + 4, (len - (data - (req + 4))),
                    (unsigned char *)"\r\n", 2))) {
    if ((len - (data - (req + 4))) > 16384)
      return (unsigned char *)(req + 4);
    else
      return (unsigned char *)req;
  }
  if (le < req + 5)
    return le + 2;
  if (memcmp(le - 9, " HTTP/1.", 8) || !strchr("01", (int)*(le - 1)))
    return le + 2;
  if (!(blankline = memstr(le + 2, (len - (data - (le + 2))),
                           (unsigned char *)"\r\n\r\n", 4))) {
    if ((len - (data - (le + 2))) > 16384)
      return (unsigned char *)(data + len - 4);
    else
      return req;
  }
  if (memcmp(req + 4, "http://", 7) == 0)
    goto found;
  if (!(hosthdr =
            memstr(le, blankline - le + 2, (unsigned char *)"\r\nHost: ", 8))) {
    return blankline + 4;
  }
found:
  *http = req;
  *httplen = blankline - req;
  return blankline + 4;
}


x86 assembly (clang, -O0):
<find_http_req>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x28,-0x18(%rbp)
jae    1160 <find_http_req+0x30>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <find_http_req+0x27a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe91(%rip),%rdx
mov    $0x4,%ecx
call   1040 <memstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    119c <find_http_req+0x6c>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <find_http_req+0x27a>
mov    -0x30(%rbp),%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    $0x4,%rcx
sub    %rcx,%rax
sub    %rax,%rsi
lea    0xe52(%rip),%rdx
mov    $0x2,%ecx
call   1040 <memstr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1219 <find_http_req+0xe9>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%rdx
add    $0x4,%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
cmp    $0x4000,%rax
jbe    120c <find_http_req+0xdc>
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <find_http_req+0x27a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <find_http_req+0x27a>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    $0x5,%rcx
cmp    %rcx,%rax
jae    123f <find_http_req+0x10f>
mov    -0x38(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <find_http_req+0x27a>
mov    -0x38(%rbp),%rdi
add    $0xfffffffffffffff7,%rdi
lea    0xdb7(%rip),%rsi
mov    $0x8,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    127f <find_http_req+0x14f>
mov    -0x38(%rbp),%rax
movzbl -0x1(%rax),%esi
lea    0xd9d(%rip),%rdi
call   1030 <strchr@plt>
cmp    $0x0,%eax
jne    1290 <find_http_req+0x160>
mov    -0x38(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <find_http_req+0x27a>
mov    -0x38(%rbp),%rdi
add    $0x2,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    $0x2,%rcx
sub    %rcx,%rax
sub    %rax,%rsi
lea    0xd5c(%rip),%rdx
mov    $0x4,%ecx
call   1040 <memstr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1311 <find_http_req+0x1e1>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x38(%rbp),%rdx
add    $0x2,%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
cmp    $0x4000,%rax
jbe    1304 <find_http_req+0x1d4>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <find_http_req+0x27a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <find_http_req+0x27a>
mov    -0x30(%rbp),%rdi
add    $0x4,%rdi
lea    0xcf6(%rip),%rsi
mov    $0x7,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    1339 <find_http_req+0x209>
jmp    1381 <find_http_req+0x251>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rax
sub    %rax,%rsi
add    $0x2,%rsi
lea    0xccb(%rip),%rdx
mov    $0x8,%ecx
call   1040 <memstr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    137c <find_http_req+0x24c>
mov    -0x40(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <find_http_req+0x27a>
jmp    1381 <find_http_req+0x251>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%rax
sub    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_http_req>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
cmp    $0x28,%rsi
jae    114f <find_http_req+0x1f>
mov    %r12,%r13
jmp    129b <find_http_req+0x16b>
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %rsi,%r15
lea    0xea1(%rip),%rdx
mov    %r12,%rdi
mov    $0x4,%ecx
call   1040 <memstr@plt>
test   %rax,%rax
je     1293 <find_http_req+0x163>
mov    %rax,%r13
mov    %rbx,0x8(%rsp)
mov    %rbp,0x10(%rsp)
lea    0x4(%rax),%rbx
mov    %rbx,%r14
sub    %r12,%r14
add    %r15,%r14
lea    0xe7d(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%ecx
call   1040 <memstr@plt>
test   %rax,%rax
je     11dd <find_http_req+0xad>
mov    %rax,%rbp
lea    0x5(%r13),%rax
cmp    %rax,%rbp
jb     11d1 <find_http_req+0xa1>
lea    -0x9(%rbp),%rdi
lea    0xe43(%rip),%rsi
mov    $0x8,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11ed <find_http_req+0xbd>
add    $0x2,%rbp
mov    %rbp,%r13
jmp    129b <find_http_req+0x16b>
cmp    $0x4001,%r14
cmovae %rbx,%r13
jmp    129b <find_http_req+0x16b>
movzbl -0x1(%rbp),%esi
lea    0xe16(%rip),%rdi
call   1030 <strchr@plt>
test   %eax,%eax
je     11d1 <find_http_req+0xa1>
lea    0x2(%rbp),%rdi
mov    %rdi,%r14
sub    %r12,%r14
add    %r15,%r14
lea    0xdfc(%rip),%rdx
mov    %r14,%rsi
mov    $0x4,%ecx
call   1040 <memstr@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     128a <find_http_req+0x15a>
lea    0xde4(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
mov    (%rsp),%rbx
je     126b <find_http_req+0x13b>
mov    %rbx,%rsi
sub    %rbp,%rsi
add    $0x2,%rsi
lea    0xdc5(%rip),%rdx
mov    %rbp,%rdi
mov    $0x8,%ecx
call   1040 <memstr@plt>
test   %rax,%rax
je     1281 <find_http_req+0x151>
mov    0x8(%rsp),%rax
mov    %r13,(%rax)
mov    %rbx,%rax
sub    %r13,%rax
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
add    $0x4,%rbx
mov    %rbx,%r13
jmp    129b <find_http_req+0x16b>
cmp    $0x4001,%r14
jb     129b <find_http_req+0x16b>
lea    (%r12,%r15,1),%r13
add    $0xfffffffffffffffc,%r13
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"GET \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [9 x i8] c" HTTP/1.\00"
@.str.3 = [3 x i8] c"01\00"
@.str.4 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.5 = [8 x i8] c"http://\00"
@.str.6 = [9 x i8] c"\0D\0AHost: \00"
define i8* @find_http_req(i8* %0, i64 %1, i8** %2, i64* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8**
%9 = alloca i64*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8** %2, i8*** %8
store i64* %3, i64** %9
%14 = load i64, i64* %7
%15 = icmp ult i64 %14, 40
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = load i8*, i8** %6
store i8* %17, i8** %5
br label %140
18: ; preds = %4
%19 = load i8*, i8** %6
%20 = load i64, i64* %7
%21 = call i8* @memstr(i8* %19, i64 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
store i8* %21, i8** %10
%22 = icmp ne i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = load i64, i64* %7
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 -4
store i8* %27, i8** %5
br label %140
28: ; preds = %18
%29 = load i8*, i8** %10
%30 = getelementptr inbounds i8, i8* %29, i64 4
%31 = load i64, i64* %7
%32 = load i8*, i8** %6
%33 = load i8*, i8** %10
%34 = getelementptr inbounds i8, i8* %33, i64 4
%35 = ptrtoint i8* %32 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = sub i64 %31, %37
%39 = call i8* @memstr(i8* %30, i64 %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
store i8* %39, i8** %11
%40 = icmp ne i8* %39, null
br i1 %40, label %56, label %41
41: ; preds = %28
%42 = load i64, i64* %7
%43 = load i8*, i8** %6
%44 = load i8*, i8** %10
%45 = getelementptr inbounds i8, i8* %44, i64 4
%46 = ptrtoint i8* %43 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
%49 = sub i64 %42, %48
%50 = icmp ugt i64 %49, 16384
br i1 %50, label %51, label %54
51: ; preds = %41
%52 = load i8*, i8** %10
%53 = getelementptr inbounds i8, i8* %52, i64 4
store i8* %53, i8** %5
br label %140
54: ; preds = %41
%55 = load i8*, i8** %10
store i8* %55, i8** %5
br label %140
56: ; preds = %28
%57 = load i8*, i8** %11
%58 = load i8*, i8** %10
%59 = getelementptr inbounds i8, i8* %58, i64 5
%60 = icmp ult i8* %57, %59
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i8*, i8** %11
%63 = getelementptr inbounds i8, i8* %62, i64 2
store i8* %63, i8** %5
br label %140
64: ; preds = %56
%65 = load i8*, i8** %11
%66 = getelementptr inbounds i8, i8* %65, i64 -9
%67 = call i64 @memcmp(i8* %66, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%68 = icmp ne i64 %67, 0
br i1 %68, label %76, label %69
69: ; preds = %64
%70 = load i8*, i8** %11
%71 = getelementptr inbounds i8, i8* %70, i64 -1
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = call i32 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %73)
%75 = icmp ne i32 %74, 0
br i1 %75, label %79, label %76
76: ; preds = %69, %64
%77 = load i8*, i8** %11
%78 = getelementptr inbounds i8, i8* %77, i64 2
store i8* %78, i8** %5
br label %140
79: ; preds = %69
%80 = load i8*, i8** %11
%81 = getelementptr inbounds i8, i8* %80, i64 2
%82 = load i64, i64* %7
%83 = load i8*, i8** %6
%84 = load i8*, i8** %11
%85 = getelementptr inbounds i8, i8* %84, i64 2
%86 = ptrtoint i8* %83 to i64
%87 = ptrtoint i8* %85 to i64
%88 = sub i64 %86, %87
%89 = sub i64 %82, %88
%90 = call i8* @memstr(i8* %81, i64 %89, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
store i8* %90, i8** %12
%91 = icmp ne i8* %90, null
br i1 %91, label %109, label %92
92: ; preds = %79
%93 = load i64, i64* %7
%94 = load i8*, i8** %6
%95 = load i8*, i8** %11
%96 = getelementptr inbounds i8, i8* %95, i64 2
%97 = ptrtoint i8* %94 to i64
%98 = ptrtoint i8* %96 to i64
%99 = sub i64 %97, %98
%100 = sub i64 %93, %99
%101 = icmp ugt i64 %100, 16384
br i1 %101, label %102, label %107
102: ; preds = %92
%103 = load i8*, i8** %6
%104 = load i64, i64* %7
%105 = getelementptr inbounds i8, i8* %103, i64 %104
%106 = getelementptr inbounds i8, i8* %105, i64 -4
store i8* %106, i8** %5
br label %140
107: ; preds = %92
%108 = load i8*, i8** %10
store i8* %108, i8** %5
br label %140
109: ; preds = %79
%110 = load i8*, i8** %10
%111 = getelementptr inbounds i8, i8* %110, i64 4
%112 = call i64 @memcmp(i8* %111, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 7)
%113 = icmp eq i64 %112, 0
br i1 %113, label %114, label %115
114: ; preds = %109
br label %129
115: ; preds = %109
%116 = load i8*, i8** %11
%117 = load i8*, i8** %12
%118 = load i8*, i8** %11
%119 = ptrtoint i8* %117 to i64
%120 = ptrtoint i8* %118 to i64
%121 = sub i64 %119, %120
%122 = add nsw i64 %121, 2
%123 = call i8* @memstr(i8* %116, i64 %122, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 8)
store i8* %123, i8** %13
%124 = icmp ne i8* %123, null
br i1 %124, label %128, label %125
125: ; preds = %115
%126 = load i8*, i8** %12
%127 = getelementptr inbounds i8, i8* %126, i64 4
store i8* %127, i8** %5
br label %140
128: ; preds = %115
br label %129
129: ; preds = %128, %114
%130 = load i8*, i8** %10
%131 = load i8**, i8*** %8
store i8* %130, i8** %131
%132 = load i8*, i8** %12
%133 = load i8*, i8** %10
%134 = ptrtoint i8* %132 to i64
%135 = ptrtoint i8* %133 to i64
%136 = sub i64 %134, %135
%137 = load i64*, i64** %9
store i64 %136, i64* %137
%138 = load i8*, i8** %12
%139 = getelementptr inbounds i8, i8* %138, i64 4
store i8* %139, i8** %5
br label %140
140: ; preds = %129, %125, %107, %102, %76, %61, %54, %51, %23, %16
%141 = load i8*, i8** %5
ret i8* %141
}

LLVM IR (-O2):
@.str = [5 x i8] c"GET \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [9 x i8] c" HTTP/1.\00"
@.str.3 = [3 x i8] c"01\00"
@.str.4 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.5 = [8 x i8] c"http://\00"
@.str.6 = [9 x i8] c"\0D\0AHost: \00"
define i8* @find_http_req(i8* %0, i64 %1, i8** nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = icmp ult i64 %1, 40
br i1 %5, label %68, label %6
6: ; preds = %4
%7 = tail call i8* @memstr(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %0, i64 %1
%11 = getelementptr inbounds i8, i8* %10, i64 -4
br label %68
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %7, i64 4
%14 = ptrtoint i8* %0 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %15, %14
%17 = add i64 %16, %1
%18 = tail call i8* @memstr(i8* %13, i64 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = icmp ugt i64 %17, 16384
%22 = select i1 %21, i8* %13, i8* %7
br label %68
23: ; preds = %12
%24 = getelementptr inbounds i8, i8* %7, i64 5
%25 = icmp ult i8* %18, %24
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = getelementptr inbounds i8, i8* %18, i64 2
br label %68
28: ; preds = %23
%29 = getelementptr inbounds i8, i8* %18, i64 -9
%30 = tail call i64 @memcmp(i8* %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = getelementptr inbounds i8, i8* %18, i64 -1
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = tail call i32 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32, %28
%39 = getelementptr inbounds i8, i8* %18, i64 2
br label %68
40: ; preds = %32
%41 = getelementptr inbounds i8, i8* %18, i64 2
%42 = ptrtoint i8* %41 to i64
%43 = sub i64 %42, %14
%44 = add i64 %43, %1
%45 = tail call i8* @memstr(i8* %41, i64 %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %52
47: ; preds = %40
%48 = icmp ugt i64 %44, 16384
br i1 %48, label %49, label %68
49: ; preds = %47
%50 = getelementptr inbounds i8, i8* %0, i64 %1
%51 = getelementptr inbounds i8, i8* %50, i64 -4
br label %68
52: ; preds = %40
%53 = tail call i64 @memcmp(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 7)
%54 = icmp eq i64 %53, 0
%55 = ptrtoint i8* %45 to i64
br i1 %54, label %64, label %56
56: ; preds = %52
%57 = ptrtoint i8* %18 to i64
%58 = sub i64 2, %57
%59 = add i64 %58, %55
%60 = tail call i8* @memstr(i8* %18, i64 %59, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 8)
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = getelementptr inbounds i8, i8* %45, i64 4
br label %68
64: ; preds = %52, %56
store i8* %7, i8** %2
%65 = ptrtoint i8* %7 to i64
%66 = sub i64 %55, %65
store i64 %66, i64* %3
%67 = getelementptr inbounds i8, i8* %45, i64 4
br label %68
68: ; preds = %47, %20, %4, %64, %62, %49, %38, %26, %9
%69 = phi i8* [ %27, %26 ], [ %39, %38 ], [ %67, %64 ], [ %63, %62 ], [ %51, %49 ], [ %11, %9 ], [ %0, %4 ], [ %22, %20 ], [ %7, %47 ]
ret i8* %69
}