#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 */

/* Variables and functions */
int HadamardSAD8x8(int *);
int HadamardMB(int c_diff[256], int blocktype) {
  int sad = 0;
  switch (blocktype) {
  case 1:
    sad = HadamardSAD8x8(c_diff);
    sad += HadamardSAD8x8(&c_diff[64]);
    sad += HadamardSAD8x8(&c_diff[128]);
    sad += HadamardSAD8x8(&c_diff[192]);
    break;
  case 2:
  case 3:
    sad = HadamardSAD8x8(c_diff);
    sad += HadamardSAD8x8(&c_diff[64]);
    break;
  case 4:
    sad = HadamardSAD8x8(c_diff);
    break;
  default:
    sad = -1;
    break;
  }
  return sad;
}


x86 assembly (clang, -O0):
<HadamardMB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     115f <HadamardMB+0x4f>
jmp    113a <HadamardMB+0x2a>
mov    -0x14(%rbp),%eax
add    $0xfffffffe,%eax
sub    $0x2,%eax
jb     11b2 <HadamardMB+0xa2>
jmp    114e <HadamardMB+0x3e>
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
je     11d9 <HadamardMB+0xc9>
jmp    11ea <HadamardMB+0xda>
mov    -0x8(%rbp),%rdi
call   1030 <HadamardSAD8x8@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x100,%rdi
call   1030 <HadamardSAD8x8@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x200,%rdi
call   1030 <HadamardSAD8x8@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x300,%rdi
call   1030 <HadamardSAD8x8@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11f1 <HadamardMB+0xe1>
mov    -0x8(%rbp),%rdi
call   1030 <HadamardSAD8x8@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x100,%rdi
call   1030 <HadamardSAD8x8@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11f1 <HadamardMB+0xe1>
mov    -0x8(%rbp),%rdi
call   1030 <HadamardSAD8x8@plt>
mov    %eax,-0x10(%rbp)
jmp    11f1 <HadamardMB+0xe1>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HadamardMB>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    -0x2(%rsi),%eax
cmp    $0x2,%eax
jb     1170 <HadamardMB+0x60>
cmp    $0x4,%esi
je     1190 <HadamardMB+0x80>
mov    $0xffffffff,%eax
cmp    $0x1,%esi
jne    118b <HadamardMB+0x7b>
mov    %rbx,%rdi
call   1030 <HadamardSAD8x8@plt>
mov    %eax,%r14d
lea    0x100(%rbx),%rdi
call   1030 <HadamardSAD8x8@plt>
mov    %eax,%ebp
add    %r14d,%ebp
lea    0x200(%rbx),%rdi
call   1030 <HadamardSAD8x8@plt>
mov    %eax,%r14d
add    %ebp,%r14d
add    $0x300,%rbx
mov    %rbx,%rdi
call   1030 <HadamardSAD8x8@plt>
add    %r14d,%eax
jmp    118b <HadamardMB+0x7b>
mov    %rbx,%rdi
call   1030 <HadamardSAD8x8@plt>
mov    %eax,%ebp
add    $0x100,%rbx
mov    %rbx,%rdi
call   1030 <HadamardSAD8x8@plt>
add    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <HadamardSAD8x8@plt>

LLVM IR (-O0):
define i32 @HadamardMB(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %4
switch i32 %6, label %36 [
i32 1, label %7
i32 2, label %25
i32 3, label %25
i32 4, label %33
]
7: ; preds = %2
%8 = load i32*, i32** %3
%9 = call i32 @HadamardSAD8x8(i32* %8)
store i32 %9, i32* %5
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 64
%12 = call i32 @HadamardSAD8x8(i32* %11)
%13 = load i32, i32* %5
%14 = add nsw i32 %13, %12
store i32 %14, i32* %5
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 128
%17 = call i32 @HadamardSAD8x8(i32* %16)
%18 = load i32, i32* %5
%19 = add nsw i32 %18, %17
store i32 %19, i32* %5
%20 = load i32*, i32** %3
%21 = getelementptr inbounds i32, i32* %20, i64 192
%22 = call i32 @HadamardSAD8x8(i32* %21)
%23 = load i32, i32* %5
%24 = add nsw i32 %23, %22
store i32 %24, i32* %5
br label %37
25: ; preds = %2, %2
%26 = load i32*, i32** %3
%27 = call i32 @HadamardSAD8x8(i32* %26)
store i32 %27, i32* %5
%28 = load i32*, i32** %3
%29 = getelementptr inbounds i32, i32* %28, i64 64
%30 = call i32 @HadamardSAD8x8(i32* %29)
%31 = load i32, i32* %5
%32 = add nsw i32 %31, %30
store i32 %32, i32* %5
br label %37
33: ; preds = %2
%34 = load i32*, i32** %3
%35 = call i32 @HadamardSAD8x8(i32* %34)
store i32 %35, i32* %5
br label %37
36: ; preds = %2
store i32 -1, i32* %5
br label %37
37: ; preds = %36, %33, %25, %7
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
define i32 @HadamardMB(i32* %0, i32 %1) {
switch i32 %1, label %21 [
i32 1, label %3
i32 2, label %14
i32 3, label %14
i32 4, label %19
]
3: ; preds = %2
%4 = tail call i32 @HadamardSAD8x8(i32* %0)
%5 = getelementptr inbounds i32, i32* %0, i64 64
%6 = tail call i32 @HadamardSAD8x8(i32* %5)
%7 = add nsw i32 %6, %4
%8 = getelementptr inbounds i32, i32* %0, i64 128
%9 = tail call i32 @HadamardSAD8x8(i32* %8)
%10 = add nsw i32 %7, %9
%11 = getelementptr inbounds i32, i32* %0, i64 192
%12 = tail call i32 @HadamardSAD8x8(i32* %11)
%13 = add nsw i32 %10, %12
br label %21
14: ; preds = %2, %2
%15 = tail call i32 @HadamardSAD8x8(i32* %0)
%16 = getelementptr inbounds i32, i32* %0, i64 64
%17 = tail call i32 @HadamardSAD8x8(i32* %16)
%18 = add nsw i32 %17, %15
br label %21
19: ; preds = %2
%20 = tail call i32 @HadamardSAD8x8(i32* %0)
br label %21
21: ; preds = %2, %19, %14, %3
%22 = phi i32 [ %20, %19 ], [ %18, %14 ], [ %13, %3 ], [ -1, %2 ]
ret i32 %22
}