#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_response(char const *, char const *, int *, int *, char const **,
                     size_t *, struct phr_header *, size_t *, size_t, int *);
int phr_parse_response(const char *buf_start, size_t len, int *minor_version,
                       int *status, const char **msg, size_t *msg_len,
                       struct phr_header *headers, size_t *num_headers,
                       size_t last_len) {
  const char *buf = buf_start, *buf_end = buf + len;
  size_t max_headers = *num_headers;
  int r;
  *minor_version = -1;
  *status = 0;
  *msg = NULL;
  *msg_len = 0;
  *num_headers = 0;
  if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) {
    return r;
  }
  if ((buf = parse_response(buf, buf_end, minor_version, status, msg, msg_len,
                            headers, num_headers, max_headers, &r)) == NULL) {
    return r;
  }
  return (int)(buf - buf_start);
}


x86 assembly (clang, -O0):
<phr_parse_response>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x78,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x40(%rbp),%rax
movq   $0x0,(%rax)
mov    0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,0x20(%rbp)
je     11d6 <phr_parse_response+0xb6>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    0x20(%rbp),%rdx
lea    -0x5c(%rbp),%rcx
call   1030 <is_complete@plt>
cmp    $0x0,%rax
jne    11d6 <phr_parse_response+0xb6>
mov    -0x5c(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    123d <phr_parse_response+0x11d>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    0x10(%rbp),%rbx
mov    0x18(%rbp),%r11
mov    -0x58(%rbp),%r10
lea    -0x5c(%rbp),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1040 <parse_response@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    122f <phr_parse_response+0x10f>
mov    -0x5c(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    123d <phr_parse_response+0x11d>
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<phr_parse_response>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r11
mov    %rsi,%rbp
mov    %rdi,%r14
mov    0x60(%rsp),%rdx
mov    0x58(%rsp),%rbx
add    %rdi,%rbp
mov    (%rbx),%r13
movl   $0xffffffff,(%r11)
movl   $0x0,(%rcx)
movq   $0x0,(%r8)
movq   $0x0,(%r9)
movq   $0x0,(%rbx)
test   %rdx,%rdx
je     11a4 <phr_parse_response+0x84>
mov    %rcx,0x10(%rsp)
lea    0xc(%rsp),%rcx
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r9,%r15
mov    %r8,%r12
mov    %r11,%rbx
call   1030 <is_complete@plt>
mov    %rbx,%r11
mov    0x10(%rsp),%rcx
mov    %r12,%r8
mov    %r15,%r9
mov    0x58(%rsp),%rbx
test   %rax,%rax
je     11cd <phr_parse_response+0xad>
lea    0xc(%rsp),%rax
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r11,%rdx
push   %rax
push   %r13
push   %rbx
push   0x68(%rsp)
call   1040 <parse_response@plt>
add    $0x20,%rsp
test   %rax,%rax
je     11cd <phr_parse_response+0xad>
sub    %r14d,%eax
jmp    11d1 <phr_parse_response+0xb1>
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_response(i8* %0, i64 %1, i32* %2, i32* %3, i8** %4, i64* %5, %struct.phr_header* %6, i64* %7, i64 %8) {
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i8**
%16 = alloca i64*
%17 = alloca %struct.phr_header*
%18 = alloca i64*
%19 = alloca i64
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i64
%23 = alloca i32
store i8* %0, i8** %11
store i64 %1, i64* %12
store i32* %2, i32** %13
store i32* %3, i32** %14
store i8** %4, i8*** %15
store i64* %5, i64** %16
store %struct.phr_header* %6, %struct.phr_header** %17
store i64* %7, i64** %18
store i64 %8, i64* %19
%24 = load i8*, i8** %11
store i8* %24, i8** %20
%25 = load i8*, i8** %20
%26 = load i64, i64* %12
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8* %27, i8** %21
%28 = load i64*, i64** %18
%29 = load i64, i64* %28
store i64 %29, i64* %22
%30 = load i32*, i32** %13
store i32 -1, i32* %30
%31 = load i32*, i32** %14
store i32 0, i32* %31
%32 = load i8**, i8*** %15
store i8* null, i8** %32
%33 = load i64*, i64** %16
store i64 0, i64* %33
%34 = load i64*, i64** %18
store i64 0, i64* %34
%35 = load i64, i64* %19
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %9
%38 = load i8*, i8** %20
%39 = load i8*, i8** %21
%40 = load i64, i64* %19
%41 = call i32* @is_complete(i8* %38, i8* %39, i64 %40, i32* %23)
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = load i32, i32* %23
store i32 %44, i32* %10
br label %66
45: ; preds = %37, %9
%46 = load i8*, i8** %20
%47 = load i8*, i8** %21
%48 = load i32*, i32** %13
%49 = load i32*, i32** %14
%50 = load i8**, i8*** %15
%51 = load i64*, i64** %16
%52 = load %struct.phr_header*, %struct.phr_header** %17
%53 = load i64*, i64** %18
%54 = load i64, i64* %22
%55 = call i8* @parse_response(i8* %46, i8* %47, i32* %48, i32* %49, i8** %50, i64* %51, %struct.phr_header* %52, i64* %53, i64 %54, i32* %23)
store i8* %55, i8** %20
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %59
57: ; preds = %45
%58 = load i32, i32* %23
store i32 %58, i32* %10
br label %66
59: ; preds = %45
%60 = load i8*, i8** %20
%61 = load i8*, i8** %11
%62 = ptrtoint i8* %60 to i64
%63 = ptrtoint i8* %61 to i64
%64 = sub i64 %62, %63
%65 = trunc i64 %64 to i32
store i32 %65, i32* %10
br label %66
66: ; preds = %59, %57, %43
%67 = load i32, i32* %10
ret i32 %67
}

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