#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__ mem_case_equal(char const *, char const *, size_t);
scalar_t__ mem_equal(char const *, char *, int);
int /*<<< orphan*/ strcspn(char const *, char *);
size_t strlen(char const *);
int strspn(char const *, char *);
const char *find_header_value(const char *str, const char *field) {
  size_t len = strlen(field);
  while (*str && !mem_equal(str, "\r\n", 2)) {
    if (mem_case_equal(str, field, len) && str[len] == ':') {
      str += len + 1;
      return str + strspn(str, " \t");
    }
    str += strcspn(str, "\r");
    str += mem_equal(str, "\r\n", 2) ? 2 : 0;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_header_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     11a3 <find_header_value+0x53>
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
mov    $0x2,%edx
call   1060 <mem_equal@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11b3 <find_header_value+0x63>
jmp    1279 <find_header_value+0x129>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <mem_case_equal@plt>
cmp    $0x0,%rax
je     1220 <find_header_value+0xd0>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    1220 <find_header_value+0xd0>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1040 <strspn@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1281 <find_header_value+0x131>
mov    -0x10(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1050 <strcspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdb5(%rip),%rsi
mov    $0x2,%edx
call   1060 <mem_equal@plt>
mov    %rax,%rdx
xor    %ecx,%ecx
mov    $0x2,%eax
cmp    $0x0,%rdx
cmovne %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    116d <find_header_value+0x1d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_header_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmpb   $0x0,(%rbx)
je     1216 <find_header_value+0xc6>
mov    %rax,%r13
lea    0xe84(%rip),%r12
lea    0xe83(%rip),%rbp
jmp    11c4 <find_header_value+0x74>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcspn@plt>
movslq %eax,%r14
add    %rbx,%r14
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1060 <mem_equal@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%r14,%rcx,2),%rbx
cmpb   $0x0,(%r14,%rcx,2)
je     1216 <find_header_value+0xc6>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1060 <mem_equal@plt>
test   %rax,%rax
jne    1216 <find_header_value+0xc6>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1070 <mem_case_equal@plt>
test   %rax,%rax
je     1190 <find_header_value+0x40>
cmpb   $0x3a,(%rbx,%r13,1)
jne    1190 <find_header_value+0x40>
lea    (%rbx,%r13,1),%rbp
lea    (%rbx,%r13,1),%rdi
add    $0x1,%rdi
lea    0xdfd(%rip),%rsi
call   1040 <strspn@plt>
cltq
add    %rbp,%rax
add    $0x1,%rax
jmp    1218 <find_header_value+0xc8>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [3 x i8] c" \09\00"
@.str.2 = [2 x i8] c"\0D\00"
define i8* @find_header_value(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
br label %9
9: ; preds = %44, %2
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = call i64 @mem_equal(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%17 = icmp ne i64 %16, 0
%18 = xor i1 %17, true
br label %19
19: ; preds = %14, %9
%20 = phi i1 [ false, %9 ], [ %18, %14 ]
br i1 %20, label %21, label %58
21: ; preds = %19
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = call i64 @mem_case_equal(i8* %22, i8* %23, i64 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %44
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = load i64, i64* %6
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 58
br i1 %33, label %34, label %44
34: ; preds = %27
%35 = load i64, i64* %6
%36 = add i64 %35, 1
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 %36
store i8* %38, i8** %4
%39 = load i8*, i8** %4
%40 = load i8*, i8** %4
%41 = call i32 @strspn(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8* %43, i8** %3
br label %59
44: ; preds = %27, %21
%45 = load i8*, i8** %4
%46 = call i32 @strcspn(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%47 = load i8*, i8** %4
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8* %49, i8** %4
%50 = load i8*, i8** %4
%51 = call i64 @mem_equal(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%52 = icmp ne i64 %51, 0
%53 = zext i1 %52 to i64
%54 = select i1 %52, i32 2, i32 0
%55 = load i8*, i8** %4
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8, i8* %55, i64 %56
store i8* %57, i8** %4
br label %9
58: ; preds = %19
store i8* null, i8** %3
br label %59
59: ; preds = %58, %34
%60 = load i8*, i8** %3
ret i8* %60
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [3 x i8] c" \09\00"
@.str.2 = [2 x i8] c"\0D\00"
define i8* @find_header_value(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %33, label %6
6: ; preds = %2, %23
%7 = phi i8* [ %30, %23 ], [ %0, %2 ]
%8 = tail call i64 @mem_equal(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %6
%11 = tail call i64 @mem_case_equal(i8* %7, i8* %1, i64 %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %7, i64 %3
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 58
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = add i64 %3, 1
%19 = getelementptr inbounds i8, i8* %7, i64 %18
%20 = tail call i32 @strspn(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
br label %33
23: ; preds = %13, %10
%24 = tail call i32 @strcspn(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %7, i64 %25
%27 = tail call i64 @mem_equal(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i64 0, i64 2
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %6
33: ; preds = %23, %6, %2, %17
%34 = phi i8* [ %22, %17 ], [ null, %2 ], [ null, %6 ], [ null, %23 ]
ret i8* %34
}