#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__ calloc(int, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char const *);
char *REQUEST_get_header_value(const char *header,
                               const char *requested_value_name) {
  char *result_handler;
  static char result[256];
  char *dst;
  char *tmp_header_val;
  int count = 0;
  tmp_header_val = strstr((char *)header, requested_value_name);
  if (!tmp_header_val) {
    return "";
  }
  result_handler = malloc(2048);
  dst = (char *)calloc(256, sizeof(char));
  strncpy(result_handler, tmp_header_val, 2048);
  tmp_header_val = NULL;
  while ((dst[count] = result_handler[count]) != '\015') {
    if (result_handler[count] != '\015') {
      count++;
    }
  }
  dst[count] = '\0';
  free(result_handler);
  result_handler = NULL;
  memset(result, '\0', 256);
  strncpy(result, strstr(dst, ": ") + 2, 256);
  free(dst);
  dst = NULL;
  return ((char *)&result);
}


x86 assembly (clang, -O0):
<REQUEST_get_header_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a3 <REQUEST_get_header_value+0x43>
lea    0xe68(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1297 <REQUEST_get_header_value+0x137>
mov    $0x800,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x100,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x800,%edx
call   1040 <strncpy@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x28(%rbp),%rcx
movslq -0x34(%rbp),%rdx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
cmp    $0xd,%eax
je     1223 <REQUEST_get_header_value+0xc3>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
je     121e <REQUEST_get_header_value+0xbe>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11de <REQUEST_get_header_value+0x7e>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
lea    0x2e19(%rip),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
lea    0xda2(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,%rsi
add    $0x2,%rsi
lea    0x2def(%rip),%rdi
mov    $0x100,%edx
call   1040 <strncpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
lea    0x2dcd(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<REQUEST_get_header_value>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1080 <strstr@plt>
test   %rax,%rax
je     1230 <REQUEST_get_header_value+0xd0>
mov    %rax,%r15
mov    $0x800,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    $0x100,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x800,%edx
call   1040 <strncpy@plt>
mov    (%r12),%cl
mov    %cl,(%r14)
xor    %eax,%eax
cmp    $0xd,%cl
je     11e3 <REQUEST_get_header_value+0x83>
mov    %r12,%rcx
nopl   0x0(%rax)
mov    %eax,%eax
xor    %edx,%edx
cmpb   $0xd,(%rcx)
setne  %dl
add    %rax,%rdx
lea    (%r12,%rdx,1),%rcx
movzbl (%r12,%rdx,1),%ebx
mov    %bl,(%r14,%rdx,1)
mov    %edx,%eax
cmp    $0xd,%bl
jne    11c0 <REQUEST_get_header_value+0x60>
mov    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r12,%rdi
call   1030 <free@plt>
lea    0x2e69(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    0xdf3(%rip),%rsi
mov    %r14,%rdi
call   1080 <strstr@plt>
lea    0x2(%rax),%rsi
mov    %rbx,%rdi
mov    $0x100,%edx
call   1040 <strncpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1237 <REQUEST_get_header_value+0xd7>
lea    0xdcb(%rip),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@REQUEST_get_header_value.result = internal global [256 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c": \00"
define i8* @REQUEST_get_header_value(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i8* @strstr(i8* %10, i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %61
16: ; preds = %2
%17 = call i8* @malloc(i32 2048)
store i8* %17, i8** %6
%18 = call i64 @calloc(i32 256, i32 1)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %7
%20 = load i8*, i8** %6
%21 = load i8*, i8** %8
%22 = call i32 @strncpy(i8* %20, i8* %21, i32 2048)
store i8* null, i8** %8
br label %23
23: ; preds = %46, %16
%24 = load i8*, i8** %6
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = load i8*, i8** %7
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
%33 = sext i8 %28 to i32
%34 = icmp ne i32 %33, 13
br i1 %34, label %35, label %47
35: ; preds = %23
%36 = load i8*, i8** %6
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 13
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %46
46: ; preds = %43, %35
br label %23
47: ; preds = %23
%48 = load i8*, i8** %7
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
%52 = load i8*, i8** %6
%53 = call i32 @free(i8* %52)
store i8* null, i8** %6
%54 = call i32 @memset(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @REQUEST_get_header_value.result, i64 0, i64 0), i8 signext 0, i32 256)
%55 = load i8*, i8** %7
%56 = call i8* @strstr(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%57 = getelementptr inbounds i8, i8* %56, i64 2
%58 = call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @REQUEST_get_header_value.result, i64 0, i64 0), i8* %57, i32 256)
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
store i8* null, i8** %7
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @REQUEST_get_header_value.result, i32 0, i32 0), i8** %3
br label %61
61: ; preds = %47, %15
%62 = load i8*, i8** %3
ret i8* %62
}

LLVM IR (-O2):
@REQUEST_get_header_value.result = internal global [256 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c": \00"
define i8* @REQUEST_get_header_value(i8* %0, i8* nocapture %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %35, label %5
5: ; preds = %2
%6 = tail call dereferenceable_or_null(2048) i8* @malloc(i32 2048)
%7 = tail call i64 @calloc(i32 256, i32 1)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strncpy(i8* %6, i8* %3, i32 2048)
%10 = load i8, i8* %6
store i8 %10, i8* %8
%11 = icmp eq i8 %10, 13
br i1 %11, label %26, label %12
12: ; preds = %5, %12
%13 = phi i8* [ %20, %12 ], [ %6, %5 ]
%14 = phi i32 [ %18, %12 ], [ 0, %5 ]
%15 = load i8, i8* %13
%16 = icmp ne i8 %15, 13
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %14, %17
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %6, i64 %19
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %8, i64 %19
store i8 %21, i8* %22
%23 = icmp eq i8 %21, 13
br i1 %23, label %24, label %12
24: ; preds = %12
%25 = zext i32 %18 to i64
br label %26
26: ; preds = %5, %24
%27 = phi i64 [ %25, %24 ], [ 0, %5 ]
%28 = getelementptr inbounds i8, i8* %8, i64 %27
store i8 0, i8* %28
%29 = tail call i32 @free(i8* %6)
%30 = tail call i32 @memset(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @REQUEST_get_header_value.result, i64 0, i64 0), i8 signext 0, i32 256)
%31 = tail call i8* @strstr(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%32 = getelementptr inbounds i8, i8* %31, i64 2
%33 = tail call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @REQUEST_get_header_value.result, i64 0, i64 0), i8* %32, i32 256)
%34 = tail call i32 @free(i8* %8)
br label %35
35: ; preds = %2, %26
%36 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @REQUEST_get_header_value.result, i64 0, i64 0), %26 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
ret i8* %36
}