#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 */
char *strchr(char *, char);
char *strstr(char const *, char const *);
char *header_value(const char *headers, const char *header_name) {
  char *cp;
  if (!headers)
    return NULL;
  while ((cp = strstr(headers, header_name))) {
    if (cp == headers || cp[-1] == '\n') {
      if (!(cp = strchr(cp, ':')))
        continue;
      while (*(++cp) == ' ')
        ;
      return cp;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<header_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1148 <header_value+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11e8 <header_value+0xc8>
jmp    114d <header_value+0x2d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11e0 <header_value+0xc0>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1187 <header_value+0x67>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0xa,%eax
jne    11db <header_value+0xbb>
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a8 <header_value+0x88>
jmp    114d <header_value+0x2d>
jmp    11ad <header_value+0x8d>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x20,%eax
jne    11ce <header_value+0xae>
jmp    11ad <header_value+0x8d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e8 <header_value+0xc8>
jmp    114d <header_value+0x2d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<header_value>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     118f <header_value+0x6f>
mov    %rdi,%r14
call   1040 <strstr@plt>
test   %rax,%rax
je     118f <header_value+0x6f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
jmp    1155 <header_value+0x35>
nopl   0x0(%rax,%rax,1)
test   %rax,%rax
jne    1180 <header_value+0x60>
cmp    %r14,%rbx
je     1150 <header_value+0x30>
sete   %dl
cmpb   $0xa,-0x1(%rbx)
sete   %cl
or     %dl,%cl
cs nopw 0x0(%rax,%rax,1)
test   %cl,%cl
je     1170 <header_value+0x50>
jmp    1150 <header_value+0x30>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rax),%rcx
cmpb   $0x20,0x1(%rax)
mov    %rcx,%rax
je     1180 <header_value+0x60>
jmp    1191 <header_value+0x71>
xor    %ecx,%ecx
mov    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @header_value(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i8* null, i8** %3
br label %43
10: ; preds = %2
br label %11
11: ; preds = %41, %30, %10
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i8* @strstr(i8* %12, i8* %13)
store i8* %14, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %42
16: ; preds = %11
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = icmp eq i8* %17, %18
br i1 %19, label %26, label %20
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 -1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %41
26: ; preds = %20, %16
%27 = load i8*, i8** %6
%28 = call i8* @strchr(i8* %27, i8 signext 58)
store i8* %28, i8** %6
%29 = icmp ne i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %26
br label %11
31: ; preds = %26
br label %32
32: ; preds = %38, %31
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %6
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 32
br i1 %37, label %38, label %39
38: ; preds = %32
br label %32
39: ; preds = %32
%40 = load i8*, i8** %6
store i8* %40, i8** %3
br label %43
41: ; preds = %20
br label %11
42: ; preds = %11
store i8* null, i8** %3
br label %43
43: ; preds = %42, %39, %9
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
define i8* @header_value(i8* %0, i8* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %24, label %4
4: ; preds = %2
%5 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %24, label %7
7: ; preds = %4
%8 = icmp eq i8* %5, %0
%9 = getelementptr inbounds i8, i8* %5, i64 -1
%10 = tail call i8* @strchr(i8* %5, i8 signext 58)
%11 = icmp eq i8* %10, null
br label %12
12: ; preds = %18, %7
br i1 %8, label %18, label %13
13: ; preds = %12
%14 = load i8, i8* %9
%15 = icmp eq i8 %14, 10
%16 = select i1 %15, i1 true, i1 %8
br label %17
17: ; preds = %13, %17
br i1 %16, label %18, label %17
18: ; preds = %17, %12
br i1 %11, label %12, label %19
19: ; preds = %18, %19
%20 = phi i8* [ %21, %19 ], [ %10, %18 ]
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 32
br i1 %23, label %19, label %24
24: ; preds = %19, %4, %2
%25 = phi i8* [ null, %2 ], [ null, %4 ], [ %21, %19 ]
ret i8* %25
}