#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);
size_t http_request_parse_headers_count(char *raw) {
  size_t counter = 0;
  char *previous = raw;
  char *current = strchr(previous, '\r');
  while (current - previous > 5) {
    previous = current;
    current = strchr(previous + 1, '\r');
    ++counter;
  }
  return counter;
}


x86 assembly (clang, -O0):
<http_request_parse_headers_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x5,%rax
jle    1182 <http_request_parse_headers_count+0x72>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113e <http_request_parse_headers_count+0x2e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_request_parse_headers_count>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    %rax,%r14
sub    %rbx,%rax
xor    %ebx,%ebx
cmp    $0x6,%rax
jl     1151 <http_request_parse_headers_count+0x41>
nop
lea    0x1(%r14),%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
add    $0x1,%rbx
mov    %rax,%rcx
sub    %r14,%rcx
mov    %rax,%r14
cmp    $0x5,%rcx
jg     1130 <http_request_parse_headers_count+0x20>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @http_request_parse_headers_count(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* %3
%6 = load i8*, i8** %2
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i8* @strchr(i8* %7, i8 signext 13)
store i8* %8, i8** %5
br label %9
9: ; preds = %16, %1
%10 = load i8*, i8** %5
%11 = load i8*, i8** %4
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = icmp sgt i64 %14, 5
br i1 %15, label %16, label %23
16: ; preds = %9
%17 = load i8*, i8** %5
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i8* @strchr(i8* %19, i8 signext 13)
store i8* %20, i8** %5
%21 = load i64, i64* %3
%22 = add i64 %21, 1
store i64 %22, i64* %3
br label %9
23: ; preds = %9
%24 = load i64, i64* %3
ret i64 %24
}

LLVM IR (-O2):
define i64 @http_request_parse_headers_count(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 13)
%3 = ptrtoint i8* %2 to i64
%4 = ptrtoint i8* %0 to i64
%5 = sub i64 %3, %4
%6 = icmp sgt i64 %5, 5
br i1 %6, label %7, label %17
7: ; preds = %1, %7
%8 = phi i8* [ %11, %7 ], [ %2, %1 ]
%9 = phi i64 [ %12, %7 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = tail call i8* @strchr(i8* %10, i8 signext 13)
%12 = add i64 %9, 1
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint i8* %8 to i64
%15 = sub i64 %13, %14
%16 = icmp sgt i64 %15, 5
br i1 %16, label %7, label %17
17: ; preds = %7, %1
%18 = phi i64 [ 0, %1 ], [ %12, %7 ]
ret i64 %18
}