#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(char const *, char *, int);
scalar_t__ memmem(char const *, int, char *, int);
int strlen(char const *);
int /*<<< orphan*/ strncasecmp(char const *, char const *, int);
const char *find_header(const char *res, const char *header) {
  const char *line = res;
  while (memcmp(line, "\r\n", 2)) {
    int line_len = (char *)memmem(line, 0x8000, "\r\n", 2) - line;
    int head_len = strlen(header);
    if (line_len > head_len && !strncasecmp(line, header, head_len))
      return line + head_len;
    line += line_len + 2;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x2,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11f9 <find_header+0xb9>
mov    -0x20(%rbp),%rdi
mov    $0x8000,%esi
lea    0xe79(%rip),%rdx
mov    $0x2,%ecx
call   1050 <memmem@plt>
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    11e0 <find_header+0xa0>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11e0 <find_header+0xa0>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <find_header+0xc1>
mov    -0x24(%rbp),%ecx
add    $0x2,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1158 <find_header+0x18>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xeab(%rip),%rsi
mov    $0x2,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     11d0 <find_header+0x90>
lea    0xe95(%rip),%r15
jmp    118e <find_header+0x4e>
nopl   (%rax)
add    $0x2,%ebx
movslq %ebx,%rax
add    %rax,%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     11d0 <find_header+0x90>
mov    %r12,%rdi
mov    $0x8000,%esi
mov    %r15,%rdx
mov    $0x2,%ecx
call   1050 <memmem@plt>
mov    %rax,%rbx
sub    %r12,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %ebx,%eax
jge    1170 <find_header+0x30>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <strncasecmp@plt>
test   %eax,%eax
jne    1170 <find_header+0x30>
movslq %ebp,%rax
add    %rax,%r12
jmp    11d3 <find_header+0x93>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
define i8* @find_header(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
store i8* %9, i8** %6
br label %10
10: ; preds = %39, %2
%11 = load i8*, i8** %6
%12 = call i64 @memcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %45
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = call i64 @memmem(i8* %15, i32 32768, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%17 = inttoptr i64 %16 to i8*
%18 = load i8*, i8** %6
%19 = ptrtoint i8* %17 to i64
%20 = ptrtoint i8* %18 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
store i32 %22, i32* %7
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %8
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %39
28: ; preds = %14
%29 = load i8*, i8** %6
%30 = load i8*, i8** %5
%31 = load i32, i32* %8
%32 = call i32 @strncasecmp(i8* %29, i8* %30, i32 %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %28
%35 = load i8*, i8** %6
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8* %38, i8** %3
br label %46
39: ; preds = %28, %14
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 2
%42 = load i8*, i8** %6
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %6
br label %10
45: ; preds = %10
store i8* null, i8** %3
br label %46
46: ; preds = %45, %34
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
define i8* @find_header(i8* %0, i8* %1) {
%3 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %26, label %5
5: ; preds = %2, %19
%6 = phi i8* [ %23, %19 ], [ %0, %2 ]
%7 = tail call i64 @memmem(i8* %6, i32 32768, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%8 = ptrtoint i8* %6 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = tail call i32 @strlen(i8* %1)
%12 = icmp slt i32 %11, %10
br i1 %12, label %13, label %19
13: ; preds = %5
%14 = tail call i32 @strncasecmp(i8* %6, i8* %1, i32 %11)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = sext i32 %11 to i64
%18 = getelementptr inbounds i8, i8* %6, i64 %17
br label %26
19: ; preds = %5, %13
%20 = shl i64 %9, 32
%21 = add i64 %20, 8589934592
%22 = ashr exact i64 %21, 32
%23 = getelementptr inbounds i8, i8* %6, i64 %22
%24 = tail call i64 @memcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %5
26: ; preds = %19, %2, %16
%27 = phi i8* [ %18, %16 ], [ null, %2 ], [ null, %19 ]
ret i8* %27
}