#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 int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm_extract_epi32(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_set1_epi32(int /*<<< orphan*/);
scalar_t__ read_int_delta(int /*<<< orphan*/ const *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
scalar_t__ read_int_group_delta(int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ *, int *,
                                int /*<<< orphan*/ *);
size_t read_ints_delta(const uint8_t *in, uint32_t *out, int length,
                       uint32_t prev) {
  __m128i mprev = _mm_set1_epi32(prev);
  size_t consumed = 0;
  int count;
  for (count = 0; count + 15 < length;) {
    int ints_read;
    consumed +=
        read_int_group_delta(in + consumed, out + count, &ints_read, &mprev);
    count += ints_read;
  }
  prev = _mm_extract_epi32(mprev, 3);
  for (; count < length; count++) {
    consumed += read_int_delta(in + consumed, out + count, &prev);
  }
  return consumed;
}


x86 assembly (clang, -O0):
<read_ints_delta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <_mm_set1_epi32@plt>
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xf,%eax
cmp    -0x14(%rbp),%eax
jge    11c0 <read_ints_delta+0x80>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    -0x30(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1060 <read_int_group_delta@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1170 <read_ints_delta+0x30>
mov    -0x1c(%rbp),%edi
mov    $0x3,%esi
call   1030 <_mm_extract_epi32@plt>
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1219 <read_ints_delta+0xd9>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    -0x18(%rbp),%rdx
call   1040 <read_int_delta@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d0 <read_ints_delta+0x90>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ints_delta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %ecx,%edi
call   1050 <_mm_set1_epi32@plt>
mov    %eax,0x4(%rsp)
cmp    $0x10,%r12d
jl     11c9 <read_ints_delta+0x89>
xor    %r13d,%r13d
xor    %ebx,%ebx
mov    %r14,0x10(%rsp)
mov    %rbp,%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rbp
mov    0x10(%rsp),%rax
lea    (%rax,%rbx,4),%rdi
movslq %r13d,%r15
lea    (%r14,%r15,4),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1060 <read_int_group_delta@plt>
mov    %rax,%rbx
add    %rbp,%rbx
mov    0x8(%rsp),%eax
lea    (%rax,%r15,1),%r13d
add    %r15d,%eax
add    $0xf,%eax
cmp    %r12d,%eax
jl     1180 <read_ints_delta+0x40>
mov    0x4(%rsp),%eax
mov    %r14,%rbp
mov    0x10(%rsp),%r14
jmp    11ce <read_ints_delta+0x8e>
xor    %ebx,%ebx
xor    %r13d,%r13d
mov    %eax,%edi
mov    $0x3,%esi
call   1030 <_mm_extract_epi32@plt>
mov    %eax,0xc(%rsp)
cmp    %r12d,%r13d
jge    121c <read_ints_delta+0xdc>
movslq %r13d,%rax
lea    0x0(%rbp,%rax,4),%rbp
sub    %r13d,%r12d
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r14,%rbx,4),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1040 <read_int_delta@plt>
add    %rax,%rbx
add    $0x4,%rbp
add    $0xffffffff,%r12d
jne    1200 <read_ints_delta+0xc0>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @read_ints_delta(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %8
%14 = call i32 @_mm_set1_epi32(i32 %13)
store i32 %14, i32* %9
store i64 0, i64* %10
store i32 0, i32* %11
br label %15
15: ; preds = %20, %4
%16 = load i32, i32* %11
%17 = add nsw i32 %16, 15
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %34
20: ; preds = %15
%21 = load i32*, i32** %5
%22 = load i64, i64* %10
%23 = getelementptr inbounds i32, i32* %21, i64 %22
%24 = load i32*, i32** %6
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = call i64 @read_int_group_delta(i32* %23, i32* %27, i32* %12, i32* %9)
%29 = load i64, i64* %10
%30 = add i64 %29, %28
store i64 %30, i64* %10
%31 = load i32, i32* %12
%32 = load i32, i32* %11
%33 = add nsw i32 %32, %31
store i32 %33, i32* %11
br label %15
34: ; preds = %15
%35 = load i32, i32* %9
%36 = call i32 @_mm_extract_epi32(i32 %35, i32 3)
store i32 %36, i32* %8
br label %37
37: ; preds = %52, %34
%38 = load i32, i32* %11
%39 = load i32, i32* %7
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %55
41: ; preds = %37
%42 = load i32*, i32** %5
%43 = load i64, i64* %10
%44 = getelementptr inbounds i32, i32* %42, i64 %43
%45 = load i32*, i32** %6
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = call i64 @read_int_delta(i32* %44, i32* %48, i32* %8)
%50 = load i64, i64* %10
%51 = add i64 %50, %49
store i64 %51, i64* %10
br label %52
52: ; preds = %41
%53 = load i32, i32* %11
%54 = add nsw i32 %53, 1
store i32 %54, i32* %11
br label %37
55: ; preds = %37
%56 = load i64, i64* %10
ret i64 %56
}

LLVM IR (-O2):
define i64 @read_ints_delta(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %6 to i8*
%9 = tail call i32 @_mm_set1_epi32(i32 %3)
store i32 %9, i32* %6
%10 = icmp sgt i32 %2, 15
br i1 %10, label %11, label %27
11: ; preds = %4
%12 = bitcast i32* %7 to i8*
br label %13
13: ; preds = %11, %13
%14 = phi i32 [ 0, %11 ], [ %22, %13 ]
%15 = phi i64 [ 0, %11 ], [ %20, %13 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = sext i32 %14 to i64
%18 = getelementptr inbounds i32, i32* %1, i64 %17
%19 = call i64 @read_int_group_delta(i32* %16, i32* %18, i32* %7, i32* %6)
%20 = add i64 %19, %15
%21 = load i32, i32* %7
%22 = add nsw i32 %21, %14
%23 = add nsw i32 %22, 15
%24 = icmp slt i32 %23, %2
br i1 %24, label %13, label %25
25: ; preds = %13
%26 = load i32, i32* %6
br label %27
27: ; preds = %25, %4
%28 = phi i32 [ %9, %4 ], [ %26, %25 ]
%29 = phi i64 [ 0, %4 ], [ %20, %25 ]
%30 = phi i32 [ 0, %4 ], [ %22, %25 ]
%31 = call i32 @_mm_extract_epi32(i32 %28, i32 3)
store i32 %31, i32* %5
%32 = icmp slt i32 %30, %2
br i1 %32, label %33, label %45
33: ; preds = %27
%34 = sext i32 %30 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ %34, %33 ], [ %42, %35 ]
%37 = phi i64 [ %29, %33 ], [ %41, %35 ]
%38 = getelementptr inbounds i32, i32* %0, i64 %37
%39 = getelementptr inbounds i32, i32* %1, i64 %36
%40 = call i64 @read_int_delta(i32* %38, i32* %39, i32* %5)
%41 = add i64 %40, %37
%42 = add nsw i64 %36, 1
%43 = trunc i64 %42 to i32
%44 = icmp eq i32 %43, %2
br i1 %44, label %45, label %35
45: ; preds = %35, %27
%46 = phi i64 [ %29, %27 ], [ %41, %35 ]
ret i64 %46
}