#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_4_U8(int /*<<< orphan*/ *,
                                    int /*<<< orphan*/ const *,
                                    int /*<<< orphan*/ const *,
                                    int /*<<< orphan*/ const *,
                                    int /*<<< orphan*/ const *);
int /*<<< orphan*/ mmx_zero_reg();
__attribute__((__always___)) void MC_put_xy_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_average_4_U8(dest, ref, ref + 1, ref_next, ref_next + 1);
    if (width == 16)
      mmx_average_4_U8(dest + 8, ref + 8, ref + 9, ref_next + 8, ref_next + 9);
    dest += stride;
    ref += stride;
    ref_next += stride;
  } while (--height);
}


x86 assembly (clang, -O0):
<MC_put_xy_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    -0x18(%rbp),%rdx
add    $0x4,%rdx
mov    -0x28(%rbp),%rcx
mov    -0x28(%rbp),%r8
add    $0x4,%r8
call   1030 <mmx_average_4_U8@plt>
cmpl   $0x10,-0x4(%rbp)
jne    11ac <MC_put_xy_mmx+0x8c>
mov    -0x10(%rbp),%rdi
add    $0x20,%rdi
mov    -0x18(%rbp),%rsi
add    $0x20,%rsi
mov    -0x18(%rbp),%rdx
add    $0x24,%rdx
mov    -0x28(%rbp),%rcx
add    $0x20,%rcx
mov    -0x28(%rbp),%r8
add    $0x24,%r8
call   1030 <mmx_average_4_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_put_xy_mmx+0x34>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MC_put_xy_mmx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,0x4(%rsp)
movslq %r8d,%r12
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <mmx_zero_reg@plt>
lea    0x0(,%r12,4),%r15
add    %r13,%r15
shl    $0x2,%r12
jmp    1168 <MC_put_xy_mmx+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %r12,%rbx
add    $0xffffffff,%ebp
je     11bc <MC_put_xy_mmx+0x9c>
lea    (%r14,%rbx,1),%rdi
lea    (%rbx,%r13,1),%rsi
lea    (%r15,%rbx,1),%rcx
lea    (%rbx,%r13,1),%rdx
add    $0x4,%rdx
lea    (%r15,%rbx,1),%r8
add    $0x4,%r8
call   1030 <mmx_average_4_U8@plt>
cmpl   $0x10,0x4(%rsp)
jne    1160 <MC_put_xy_mmx+0x40>
lea    (%r14,%rbx,1),%rdi
add    $0x20,%rdi
lea    0x20(%r13,%rbx,1),%rsi
lea    (%rbx,%r13,1),%rdx
add    $0x24,%rdx
lea    (%r15,%rbx,1),%rcx
add    $0x20,%rcx
lea    (%r15,%rbx,1),%r8
add    $0x24,%r8
call   1030 <mmx_average_4_U8@plt>
jmp    1160 <MC_put_xy_mmx+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @MC_put_xy_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 = %53, %5
%18 = load i32*, i32** %8
%19 = load i32*, i32** %9
%20 = load i32*, i32** %9
%21 = getelementptr inbounds i32, i32* %20, i64 1
%22 = load i32*, i32** %11
%23 = load i32*, i32** %11
%24 = getelementptr inbounds i32, i32* %23, i64 1
%25 = call i32 @mmx_average_4_U8(i32* %18, i32* %19, i32* %21, i32* %22, i32* %24)
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 16
br i1 %27, label %28, label %40
28: ; preds = %17
%29 = load i32*, i32** %8
%30 = getelementptr inbounds i32, i32* %29, i64 8
%31 = load i32*, i32** %9
%32 = getelementptr inbounds i32, i32* %31, i64 8
%33 = load i32*, i32** %9
%34 = getelementptr inbounds i32, i32* %33, i64 9
%35 = load i32*, i32** %11
%36 = getelementptr inbounds i32, i32* %35, i64 8
%37 = load i32*, i32** %11
%38 = getelementptr inbounds i32, i32* %37, i64 9
%39 = call i32 @mmx_average_4_U8(i32* %30, i32* %32, i32* %34, i32* %36, i32* %38)
br label %40
40: ; preds = %28, %17
%41 = load i32, i32* %10
%42 = load i32*, i32** %8
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i32, i32* %42, i64 %43
store i32* %44, i32** %8
%45 = load i32, i32* %10
%46 = load i32*, i32** %9
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i32, i32* %46, i64 %47
store i32* %48, i32** %9
%49 = load i32, i32* %10
%50 = load i32*, i32** %11
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i32, i32* %50, i64 %51
store i32* %52, i32** %11
br label %53
53: ; preds = %40
%54 = load i32, i32* %7
%55 = add nsw i32 %54, -1
store i32 %55, i32* %7
%56 = icmp ne i32 %55, 0
br i1 %56, label %17, label %57
57: ; preds = %53
ret void
}

LLVM IR (-O2):
define void @MC_put_xy_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 = %24, %5
%10 = phi i32* [ %2, %5 ], [ %25, %24 ]
%11 = phi i32* [ %3, %5 ], [ %13, %24 ]
%12 = phi i32 [ %1, %5 ], [ %26, %24 ]
%13 = getelementptr inbounds i32, i32* %11, i64 %6
%14 = getelementptr inbounds i32, i32* %11, i64 1
%15 = getelementptr inbounds i32, i32* %13, i64 1
%16 = tail call i32 @mmx_average_4_U8(i32* %10, i32* %11, i32* %14, i32* %13, i32* %15)
br i1 %8, label %17, label %24
17: ; preds = %9
%18 = getelementptr inbounds i32, i32* %10, i64 8
%19 = getelementptr inbounds i32, i32* %11, i64 8
%20 = getelementptr inbounds i32, i32* %11, i64 9
%21 = getelementptr inbounds i32, i32* %13, i64 8
%22 = getelementptr inbounds i32, i32* %13, i64 9
%23 = tail call i32 @mmx_average_4_U8(i32* %18, i32* %19, i32* %20, i32* %21, i32* %22)
br label %24
24: ; preds = %17, %9
%25 = getelementptr inbounds i32, i32* %10, i64 %6
%26 = add nsw i32 %12, -1
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %9
28: ; preds = %24
ret void
}