#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 */
int /*<<< orphan*/ strcasecmpstart(char const *, char const *);
void *strchr(char const *, char);
int /*<<< orphan*/ strlen(char const *);
char *tor_strdup_(char const *);
char *tor_strndup_(char const *, int);
char *http_get_header(const char *headers, const char *which) {
  const char *cp = headers;
  while (cp) {
    if (!strcasecmpstart(cp, which)) {
      char *eos;
      cp += strlen(which);
      if ((eos = strchr(cp, '\r')))
        return tor_strndup_(cp, eos - cp);
      else
        return tor_strdup_(cp);
    }
    cp = strchr(cp, '\n');
    if (cp)
      ++cp;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<http_get_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)
cmpq   $0x0,-0x20(%rbp)
je     121d <http_get_header+0xcd>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcasecmpstart@plt>
cmp    $0x0,%eax
jne    11ef <http_get_header+0x9f>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xd,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11dd <http_get_header+0x8d>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1070 <tor_strndup_@plt>
mov    %rax,-0x8(%rbp)
jmp    1225 <http_get_header+0xd5>
mov    -0x20(%rbp),%rdi
call   1040 <tor_strdup_@plt>
mov    %rax,-0x8(%rbp)
jmp    1225 <http_get_header+0xd5>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1218 <http_get_header+0xc8>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1168 <http_get_header+0x18>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_get_header>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1185 <http_get_header+0x35>
mov    %rsi,%r14
mov    %rdi,%rbx
nop
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcasecmpstart@plt>
test   %eax,%eax
je     118f <http_get_header+0x3f>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
jne    1160 <http_get_header+0x10>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0xd,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c1 <http_get_header+0x71>
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <tor_strndup_@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <tor_strdup_@plt>

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

LLVM IR (-O2):
define i8* @http_get_header(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %26, label %4
4: ; preds = %2, %22
%5 = phi i8* [ %25, %22 ], [ %0, %2 ]
%6 = tail call i32 @strcasecmpstart(i8* %5, i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = tail call i32 @strlen(i8* %1)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %5, i64 %10
%12 = tail call i8* @strchr(i8* %11, i8 signext 13)
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %8
%15 = ptrtoint i8* %12 to i64
%16 = ptrtoint i8* %11 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = tail call i8* @tor_strndup_(i8* %11, i32 %18)
br label %26
20: ; preds = %8
%21 = tail call i8* @tor_strdup_(i8* %11)
br label %26
22: ; preds = %4
%23 = tail call i8* @strchr(i8* %5, i8 signext 10)
%24 = icmp eq i8* %23, null
%25 = getelementptr inbounds i8, i8* %23, i64 1
br i1 %24, label %26, label %4
26: ; preds = %22, %2, %14, %20
%27 = phi i8* [ %19, %14 ], [ %21, %20 ], [ null, %2 ], [ null, %22 ]
ret i8* %27
}