#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_average_2_U8(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                    int /*<<< orphan*/ const *);
int /*<<< orphan*/ mmx_zero_reg();
__attribute__((__always___)) void MC_avg_mmx(const int width, int height,
                                             uint8_t *dest, const uint8_t *ref,
                                             const int stride) {
  mmx_zero_reg();
  do {
    mmx_average_2_U8(dest, dest, ref);
    if (width == 16)
      mmx_average_2_U8(dest + 8, dest + 8, ref + 8);
    dest += stride;
    ref += stride;
  } while (--height);
}


x86 assembly (clang, -O0):
<MC_avg_mmx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <mmx_zero_reg@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <mmx_average_2_U8@plt>
cmpl   $0x10,-0x4(%rbp)
jne    1179 <MC_avg_mmx+0x59>
mov    -0x10(%rbp),%rdi
add    $0x20,%rdi
mov    -0x10(%rbp),%rsi
add    $0x20,%rsi
mov    -0x18(%rbp),%rdx
add    $0x20,%rdx
call   1030 <mmx_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    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    1141 <MC_avg_mmx+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MC_avg_mmx>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r12d
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r15d
xor    %eax,%eax
call   1040 <mmx_zero_reg@plt>
movslq %r12d,%r12
shl    $0x2,%r12
jmp    115b <MC_avg_mmx+0x3b>
cs nopw 0x0(%rax,%rax,1)
add    %r12,%rbx
add    %r12,%r14
add    $0xffffffff,%ebp
je     1181 <MC_avg_mmx+0x61>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <mmx_average_2_U8@plt>
cmp    $0x10,%r15d
jne    1150 <MC_avg_mmx+0x30>
lea    0x20(%rbx),%rdi
lea    0x20(%r14),%rdx
mov    %rdi,%rsi
call   1030 <mmx_average_2_U8@plt>
jmp    1150 <MC_avg_mmx+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @MC_avg_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
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
%11 = call i32 (...) @mmx_zero_reg()
br label %12
12: ; preds = %36, %5
%13 = load i32*, i32** %8
%14 = load i32*, i32** %8
%15 = load i32*, i32** %9
%16 = call i32 @mmx_average_2_U8(i32* %13, i32* %14, i32* %15)
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 16
br i1 %18, label %19, label %27
19: ; preds = %12
%20 = load i32*, i32** %8
%21 = getelementptr inbounds i32, i32* %20, i64 8
%22 = load i32*, i32** %8
%23 = getelementptr inbounds i32, i32* %22, i64 8
%24 = load i32*, i32** %9
%25 = getelementptr inbounds i32, i32* %24, i64 8
%26 = call i32 @mmx_average_2_U8(i32* %21, i32* %23, i32* %25)
br label %27
27: ; preds = %19, %12
%28 = load i32, i32* %10
%29 = load i32*, i32** %8
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i32, i32* %29, i64 %30
store i32* %31, i32** %8
%32 = load i32, i32* %10
%33 = load i32*, i32** %9
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i32, i32* %33, i64 %34
store i32* %35, i32** %9
br label %36
36: ; preds = %27
%37 = load i32, i32* %7
%38 = add nsw i32 %37, -1
store i32 %38, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %12, label %40
40: ; preds = %36
ret void
}

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