#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 */
struct phr_header {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ *is_complete(char const *, char const *, size_t, int *);
char *parse_request(char const *, char const *, char const **, size_t *,
                    char const **, size_t *, int *, struct phr_header *,
                    size_t *, size_t, int *);
int phr_parse_request(const char *buf_start, size_t len, const char **method,
                      size_t *method_len, const char **path, size_t *path_len,
                      int *minor_version, struct phr_header *headers,
                      size_t *num_headers, size_t last_len) {
  const char *buf = buf_start, *buf_end = buf_start + len;
  size_t max_headers = *num_headers;
  int r;
  *method = NULL;
  *method_len = 0;
  *path = NULL;
  *path_len = 0;
  *minor_version = -1;
  *num_headers = 0;
  if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) {
    return r;
  }
  if ((buf = parse_request(buf, buf_end, method, method_len, path, path_len,
                           minor_version, headers, num_headers, max_headers,
                           &r)) == NULL) {
    return r;
  }
  return (int)(buf - buf_start);
}


x86 assembly (clang, -O0):
<phr_parse_request>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
mov    %r9,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x40(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x48(%rbp),%rax
movq   $0x0,(%rax)
mov    0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    0x20(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,0x28(%rbp)
je     11eb <phr_parse_request+0xcb>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    0x28(%rbp),%rdx
lea    -0x64(%rbp),%rcx
call   1030 <is_complete@plt>
cmp    $0x0,%rax
jne    11eb <phr_parse_request+0xcb>
mov    -0x64(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    125b <phr_parse_request+0x13b>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9
mov    0x10(%rbp),%r14
mov    0x18(%rbp),%rbx
mov    0x20(%rbp),%r11
mov    -0x60(%rbp),%r10
lea    -0x64(%rbp),%rax
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1040 <parse_request@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    124d <phr_parse_request+0x12d>
mov    -0x64(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    125b <phr_parse_request+0x13b>
mov    -0x50(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<phr_parse_request>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r10
mov    %rsi,%r13
mov    %rdi,%r14
mov    0x68(%rsp),%rdx
mov    0x60(%rsp),%rbp
mov    0x50(%rsp),%rbx
add    %rdi,%r13
mov    0x0(%rbp),%r11
movq   $0x0,(%r10)
movq   $0x0,(%rcx)
movq   $0x0,(%r8)
movq   $0x0,(%r9)
movl   $0xffffffff,(%rbx)
movq   $0x0,0x0(%rbp)
test   %rdx,%rdx
je     11c3 <phr_parse_request+0xa3>
mov    %rcx,0x10(%rsp)
lea    0xc(%rsp),%rcx
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r9,%r15
mov    %r8,%r12
mov    %r14,%rbp
mov    %r10,%r14
mov    %r11,%rbx
call   1030 <is_complete@plt>
mov    %rbx,%r11
mov    %r14,%r10
mov    %rbp,%r14
mov    0x10(%rsp),%rcx
mov    0x60(%rsp),%rbp
mov    %r12,%r8
mov    %r15,%r9
mov    0x50(%rsp),%rbx
test   %rax,%rax
je     11f1 <phr_parse_request+0xd1>
sub    $0x8,%rsp
lea    0x14(%rsp),%rax
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r10,%rdx
push   %rax
push   %r11
push   %rbp
push   0x78(%rsp)
push   %rbx
call   1040 <parse_request@plt>
add    $0x30,%rsp
test   %rax,%rax
je     11f1 <phr_parse_request+0xd1>
sub    %r14d,%eax
jmp    11f5 <phr_parse_request+0xd5>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.phr_header = type { i32 }
define i32 @phr_parse_request(i8* %0, i64 %1, i8** %2, i64* %3, i8** %4, i64* %5, i32* %6, %struct.phr_header* %7, i64* %8, i64 %9) {
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8**
%15 = alloca i64*
%16 = alloca i8**
%17 = alloca i64*
%18 = alloca i32*
%19 = alloca %struct.phr_header*
%20 = alloca i64*
%21 = alloca i64
%22 = alloca i8*
%23 = alloca i8*
%24 = alloca i64
%25 = alloca i32
store i8* %0, i8** %12
store i64 %1, i64* %13
store i8** %2, i8*** %14
store i64* %3, i64** %15
store i8** %4, i8*** %16
store i64* %5, i64** %17
store i32* %6, i32** %18
store %struct.phr_header* %7, %struct.phr_header** %19
store i64* %8, i64** %20
store i64 %9, i64* %21
%26 = load i8*, i8** %12
store i8* %26, i8** %22
%27 = load i8*, i8** %12
%28 = load i64, i64* %13
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %23
%30 = load i64*, i64** %20
%31 = load i64, i64* %30
store i64 %31, i64* %24
%32 = load i8**, i8*** %14
store i8* null, i8** %32
%33 = load i64*, i64** %15
store i64 0, i64* %33
%34 = load i8**, i8*** %16
store i8* null, i8** %34
%35 = load i64*, i64** %17
store i64 0, i64* %35
%36 = load i32*, i32** %18
store i32 -1, i32* %36
%37 = load i64*, i64** %20
store i64 0, i64* %37
%38 = load i64, i64* %21
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %48
40: ; preds = %10
%41 = load i8*, i8** %22
%42 = load i8*, i8** %23
%43 = load i64, i64* %21
%44 = call i32* @is_complete(i8* %41, i8* %42, i64 %43, i32* %25)
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %48
46: ; preds = %40
%47 = load i32, i32* %25
store i32 %47, i32* %11
br label %70
48: ; preds = %40, %10
%49 = load i8*, i8** %22
%50 = load i8*, i8** %23
%51 = load i8**, i8*** %14
%52 = load i64*, i64** %15
%53 = load i8**, i8*** %16
%54 = load i64*, i64** %17
%55 = load i32*, i32** %18
%56 = load %struct.phr_header*, %struct.phr_header** %19
%57 = load i64*, i64** %20
%58 = load i64, i64* %24
%59 = call i8* @parse_request(i8* %49, i8* %50, i8** %51, i64* %52, i8** %53, i64* %54, i32* %55, %struct.phr_header* %56, i64* %57, i64 %58, i32* %25)
store i8* %59, i8** %22
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %63
61: ; preds = %48
%62 = load i32, i32* %25
store i32 %62, i32* %11
br label %70
63: ; preds = %48
%64 = load i8*, i8** %22
%65 = load i8*, i8** %12
%66 = ptrtoint i8* %64 to i64
%67 = ptrtoint i8* %65 to i64
%68 = sub i64 %66, %67
%69 = trunc i64 %68 to i32
store i32 %69, i32* %11
br label %70
70: ; preds = %63, %61, %46
%71 = load i32, i32* %11
ret i32 %71
}

LLVM IR (-O2):
%struct.phr_header = type { i32 }
define i32 @phr_parse_request(i8* %0, i64 %1, i8** %2, i64* %3, i8** %4, i64* %5, i32* %6, %struct.phr_header* %7, i64* %8, i64 %9) {
%11 = alloca i32
%12 = getelementptr inbounds i8, i8* %0, i64 %1
%13 = load i64, i64* %8
%14 = bitcast i32* %11 to i8*
store i8* null, i8** %2
store i64 0, i64* %3
store i8* null, i8** %4
store i64 0, i64* %5
store i32 -1, i32* %6
store i64 0, i64* %8
%15 = icmp eq i64 %9, 0
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = call i32* @is_complete(i8* %0, i8* %12, i64 %9, i32* %11)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i32, i32* %11
br label %31
21: ; preds = %16, %10
%22 = call i8* @parse_request(i8* %0, i8* %12, i8** %2, i64* %3, i8** %4, i64* %5, i32* %6, %struct.phr_header* %7, i64* %8, i64 %13, i32* %11)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32, i32* %11
br label %31
26: ; preds = %21
%27 = ptrtoint i8* %22 to i64
%28 = ptrtoint i8* %0 to i64
%29 = sub i64 %27, %28
%30 = trunc i64 %29 to i32
br label %31
31: ; preds = %26, %24, %19
%32 = phi i32 [ %20, %19 ], [ %25, %24 ], [ %30, %26 ]
ret i32 %32
}