#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 *strchr(char *, char);
int read_http_header(char *buffer, char **key, char **value, int *key_length,
                     int *value_length) {
  *key = buffer;
  *value = strchr(*key, ':') + 2;
  if (*value == NULL)
    return -1;
  *key_length = *value - *key - 2;
  *value_length = strchr(*value, '\r') - *value;
  return *key_length + *value_length + 4;
}


x86 assembly (clang, -O0):
<read_http_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
add    $0x2,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1170 <read_http_header+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <read_http_header+0xb2>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
sub    $0x2,%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    -0x30(%rbp),%rcx
add    (%rcx),%eax
add    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_http_header>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,(%rsi)
mov    $0x3a,%esi
call   1030 <strchr@plt>
lea    0x2(%rax),%rbx
mov    %rbx,(%r12)
mov    %ebx,%eax
sub    0x0(%r13),%eax
add    $0xfffffffe,%eax
mov    %eax,(%r15)
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
sub    %ebx,%eax
mov    %eax,(%r14)
mov    (%r15),%ecx
add    %ecx,%eax
add    $0x4,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @read_http_header(i8* %0, i8** nocapture %1, i8** nocapture %2, i32* nocapture %3, i32* nocapture writeonly %4) {
store i8* %0, i8** %1
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%7 = getelementptr inbounds i8, i8* %6, i64 2
store i8* %7, i8** %2
%8 = load i8*, i8** %1
%9 = ptrtoint i8* %7 to i64
%10 = ptrtoint i8* %8 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = add i32 %12, -2
store i32 %13, i32* %3
%14 = tail call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 13)
%15 = ptrtoint i8* %14 to i64
%16 = sub i64 %15, %9
%17 = trunc i64 %16 to i32
store i32 %17, i32* %4
%18 = load i32, i32* %3
%19 = add i32 %18, 4
%20 = add i32 %19, %17
ret i32 %20
}