#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 */
typedef scalar_t__ const uint8_t;
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
ssize_t _packbits_replicate_length(const uint8_t *src, const uint8_t *srcend) {
  uint8_t *srcptr = (uint8_t *)src;
  const uint8_t value = *srcptr;
  while ((++srcptr < srcend) && (value == *srcptr)) {
    ;
  }
  return (ssize_t)(srcptr - src);
}


x86 assembly (clang, -O0):
<_packbits_replicate_length>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x21(%rbp)
jae    114b <_packbits_replicate_length+0x4b>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    115b <_packbits_replicate_length+0x5b>
jmp    1160 <_packbits_replicate_length+0x60>
jmp    111f <_packbits_replicate_length+0x1f>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_packbits_replicate_length>:
mov    (%rdi),%r8
mov    $0x8,%edx
nopl   0x0(%rax,%rax,1)
mov    %rdx,%rax
lea    (%rdi,%rdx,1),%rcx
cmp    %rsi,%rcx
jae    1125 <_packbits_replicate_length+0x25>
lea    0x8(%rax),%rdx
cmp    (%rcx),%r8
je     1110 <_packbits_replicate_length+0x10>
shr    $0x3,%rax
ret

LLVM IR (-O0):
define i32 @_packbits_replicate_length(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i64
store i64* %0, i64** %3
store i64* %1, i64** %4
%7 = load i64*, i64** %3
store i64* %7, i64** %5
%8 = load i64*, i64** %5
%9 = load i64, i64* %8
store i64 %9, i64* %6
br label %10
10: ; preds = %22, %2
%11 = load i64*, i64** %5
%12 = getelementptr inbounds i64, i64* %11, i32 1
store i64* %12, i64** %5
%13 = load i64*, i64** %4
%14 = icmp ult i64* %12, %13
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i64, i64* %6
%17 = load i64*, i64** %5
%18 = load i64, i64* %17
%19 = icmp eq i64 %16, %18
br label %20
20: ; preds = %15, %10
%21 = phi i1 [ false, %10 ], [ %19, %15 ]
br i1 %21, label %22, label %23
22: ; preds = %20
br label %10
23: ; preds = %20
%24 = load i64*, i64** %5
%25 = load i64*, i64** %3
%26 = ptrtoint i64* %24 to i64
%27 = ptrtoint i64* %25 to i64
%28 = sub i64 %26, %27
%29 = sdiv exact i64 %28, 8
%30 = trunc i64 %29 to i32
ret i32 %30
}

LLVM IR (-O2):
define i32 @_packbits_replicate_length(i64* %0, i64* readnone %1) {
%3 = load i64, i64* %0
br label %4
4: ; preds = %8, %2
%5 = phi i64* [ %0, %2 ], [ %6, %8 ]
%6 = getelementptr inbounds i64, i64* %5, i64 1
%7 = icmp ult i64* %6, %1
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i64, i64* %6
%10 = icmp eq i64 %3, %9
br i1 %10, label %4, label %11
11: ; preds = %4, %8
%12 = ptrtoint i64* %6 to i64
%13 = ptrtoint i64* %0 to i64
%14 = sub i64 %12, %13
%15 = lshr exact i64 %14, 3
%16 = trunc i64 %15 to i32
ret i32 %16
}