#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 int32_t;
typedef int /*<<< orphan*/ int16_t;

/* Variables and functions */
int abs(int);
int /*<<< orphan*/ get_scaled_mv(int /*<<< orphan*/, int);
void apply_mv_scaling_pocs(int32_t current_poc, int32_t current_ref_poc,
                           int32_t neighbor_poc, int32_t neighbor_ref_poc,
                           int16_t mv_cand[2]) {
  int32_t diff_current = current_poc - current_ref_poc;
  int32_t diff_neighbor = neighbor_poc - neighbor_ref_poc;
  if (diff_current == diff_neighbor)
    return;
  diff_current =
      ((((-128)) >
        (((((127)) < ((diff_current))) ? ((127)) : ((diff_current)))))
           ? ((-128))
           : (((((127)) < ((diff_current))) ? ((127)) : ((diff_current)))));
  diff_neighbor =
      ((((-128)) >
        (((((127)) < ((diff_neighbor))) ? ((127)) : ((diff_neighbor)))))
           ? ((-128))
           : (((((127)) < ((diff_neighbor))) ? ((127)) : ((diff_neighbor)))));
  int scale =
      ((((-4096)) >
        (((((4095)) < (((diff_current * ((0x4000 + (abs(diff_neighbor) >> 1)) /
                                         diff_neighbor) +
                         32) >>
                        6)))
              ? ((4095))
              : (((diff_current *
                       ((0x4000 + (abs(diff_neighbor) >> 1)) / diff_neighbor) +
                   32) >>
                  6)))))
           ? ((-4096))
           : (((((4095)) <
                (((diff_current *
                       ((0x4000 + (abs(diff_neighbor) >> 1)) / diff_neighbor) +
                   32) >>
                  6)))
                   ? ((4095))
                   : (((diff_current * ((0x4000 + (abs(diff_neighbor) >> 1)) /
                                        diff_neighbor) +
                        32) >>
                       6)))));
  mv_cand[0] = get_scaled_mv(mv_cand[0], scale);
  mv_cand[1] = get_scaled_mv(mv_cand[1], scale);
}


x86 assembly (clang, -O0):
<apply_mv_scaling_pocs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    115b <apply_mv_scaling_pocs+0x3b>
jmp    135e <apply_mv_scaling_pocs+0x23e>
mov    $0x7f,%eax
cmp    -0x1c(%rbp),%eax
jge    1176 <apply_mv_scaling_pocs+0x56>
mov    $0x7f,%eax
mov    %eax,-0x28(%rbp)
jmp    117c <apply_mv_scaling_pocs+0x5c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    $0xffffff80,%eax
cmp    %ecx,%eax
jle    1199 <apply_mv_scaling_pocs+0x79>
mov    $0xffffff80,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c0 <apply_mv_scaling_pocs+0xa0>
mov    $0x7f,%eax
cmp    -0x1c(%rbp),%eax
jge    11b4 <apply_mv_scaling_pocs+0x94>
mov    $0x7f,%eax
mov    %eax,-0x30(%rbp)
jmp    11ba <apply_mv_scaling_pocs+0x9a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x7f,%eax
cmp    -0x20(%rbp),%eax
jge    11e1 <apply_mv_scaling_pocs+0xc1>
mov    $0x7f,%eax
mov    %eax,-0x34(%rbp)
jmp    11e7 <apply_mv_scaling_pocs+0xc7>
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
mov    $0xffffff80,%eax
cmp    %ecx,%eax
jle    1204 <apply_mv_scaling_pocs+0xe4>
mov    $0xffffff80,%eax
mov    %eax,-0x38(%rbp)
jmp    122b <apply_mv_scaling_pocs+0x10b>
mov    $0x7f,%eax
cmp    -0x20(%rbp),%eax
jge    121f <apply_mv_scaling_pocs+0xff>
mov    $0x7f,%eax
mov    %eax,-0x3c(%rbp)
jmp    1225 <apply_mv_scaling_pocs+0x105>
mov    -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <abs@plt>
mov    -0x40(%rbp),%ecx
sar    $0x1,%eax
add    $0x4000,%eax
cltd
idivl  -0x20(%rbp)
imul   %eax,%ecx
add    $0x20,%ecx
sar    $0x6,%ecx
mov    $0xfff,%eax
cmp    %ecx,%eax
jge    1271 <apply_mv_scaling_pocs+0x151>
mov    $0xfff,%eax
mov    %eax,-0x44(%rbp)
jmp    129c <apply_mv_scaling_pocs+0x17c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <abs@plt>
sar    $0x1,%eax
add    $0x4000,%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
imul   %ecx,%eax
add    $0x20,%eax
sar    $0x6,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%ecx
mov    $0xfffff000,%eax
cmp    %ecx,%eax
jle    12b9 <apply_mv_scaling_pocs+0x199>
mov    $0xfffff000,%eax
mov    %eax,-0x4c(%rbp)
jmp    132a <apply_mv_scaling_pocs+0x20a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <abs@plt>
mov    -0x50(%rbp),%ecx
sar    $0x1,%eax
add    $0x4000,%eax
cltd
idivl  -0x20(%rbp)
imul   %eax,%ecx
add    $0x20,%ecx
sar    $0x6,%ecx
mov    $0xfff,%eax
cmp    %ecx,%eax
jge    12f9 <apply_mv_scaling_pocs+0x1d9>
mov    $0xfff,%eax
mov    %eax,-0x54(%rbp)
jmp    1324 <apply_mv_scaling_pocs+0x204>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <abs@plt>
sar    $0x1,%eax
add    $0x4000,%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
imul   %ecx,%eax
add    $0x20,%eax
sar    $0x6,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%esi
call   1040 <get_scaled_mv@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x24(%rbp),%esi
call   1040 <get_scaled_mv@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_mv_scaling_pocs>:
sub    %esi,%edi
sub    %ecx,%edx
cmp    %edx,%edi
je     1196 <apply_mv_scaling_pocs+0x86>
push   %rbp
push   %rbx
push   %rax
mov    %r8,%rbx
cmp    $0x7f,%edi
mov    $0x7f,%ecx
cmovge %ecx,%edi
cmp    $0xffffff81,%edi
mov    $0xffffff80,%eax
cmovl  %eax,%edi
cmp    $0x7f,%edx
cmovl  %edx,%ecx
cmp    $0xffffff81,%ecx
cmovl  %eax,%ecx
mov    %ecx,%eax
neg    %eax
cmovs  %ecx,%eax
shr    %eax
add    $0x4000,%eax
cwtd
idiv   %cx
cwtl
imul   %edi,%eax
lea    0x20(%rax),%ecx
sar    $0x6,%ecx
cmp    $0x3ffe0,%eax
mov    $0xfff,%edx
cmovl  %ecx,%edx
cmp    $0xfffbffe0,%eax
mov    $0xfffff000,%ebp
cmovge %edx,%ebp
mov    (%r8),%edi
mov    %ebp,%esi
call   1030 <get_scaled_mv@plt>
mov    %eax,(%rbx)
mov    0x4(%rbx),%edi
mov    %ebp,%esi
call   1030 <get_scaled_mv@plt>
mov    %eax,0x4(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @apply_mv_scaling_pocs(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
%12 = alloca i32
%13 = 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
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = sub nsw i32 %14, %15
store i32 %16, i32* %11
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = sub nsw i32 %17, %18
store i32 %19, i32* %12
%20 = load i32, i32* %11
%21 = load i32, i32* %12
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %5
br label %132
24: ; preds = %5
%25 = load i32, i32* %11
%26 = icmp slt i32 127, %25
br i1 %26, label %27, label %28
27: ; preds = %24
br label %30
28: ; preds = %24
%29 = load i32, i32* %11
br label %30
30: ; preds = %28, %27
%31 = phi i32 [ 127, %27 ], [ %29, %28 ]
%32 = icmp sgt i32 -128, %31
br i1 %32, label %33, label %34
33: ; preds = %30
br label %42
34: ; preds = %30
%35 = load i32, i32* %11
%36 = icmp slt i32 127, %35
br i1 %36, label %37, label %38
37: ; preds = %34
br label %40
38: ; preds = %34
%39 = load i32, i32* %11
br label %40
40: ; preds = %38, %37
%41 = phi i32 [ 127, %37 ], [ %39, %38 ]
br label %42
42: ; preds = %40, %33
%43 = phi i32 [ -128, %33 ], [ %41, %40 ]
store i32 %43, i32* %11
%44 = load i32, i32* %12
%45 = icmp slt i32 127, %44
br i1 %45, label %46, label %47
46: ; preds = %42
br label %49
47: ; preds = %42
%48 = load i32, i32* %12
br label %49
49: ; preds = %47, %46
%50 = phi i32 [ 127, %46 ], [ %48, %47 ]
%51 = icmp sgt i32 -128, %50
br i1 %51, label %52, label %53
52: ; preds = %49
br label %61
53: ; preds = %49
%54 = load i32, i32* %12
%55 = icmp slt i32 127, %54
br i1 %55, label %56, label %57
56: ; preds = %53
br label %59
57: ; preds = %53
%58 = load i32, i32* %12
br label %59
59: ; preds = %57, %56
%60 = phi i32 [ 127, %56 ], [ %58, %57 ]
br label %61
61: ; preds = %59, %52
%62 = phi i32 [ -128, %52 ], [ %60, %59 ]
store i32 %62, i32* %12
%63 = load i32, i32* %11
%64 = load i32, i32* %12
%65 = call i32 @abs(i32 %64)
%66 = ashr i32 %65, 1
%67 = add nsw i32 16384, %66
%68 = load i32, i32* %12
%69 = sdiv i32 %67, %68
%70 = mul nsw i32 %63, %69
%71 = add nsw i32 %70, 32
%72 = ashr i32 %71, 6
%73 = icmp slt i32 4095, %72
br i1 %73, label %74, label %75
74: ; preds = %61
br label %86
75: ; preds = %61
%76 = load i32, i32* %11
%77 = load i32, i32* %12
%78 = call i32 @abs(i32 %77)
%79 = ashr i32 %78, 1
%80 = add nsw i32 16384, %79
%81 = load i32, i32* %12
%82 = sdiv i32 %80, %81
%83 = mul nsw i32 %76, %82
%84 = add nsw i32 %83, 32
%85 = ashr i32 %84, 6
br label %86
86: ; preds = %75, %74
%87 = phi i32 [ 4095, %74 ], [ %85, %75 ]
%88 = icmp sgt i32 -4096, %87
br i1 %88, label %89, label %90
89: ; preds = %86
br label %116
90: ; preds = %86
%91 = load i32, i32* %11
%92 = load i32, i32* %12
%93 = call i32 @abs(i32 %92)
%94 = ashr i32 %93, 1
%95 = add nsw i32 16384, %94
%96 = load i32, i32* %12
%97 = sdiv i32 %95, %96
%98 = mul nsw i32 %91, %97
%99 = add nsw i32 %98, 32
%100 = ashr i32 %99, 6
%101 = icmp slt i32 4095, %100
br i1 %101, label %102, label %103
102: ; preds = %90
br label %114
103: ; preds = %90
%104 = load i32, i32* %11
%105 = load i32, i32* %12
%106 = call i32 @abs(i32 %105)
%107 = ashr i32 %106, 1
%108 = add nsw i32 16384, %107
%109 = load i32, i32* %12
%110 = sdiv i32 %108, %109
%111 = mul nsw i32 %104, %110
%112 = add nsw i32 %111, 32
%113 = ashr i32 %112, 6
br label %114
114: ; preds = %103, %102
%115 = phi i32 [ 4095, %102 ], [ %113, %103 ]
br label %116
116: ; preds = %114, %89
%117 = phi i32 [ -4096, %89 ], [ %115, %114 ]
store i32 %117, i32* %13
%118 = load i32*, i32** %10
%119 = getelementptr inbounds i32, i32* %118, i64 0
%120 = load i32, i32* %119
%121 = load i32, i32* %13
%122 = call i32 @get_scaled_mv(i32 %120, i32 %121)
%123 = load i32*, i32** %10
%124 = getelementptr inbounds i32, i32* %123, i64 0
store i32 %122, i32* %124
%125 = load i32*, i32** %10
%126 = getelementptr inbounds i32, i32* %125, i64 1
%127 = load i32, i32* %126
%128 = load i32, i32* %13
%129 = call i32 @get_scaled_mv(i32 %127, i32 %128)
%130 = load i32*, i32** %10
%131 = getelementptr inbounds i32, i32* %130, i64 1
store i32 %129, i32* %131
br label %132
132: ; preds = %116, %23
ret void
}

LLVM IR (-O2):
define void @apply_mv_scaling_pocs(i32 %0, i32 %1, i32 %2, i32 %3, i32* nocapture %4) {
%6 = sub nsw i32 %0, %1
%7 = sub nsw i32 %2, %3
%8 = icmp eq i32 %6, %7
br i1 %8, label %37, label %9
9: ; preds = %5
%10 = icmp slt i32 %6, 127
%11 = select i1 %10, i32 %6, i32 127
%12 = icmp sgt i32 %11, -128
%13 = select i1 %12, i32 %11, i32 -128
%14 = icmp slt i32 %7, 127
%15 = select i1 %14, i32 %7, i32 127
%16 = icmp sgt i32 %15, -128
%17 = select i1 %16, i32 %15, i32 -128
%18 = tail call i32 @llvm.abs.i32(i32 %17, i1 true)
%19 = lshr i32 %18, 1
%20 = trunc i32 %19 to i16
%21 = add nuw nsw i16 %20, 16384
%22 = trunc i32 %17 to i16
%23 = sdiv i16 %21, %22
%24 = sext i16 %23 to i32
%25 = mul nsw i32 %13, %24
%26 = add nsw i32 %25, 32
%27 = ashr i32 %26, 6
%28 = icmp sgt i32 %25, 262111
%29 = icmp slt i32 %25, -262176
%30 = select i1 %28, i32 4095, i32 %27
%31 = select i1 %29, i32 -4096, i32 %30
%32 = load i32, i32* %4
%33 = tail call i32 @get_scaled_mv(i32 %32, i32 %31)
store i32 %33, i32* %4
%34 = getelementptr inbounds i32, i32* %4, i64 1
%35 = load i32, i32* %34
%36 = tail call i32 @get_scaled_mv(i32 %35, i32 %31)
store i32 %36, i32* %34
br label %37
37: ; preds = %5, %9
ret void
}