#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 *getBufferSpace();
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
char *getHeader(char **headers, char *header) {
  char *current_header, *matching_header, *value;
  char *retval = getBufferSpace();
  int i;
  for (i = 0; headers[i] != NULL; i++) {
    current_header = headers[i];
    if ((matching_header = strstr(current_header, header))) {
      value = matching_header + strlen(header);
      if (*value == ':') {
        while (*value == ' ' || *value == ':') {
          value++;
        }
        strncpy(retval, value, 8192);
        return retval;
      }
    }
  }
  memcpy(retval, "VALUE_UNDEFINED", sizeof("VALUE_UNDEFINED"));
  return retval;
}


x86 assembly (clang, -O0):
<getHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1060 <getBufferSpace@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1263 <getHeader+0x113>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1250 <getHeader+0x100>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    124b <getHeader+0xfb>
jmp    11e6 <getHeader+0x96>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x49(%rbp)
je     120b <getHeader+0xbb>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
sete   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    121b <getHeader+0xcb>
jmp    122c <getHeader+0xdc>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11e6 <getHeader+0x96>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x2000,%edx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1280 <getHeader+0x130>
jmp    1250 <getHeader+0x100>
jmp    1255 <getHeader+0x105>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1172 <getHeader+0x22>
mov    -0x38(%rbp),%rdi
lea    0xd92(%rip),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHeader>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <getBufferSpace@plt>
mov    %rax,%r14
mov    (%rbx),%rdi
test   %rdi,%rdi
je     11e4 <getHeader+0x94>
add    $0x8,%rbx
jmp    118c <getHeader+0x3c>
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
je     11e4 <getHeader+0x94>
mov    %r15,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1180 <getHeader+0x30>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x3a,(%r12,%rax,1)
jne    1180 <getHeader+0x30>
add    %rax,%r12
mov    $0x3a,%al
jmp    11ca <getHeader+0x7a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x1(%r12),%eax
add    $0x1,%r12
cmp    $0x3a,%al
je     11c0 <getHeader+0x70>
cmp    $0x20,%al
je     11c0 <getHeader+0x70>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x2000,%edx
call   1030 <strncpy@plt>
jmp    11f8 <getHeader+0xa8>
lea    0xe15(%rip),%rsi
mov    %r14,%rdi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"VALUE_UNDEFINED\00"
define i8* @getHeader(i8** %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
%11 = call i8* (...) @getBufferSpace()
store i8* %11, i8** %9
store i32 0, i32* %10
br label %12
12: ; preds = %62, %2
%13 = load i8**, i8*** %4
%14 = load i32, i32* %10
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %65
19: ; preds = %12
%20 = load i8**, i8*** %4
%21 = load i32, i32* %10
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = load i8*, i8** %5
%27 = call i8* @strstr(i8* %25, i8* %26)
store i8* %27, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %61
29: ; preds = %19
%30 = load i8*, i8** %7
%31 = load i8*, i8** %5
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8* %34, i8** %8
%35 = load i8*, i8** %8
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 58
br i1 %38, label %39, label %60
39: ; preds = %29
br label %40
40: ; preds = %52, %39
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 32
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 58
br label %50
50: ; preds = %45, %40
%51 = phi i1 [ true, %40 ], [ %49, %45 ]
br i1 %51, label %52, label %55
52: ; preds = %50
%53 = load i8*, i8** %8
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %8
br label %40
55: ; preds = %50
%56 = load i8*, i8** %9
%57 = load i8*, i8** %8
%58 = call i32 @strncpy(i8* %56, i8* %57, i32 8192)
%59 = load i8*, i8** %9
store i8* %59, i8** %3
br label %69
60: ; preds = %29
br label %61
61: ; preds = %60, %19
br label %62
62: ; preds = %61
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %12
65: ; preds = %12
%66 = load i8*, i8** %9
%67 = call i32 @memcpy(i8* %66, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 16)
%68 = load i8*, i8** %9
store i8* %68, i8** %3
br label %69
69: ; preds = %65, %55
%70 = load i8*, i8** %3
ret i8* %70
}

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