#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;

/* Variables and functions */
int /*<<< orphan*/ mmx_interp_average_2_U8(int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ const *,
                                           int /*<<< orphan*/ const *);
int /*<<< orphan*/ mmx_zero_reg();
__attribute__((__always___)) void MC_avg_y_mmx(const int width, int height,
                                               uint8_t *dest,
                                               const uint8_t *ref,
                                               const int stride) {
  const uint8_t *ref_next = ref + stride;
  mmx_zero_reg();
  do {
    mmx_interp_average_2_U8(dest, ref, ref_next);
    if (width == 16)
      mmx_interp_average_2_U8(dest + 8, ref + 8, ref_next + 8);
    dest += stride;
    ref += stride;
    ref_next += stride;
  } while (--height);
}


x86 assembly (clang, -O0):
<MC_avg_y_mmx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <mmx_zero_reg@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <mmx_interp_average_2_U8@plt>
cmpl   $0x10,-0x4(%rbp)
jne    118c <MC_avg_y_mmx+0x6c>
mov    -0x10(%rbp),%rdi
add    $0x20,%rdi
mov    -0x18(%rbp),%rsi
add    $0x20,%rsi
mov    -0x28(%rbp),%rdx
add    $0x20,%rdx
call   1030 <mmx_interp_average_2_U8@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    1154 <MC_avg_y_mmx+0x34>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MC_avg_y_mmx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%r14d
movslq %r8d,%r13
xor    %eax,%eax
call   1040 <mmx_zero_reg@plt>
lea    0x20(,%r13,4),%rax
mov    %rax,(%rsp)
shl    $0x2,%r13
jmp    116c <MC_avg_y_mmx+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %r13,%rbx
mov    %r12,%rbp
add    $0xffffffff,%r15d
je     119c <MC_avg_y_mmx+0x7c>
mov    %rbp,%r12
add    %r13,%r12
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1030 <mmx_interp_average_2_U8@plt>
cmp    $0x10,%r14d
jne    1160 <MC_avg_y_mmx+0x40>
lea    0x20(%rbx),%rdi
lea    0x20(%rbp),%rsi
add    (%rsp),%rbp
mov    %rbp,%rdx
call   1030 <mmx_interp_average_2_U8@plt>
jmp    1160 <MC_avg_y_mmx+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @MC_avg_y_mmx(i32 %0, i32 %1, i32* %2, i32* %3, i32 %4) {
%6 = sext i32 %4 to i64
%7 = tail call i32 (...) @mmx_zero_reg()
%8 = icmp eq i32 %0, 16
br label %9
9: ; preds = %20, %5
%10 = phi i32* [ %2, %5 ], [ %21, %20 ]
%11 = phi i32* [ %3, %5 ], [ %13, %20 ]
%12 = phi i32 [ %1, %5 ], [ %22, %20 ]
%13 = getelementptr inbounds i32, i32* %11, i64 %6
%14 = tail call i32 @mmx_interp_average_2_U8(i32* %10, i32* %11, i32* %13)
br i1 %8, label %15, label %20
15: ; preds = %9
%16 = getelementptr inbounds i32, i32* %10, i64 8
%17 = getelementptr inbounds i32, i32* %11, i64 8
%18 = getelementptr inbounds i32, i32* %13, i64 8
%19 = tail call i32 @mmx_interp_average_2_U8(i32* %16, i32* %17, i32* %18)
br label %20
20: ; preds = %15, %9
%21 = getelementptr inbounds i32, i32* %10, i64 %6
%22 = add nsw i32 %12, -1
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %9
24: ; preds = %20
ret void
}