#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 */
struct _citrus_memory_stream {
  int dummy;
};

/* Variables and functions */
char *_citrus_bcs_skip_nonws_len(char const *, size_t *);
char *_citrus_bcs_skip_ws_len(char const *, size_t *);
scalar_t__ _citrus_bcs_strncasecmp(char const *, char const *, size_t);
int /*<<< orphan*/ _citrus_bcs_trunc_rws_len(char const *, size_t *);
char *_citrus_memory_stream_getln(struct _citrus_memory_stream *, size_t *);
char *memchr(char const *, char, size_t);
scalar_t__ memcmp(char const *, char const *, size_t);
size_t strlen(char const *);
const char *
_citrus_memory_stream_matchline(struct _citrus_memory_stream *__restrict ms,
                                const char *__restrict key,
                                size_t *__restrict rlen, int iscasesensitive) {
  const char *p, *q;
  size_t len, keylen;
  keylen = strlen(key);
  while (1) {
    p = _citrus_memory_stream_getln(ms, &len);
    if (p == NULL)
      return (NULL);
    q = memchr(p, '#', len);
    if (q) {
      len = q - p;
    }
    _citrus_bcs_trunc_rws_len(p, &len);
    if (len == 0)
      continue;
    p = _citrus_bcs_skip_ws_len(p, &len);
    q = _citrus_bcs_skip_nonws_len(p, &len);
    if ((size_t)(q - p) == keylen) {
      if (iscasesensitive) {
        if (memcmp(key, p, keylen) == 0)
          break;
      } else {
        if (_citrus_bcs_strncasecmp(key, p, keylen) == 0)
          break;
      }
    }
  }
  p = _citrus_bcs_skip_ws_len(q, &len);
  *rlen = len;
  return (p);
}


x86 assembly (clang, -O0):
<_citrus_memory_stream_matchline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <_citrus_memory_stream_getln@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11cd <_citrus_memory_stream_matchline+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    12d3 <_citrus_memory_stream_matchline+0x153>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    $0x23,%esi
call   1050 <memchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11fd <_citrus_memory_stream_matchline+0x7d>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <_citrus_bcs_trunc_rws_len@plt>
cmpq   $0x0,-0x40(%rbp)
jne    121a <_citrus_memory_stream_matchline+0x9a>
jmp    11a4 <_citrus_memory_stream_matchline+0x24>
mov    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <_citrus_bcs_skip_ws_len@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <_citrus_bcs_skip_nonws_len@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x48(%rbp),%rax
jne    12aa <_citrus_memory_stream_matchline+0x12a>
cmpl   $0x0,-0x24(%rbp)
je     1280 <_citrus_memory_stream_matchline+0x100>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    127b <_citrus_memory_stream_matchline+0xfb>
jmp    12af <_citrus_memory_stream_matchline+0x12f>
jmp    12a5 <_citrus_memory_stream_matchline+0x125>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1090 <_citrus_bcs_strncasecmp@plt>
cmp    $0x0,%rax
jne    12a0 <_citrus_memory_stream_matchline+0x120>
jmp    12af <_citrus_memory_stream_matchline+0x12f>
jmp    12a5 <_citrus_memory_stream_matchline+0x125>
jmp    12aa <_citrus_memory_stream_matchline+0x12a>
jmp    11a4 <_citrus_memory_stream_matchline+0x24>
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <_citrus_bcs_skip_ws_len@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_citrus_memory_stream_matchline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,0x14(%rsp)
mov    %rdx,%rbx
mov    %rdi,%r12
mov    %rsi,0x18(%rsp)
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1080 <_citrus_memory_stream_getln@plt>
test   %rax,%rax
je     129d <_citrus_memory_stream_matchline+0x11d>
mov    %rax,%r13
mov    %rbx,0x20(%rsp)
lea    0x8(%rsp),%r14
jmp    1207 <_citrus_memory_stream_matchline+0x87>
mov    0x18(%rsp),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1090 <_citrus_bcs_strncasecmp@plt>
test   %rax,%rax
je     1281 <_citrus_memory_stream_matchline+0x101>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1080 <_citrus_memory_stream_getln@plt>
mov    %rax,%r13
test   %rax,%rax
je     129d <_citrus_memory_stream_matchline+0x11d>
mov    0x8(%rsp),%rdx
mov    %r13,%rdi
mov    $0x23,%esi
call   1050 <memchr@plt>
test   %rax,%rax
je     1226 <_citrus_memory_stream_matchline+0xa6>
sub    %r13,%rax
mov    %rax,0x8(%rsp)
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <_citrus_bcs_trunc_rws_len@plt>
cmpq   $0x0,0x8(%rsp)
je     11f0 <_citrus_memory_stream_matchline+0x70>
mov    %r13,%rdi
mov    %r14,%rsi
call   1070 <_citrus_bcs_skip_ws_len@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
call   10a0 <_citrus_bcs_skip_nonws_len@plt>
mov    %rax,%rbx
sub    %rbp,%rax
cmp    %r15,%rax
jne    11f0 <_citrus_memory_stream_matchline+0x70>
cmpl   $0x0,0x14(%rsp)
je     11cd <_citrus_memory_stream_matchline+0x4d>
mov    0x18(%rsp),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1060 <memcmp@plt>
test   %rax,%rax
jne    11f0 <_citrus_memory_stream_matchline+0x70>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <_citrus_bcs_skip_ws_len@plt>
mov    0x8(%rsp),%rdx
mov    0x20(%rsp),%rcx
mov    %rdx,(%rcx)
jmp    129f <_citrus_memory_stream_matchline+0x11f>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct._citrus_memory_stream = type { i32 }
define i8* @_citrus_memory_stream_matchline(%struct._citrus_memory_stream* noalias %0, i8* noalias %1, i64* noalias %2, i32 %3) {
%5 = alloca i8*
%6 = alloca %struct._citrus_memory_stream*
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
store %struct._citrus_memory_stream* %0, %struct._citrus_memory_stream** %6
store i8* %1, i8** %7
store i64* %2, i64** %8
store i32 %3, i32* %9
%14 = load i8*, i8** %7
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %13
br label %16
16: ; preds = %4, %39, %72
%17 = load %struct._citrus_memory_stream*, %struct._citrus_memory_stream** %6
%18 = call i8* @_citrus_memory_stream_getln(%struct._citrus_memory_stream* %17, i64* %12)
store i8* %18, i8** %10
%19 = load i8*, i8** %10
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16
store i8* null, i8** %5
br label %79
22: ; preds = %16
%23 = load i8*, i8** %10
%24 = load i64, i64* %12
%25 = call i8* @memchr(i8* %23, i8 signext 35, i64 %24)
store i8* %25, i8** %11
%26 = load i8*, i8** %11
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load i8*, i8** %11
%30 = load i8*, i8** %10
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
store i64 %33, i64* %12
br label %34
34: ; preds = %28, %22
%35 = load i8*, i8** %10
%36 = call i32 @_citrus_bcs_trunc_rws_len(i8* %35, i64* %12)
%37 = load i64, i64* %12
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %34
br label %16
40: ; preds = %34
%41 = load i8*, i8** %10
%42 = call i8* @_citrus_bcs_skip_ws_len(i8* %41, i64* %12)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
%44 = call i8* @_citrus_bcs_skip_nonws_len(i8* %43, i64* %12)
store i8* %44, i8** %11
%45 = load i8*, i8** %11
%46 = load i8*, i8** %10
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = load i64, i64* %13
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %72
52: ; preds = %40
%53 = load i32, i32* %9
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %52
%56 = load i8*, i8** %7
%57 = load i8*, i8** %10
%58 = load i64, i64* %13
%59 = call i64 @memcmp(i8* %56, i8* %57, i64 %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %55
br label %73
62: ; preds = %55
br label %71
63: ; preds = %52
%64 = load i8*, i8** %7
%65 = load i8*, i8** %10
%66 = load i64, i64* %13
%67 = call i64 @_citrus_bcs_strncasecmp(i8* %64, i8* %65, i64 %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %63
br label %73
70: ; preds = %63
br label %71
71: ; preds = %70, %62
br label %72
72: ; preds = %71, %40
br label %16
73: ; preds = %69, %61
%74 = load i8*, i8** %11
%75 = call i8* @_citrus_bcs_skip_ws_len(i8* %74, i64* %12)
store i8* %75, i8** %10
%76 = load i64, i64* %12
%77 = load i64*, i64** %8
store i64 %76, i64* %77
%78 = load i8*, i8** %10
store i8* %78, i8** %5
br label %79
79: ; preds = %73, %21
%80 = load i8*, i8** %5
ret i8* %80
}

LLVM IR (-O2):
%struct._citrus_memory_stream = type { i32 }
define i8* @_citrus_memory_stream_matchline(%struct._citrus_memory_stream* noalias %0, i8* noalias %1, i64* noalias nocapture writeonly %2, i32 %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = call i8* @_citrus_memory_stream_getln(%struct._citrus_memory_stream* %0, i64* %5)
%9 = icmp eq i8* %8, null
br i1 %9, label %45, label %10
10: ; preds = %4
%11 = icmp eq i32 %3, 0
br label %12
12: ; preds = %10, %39
%13 = phi i8* [ %8, %10 ], [ %40, %39 ]
%14 = load i64, i64* %5
%15 = call i8* @memchr(i8* %13, i8 signext 35, i64 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = ptrtoint i8* %15 to i64
%19 = ptrtoint i8* %13 to i64
%20 = sub i64 %18, %19
store i64 %20, i64* %5
br label %21
21: ; preds = %17, %12
%22 = call i32 @_citrus_bcs_trunc_rws_len(i8* %13, i64* %5)
%23 = load i64, i64* %5
%24 = icmp eq i64 %23, 0
br i1 %24, label %39, label %25
25: ; preds = %21
%26 = call i8* @_citrus_bcs_skip_ws_len(i8* %13, i64* %5)
%27 = call i8* @_citrus_bcs_skip_nonws_len(i8* %26, i64* %5)
%28 = ptrtoint i8* %27 to i64
%29 = ptrtoint i8* %26 to i64
%30 = sub i64 %28, %29
%31 = icmp eq i64 %30, %7
br i1 %31, label %32, label %39
32: ; preds = %25
br i1 %11, label %36, label %33
33: ; preds = %32
%34 = call i64 @memcmp(i8* %1, i8* %26, i64 %7)
%35 = icmp eq i64 %34, 0
br i1 %35, label %42, label %39
36: ; preds = %32
%37 = call i64 @_citrus_bcs_strncasecmp(i8* %1, i8* %26, i64 %7)
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %25, %36, %33, %21
%40 = call i8* @_citrus_memory_stream_getln(%struct._citrus_memory_stream* %0, i64* %5)
%41 = icmp eq i8* %40, null
br i1 %41, label %45, label %12
42: ; preds = %36, %33
%43 = call i8* @_citrus_bcs_skip_ws_len(i8* %27, i64* %5)
%44 = load i64, i64* %5
store i64 %44, i64* %2
br label %45
45: ; preds = %39, %4, %42
%46 = phi i8* [ %43, %42 ], [ null, %4 ], [ null, %39 ]
ret i8* %46
}