#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*/ strcpy(char *, char *);
int strcspn(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
void extract_http_header_field(char *destination, char *headername,
                               char *header) {
  char *ptrToHeaderField = NULL;
  int nameLength = strlen(headername) + 1;
  int valueLength = 0;
  ptrToHeaderField = strstr(header, headername);
  if (ptrToHeaderField == NULL) {
    strcpy(destination, "N/A");
  } else {
    ptrToHeaderField = ptrToHeaderField + nameLength;
    valueLength = strcspn(ptrToHeaderField, "\r\n");
    strncpy(destination, ptrToHeaderField, valueLength);
    destination[valueLength] = '\0';
  }
}


x86 assembly (clang, -O0):
<extract_http_header_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b3 <extract_http_header_field+0x63>
mov    -0x8(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11f1 <extract_http_header_field+0xa1>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1060 <strcspn@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_http_header_field>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11b7 <extract_http_header_field+0x67>
movslq %r15d,%rcx
lea    (%rcx,%rax,1),%rbx
add    $0x1,%rbx
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcspn@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe42(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strcpy@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"N/A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @extract_http_header_field(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i8* null, i8** %7
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
store i32 %12, i32* %8
store i32 0, i32* %9
%13 = load i8*, i8** %6
%14 = load i8*, i8** %5
%15 = call i8* @strstr(i8* %13, i8* %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %36
21: ; preds = %3
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = call i32 @strcspn(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %27, i32* %9
%28 = load i8*, i8** %4
%29 = load i8*, i8** %7
%30 = load i32, i32* %9
%31 = call i32 @strncpy(i8* %28, i8* %29, i32 %30)
%32 = load i8*, i8** %4
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %21, %18
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"N/A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @extract_http_header_field(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i8* @strstr(i8* dereferenceable(1) %2, i8* dereferenceable(1) %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %17
9: ; preds = %3
%10 = add nsw i32 %4, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %5, i64 %11
%13 = tail call i32 @strcspn(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @strncpy(i8* %0, i8* %12, i32 %13)
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %9, %7
ret void
}