#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 */
scalar_t__ abs_diff(unsigned char, unsigned char);
void get_cost2(unsigned char *ref, unsigned char *ref2, int *c) {
  *c += abs_diff(ref[0], ref2[0]);
  *c += abs_diff(ref[1], ref2[1]);
  *c += abs_diff(ref[2], ref2[2]);
  *c += abs_diff(ref[3], ref2[3]);
}


x86 assembly (clang, -O0):
<get_cost2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
movzbl %cl,%edi
movzbl (%rax),%esi
call   1030 <abs_diff@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq (%rax),%rcx
add    %rdx,%rcx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x10(%rbp),%rax
movzbl %cl,%edi
movzbl 0x1(%rax),%esi
call   1030 <abs_diff@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq (%rax),%rcx
add    %rdx,%rcx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x10(%rbp),%rax
movzbl %cl,%edi
movzbl 0x2(%rax),%esi
call   1030 <abs_diff@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq (%rax),%rcx
add    %rdx,%rcx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x3(%rax),%cl
mov    -0x10(%rbp),%rax
movzbl %cl,%edi
movzbl 0x3(%rax),%esi
call   1030 <abs_diff@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq (%rax),%rcx
add    %rdx,%rcx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cost2>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movzbl (%rdi),%edi
movzbl (%rsi),%esi
call   1030 <abs_diff@plt>
add    %eax,(%r14)
movzbl 0x1(%rbx),%edi
movzbl 0x1(%r15),%esi
call   1030 <abs_diff@plt>
add    %eax,(%r14)
movzbl 0x2(%rbx),%edi
movzbl 0x2(%r15),%esi
call   1030 <abs_diff@plt>
add    %eax,(%r14)
movzbl 0x3(%rbx),%edi
movzbl 0x3(%r15),%esi
call   1030 <abs_diff@plt>
add    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @get_cost2(i8* nocapture %0, i8* nocapture %1, i32* nocapture %2) {
%4 = load i8, i8* %0
%5 = load i8, i8* %1
%6 = tail call i64 @abs_diff(i8 zeroext %4, i8 zeroext %5)
%7 = load i32, i32* %2
%8 = trunc i64 %6 to i32
%9 = add i32 %7, %8
store i32 %9, i32* %2
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %1, i64 1
%13 = load i8, i8* %12
%14 = tail call i64 @abs_diff(i8 zeroext %11, i8 zeroext %13)
%15 = load i32, i32* %2
%16 = trunc i64 %14 to i32
%17 = add i32 %15, %16
store i32 %17, i32* %2
%18 = getelementptr inbounds i8, i8* %0, i64 2
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %1, i64 2
%21 = load i8, i8* %20
%22 = tail call i64 @abs_diff(i8 zeroext %19, i8 zeroext %21)
%23 = load i32, i32* %2
%24 = trunc i64 %22 to i32
%25 = add i32 %23, %24
store i32 %25, i32* %2
%26 = getelementptr inbounds i8, i8* %0, i64 3
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %1, i64 3
%29 = load i8, i8* %28
%30 = tail call i64 @abs_diff(i8 zeroext %27, i8 zeroext %29)
%31 = load i32, i32* %2
%32 = trunc i64 %30 to i32
%33 = add i32 %31, %32
store i32 %33, i32* %2
ret void
}