#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*/ p264_mc_clip1(int);
int p264_tapfilter(int /*<<< orphan*/ *, int);
void mc_hv(uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride,
           int i_width, int i_height) {
  int x, y;
  for (y = 0; y < i_height; y++) {
    for (x = 0; x < i_width; x++) {
      dst[x] = p264_mc_clip1((p264_tapfilter(&src[x], i_src_stride) + 16) >> 5);
    }
    src += i_src_stride;
    dst += i_dst_stride;
  }
}


x86 assembly (clang, -O0):
<mc_hv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11db <mc_hv+0xbb>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11a3 <mc_hv+0x83>
mov    -0x8(%rbp),%rdi
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
call   1030 <p264_tapfilter@plt>
mov    %eax,%edi
add    $0x10,%edi
sar    $0x5,%edi
call   1040 <p264_mc_clip1@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1158 <mc_hv+0x38>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1145 <mc_hv+0x25>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mc_hv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,(%rsp)
mov    %r9d,0x4(%rsp)
test   %r9d,%r9d
jle    11b7 <mc_hv+0x97>
mov    %rdx,%rbp
mov    %esi,%r12d
mov    %rdi,%rbx
movslq %esi,%rax
movslq %ecx,%rcx
mov    (%rsp),%r15d
shl    $0x2,%rcx
mov    %rcx,0x8(%rsp)
shl    $0x2,%rax
mov    %rax,0x10(%rsp)
shl    $0x2,%r15
xor    %r13d,%r13d
jmp    1185 <mc_hv+0x65>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13d
add    0x8(%rsp),%rbp
add    0x10(%rsp),%rbx
cmp    0x4(%rsp),%r13d
je     11b7 <mc_hv+0x97>
cmpl   $0x0,(%rsp)
jle    1170 <mc_hv+0x50>
xor    %r14d,%r14d
xchg   %ax,%ax
lea    (%rbx,%r14,1),%rdi
mov    %r12d,%esi
call   1030 <p264_tapfilter@plt>
lea    0x10(%rax),%edi
sar    $0x5,%edi
call   1040 <p264_mc_clip1@plt>
mov    %eax,0x0(%rbp,%r14,1)
add    $0x4,%r14
cmp    %r14,%r15
jne    1190 <mc_hv+0x70>
jmp    1170 <mc_hv+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @mc_hv(i32* %0, i32 %1, i32* nocapture writeonly %2, i32 %3, i32 %4, i32 %5) {
%7 = icmp sgt i32 %5, 0
br i1 %7, label %8, label %32
8: ; preds = %6
%9 = icmp sgt i32 %4, 0
%10 = sext i32 %1 to i64
%11 = sext i32 %3 to i64
%12 = zext i32 %4 to i64
br label %13
13: ; preds = %8, %27
%14 = phi i32 [ 0, %8 ], [ %30, %27 ]
%15 = phi i32* [ %0, %8 ], [ %28, %27 ]
%16 = phi i32* [ %2, %8 ], [ %29, %27 ]
br i1 %9, label %17, label %27
17: ; preds = %13, %17
%18 = phi i64 [ %25, %17 ], [ 0, %13 ]
%19 = getelementptr inbounds i32, i32* %15, i64 %18
%20 = tail call i32 @p264_tapfilter(i32* %19, i32 %1)
%21 = add nsw i32 %20, 16
%22 = ashr i32 %21, 5
%23 = tail call i32 @p264_mc_clip1(i32 %22)
%24 = getelementptr inbounds i32, i32* %16, i64 %18
store i32 %23, i32* %24
%25 = add nuw nsw i64 %18, 1
%26 = icmp eq i64 %25, %12
br i1 %26, label %27, label %17
27: ; preds = %17, %13
%28 = getelementptr inbounds i32, i32* %15, i64 %10
%29 = getelementptr inbounds i32, i32* %16, i64 %11
%30 = add nuw nsw i32 %14, 1
%31 = icmp eq i32 %30, %5
br i1 %31, label %32, label %13
32: ; preds = %27, %6
ret void
}