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


x86 assembly (clang, -O0):
<MC_put_x_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    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x4,%rdx
call   1030 <mmx_average_2_U8@plt>
cmpl   $0x10,-0x4(%rbp)
jne    117d <MC_put_x_mmx+0x5d>
mov    -0x10(%rbp),%rdi
add    $0x20,%rdi
mov    -0x18(%rbp),%rsi
add    $0x20,%rsi
mov    -0x18(%rbp),%rdx
add    $0x24,%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_put_x_mmx+0x21>
add    $0x20,%rsp
pop    %rbp
ret

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

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

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