#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__ is_cr_present(char *, int);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char const *);
int get_http_header_field(char *header, const char *field, char *value) {
  int i;
  char *occurrence = NULL;
  int content_pos = 0;
  occurrence = strstr(header, field);
  content_pos = strlen(field) + 1;
  for (i = content_pos; occurrence[i] != '\0'; i++) {
    if (is_cr_present(occurrence, i)) {
      strncpy(value, occurrence + content_pos, i - content_pos);
      value[i - content_pos - 1] = '\0';
      return 0;
    }
  }
  value[0] = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<get_http_header_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1201 <get_http_header_field+0xc1>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <is_cr_present@plt>
cmp    $0x0,%rax
je     11ee <get_http_header_field+0xae>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
sub    -0x34(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    120f <get_http_header_field+0xcf>
jmp    11f3 <get_http_header_field+0xb3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1189 <get_http_header_field+0x49>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_http_header_field>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbp
call   1060 <strstr@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
mov    $0x1,%r12d
cmpb   $0x0,0x1(%r13,%rax,1)
je     11c7 <get_http_header_field+0x87>
lea    (%rax,%r13,1),%rcx
add    $0x1,%rcx
mov    %rcx,(%rsp)
add    $0x1,%rax
mov    %eax,%ebx
lea    (%rax,%r13,1),%r15
add    $0x1,%r15
xor    %ebp,%ebp
nopl   (%rax)
lea    (%rbx,%rbp,1),%esi
mov    %r13,%rdi
call   1050 <is_cr_present@plt>
test   %rax,%rax
jne    11ad <get_http_header_field+0x6d>
cmpb   $0x0,(%r15,%rbp,1)
lea    0x1(%rbp),%rbp
jne    1190 <get_http_header_field+0x50>
jmp    11c7 <get_http_header_field+0x87>
mov    %r14,%rdi
mov    (%rsp),%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
add    $0xffffffff,%ebp
movslq %ebp,%rax
add    %rax,%r14
xor    %r12d,%r12d
movb   $0x0,(%r14)
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @get_http_header_field(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %3, %23
%12 = phi i64 [ %24, %23 ], [ %7, %3 ]
%13 = trunc i64 %12 to i32
%14 = tail call i64 @is_cr_present(i8* %4, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %11
%17 = trunc i64 %12 to i32
%18 = sub nsw i32 %17, %6
%19 = tail call i32 @strncpy(i8* %2, i8* %8, i32 %18)
%20 = add nsw i32 %18, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %2, i64 %21
br label %28
23: ; preds = %11
%24 = add i64 %12, 1
%25 = getelementptr inbounds i8, i8* %4, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %11
28: ; preds = %23, %3, %16
%29 = phi i8* [ %22, %16 ], [ %2, %3 ], [ %2, %23 ]
%30 = phi i32 [ 0, %16 ], [ 1, %3 ], [ 1, %23 ]
store i8 0, i8* %29
ret i32 %30
}