#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 /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *);
char *xorDataBlock(char *, int, char *, int);
int computeHammingDistance(char *dataOne, char *dataTwo, int numberOfBytes) {
  int result = 0;
  if (!dataOne || !dataTwo) {
    printf("Error: computeHammingDistance received null arguments.\n");
    return result;
  } else if (numberOfBytes < 1) {
    printf("Error: computeHammingDistance number of bytes less than one.\n");
    return result;
  }
  for (int i = 0; i < numberOfBytes; i++) {
    char *xorResult = xorDataBlock(dataOne + i, 1, dataTwo + i, 1);
    if (!xorResult) {
      printf("Error: computeHammingDistance call to xorDataBlock failed.\n");
      return result;
    }
    for (int j = 0; j < 8; j++) {
      int isBitSet = ((xorResult[0] >> j) % 2) ? 1 : 0;
      result += isBitSet;
    }
    free(xorResult);
  }
  return result;
}


x86 assembly (clang, -O0):
<computeHammingDistance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1160 <computeHammingDistance+0x30>
cmpq   $0x0,-0x18(%rbp)
jne    1177 <computeHammingDistance+0x47>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1261 <computeHammingDistance+0x131>
cmpl   $0x1,-0x1c(%rbp)
jge    1198 <computeHammingDistance+0x68>
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1261 <computeHammingDistance+0x131>
jmp    119d <computeHammingDistance+0x6d>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    125b <computeHammingDistance+0x12b>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
movslq -0x24(%rbp),%rax
add    %rax,%rdx
mov    $0x1,%ecx
mov    %ecx,%esi
call   1050 <xorDataBlock@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f8 <computeHammingDistance+0xc8>
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1261 <computeHammingDistance+0x131>
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jge    1244 <computeHammingDistance+0x114>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
mov    -0x34(%rbp),%ecx
sar    %cl,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ff <computeHammingDistance+0xcf>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a4 <computeHammingDistance+0x74>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeHammingDistance>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r13d,%r13d
lea    0xebb(%rip),%r14
test   %rdi,%rdi
je     1207 <computeHammingDistance+0xd7>
mov    %rsi,%r15
test   %rsi,%rsi
je     1207 <computeHammingDistance+0xd7>
test   %edx,%edx
jle    1200 <computeHammingDistance+0xd0>
mov    %rdi,%rbx
mov    %edx,%r12d
xor    %r13d,%r13d
lea    0xec5(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    $0x1,%ecx
call   1050 <xorDataBlock@plt>
test   %rax,%rax
je     1207 <computeHammingDistance+0xd7>
movzbl (%rax),%ebp
mov    %ebp,%ecx
and    $0x1,%ecx
add    %r13d,%ecx
mov    %ebp,%edx
shr    %edx
and    $0x1,%edx
add    %ecx,%edx
mov    %ebp,%ecx
shr    $0x2,%ecx
and    $0x1,%ecx
add    %edx,%ecx
mov    %ebp,%edx
shr    $0x3,%edx
and    $0x1,%edx
add    %ecx,%edx
mov    %ebp,%ecx
shr    $0x4,%ecx
and    $0x1,%ecx
add    %edx,%ecx
mov    %ebp,%edx
shr    $0x5,%edx
and    $0x1,%edx
add    %ecx,%edx
mov    %ebp,%ecx
shr    $0x6,%ecx
and    $0x1,%ecx
add    %edx,%ecx
shr    $0x7,%ebp
add    %ecx,%ebp
mov    %rax,%rdi
call   1030 <free@plt>
add    $0x1,%r15
add    $0x1,%rbx
mov    %ebp,%r13d
add    $0xffffffffffffffff,%r12
jne    1180 <computeHammingDistance+0x50>
jmp    1212 <computeHammingDistance+0xe2>
lea    0xe6b(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r13d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Error: computeHammingDistance received null arguments.\0A\00"
@.str.1 = [62 x i8] c"Error: computeHammingDistance number of bytes less than one.\0A\00"
@.str.2 = [60 x i8] c"Error: computeHammingDistance call to xorDataBlock failed.\0A\00"
define i32 @computeHammingDistance(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %15, %3
%19 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %8
store i32 %20, i32* %4
br label %77
21: ; preds = %15
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* %8
store i32 %26, i32* %4
br label %77
27: ; preds = %21
br label %28
28: ; preds = %27
store i32 0, i32* %9
br label %29
29: ; preds = %72, %28
%30 = load i32, i32* %9
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %75
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8*, i8** %6
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = call i8* @xorDataBlock(i8* %37, i32 1, i8* %41, i32 1)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
%44 = icmp ne i8* %43, null
br i1 %44, label %48, label %45
45: ; preds = %33
%46 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* %8
store i32 %47, i32* %4
br label %77
48: ; preds = %33
store i32 0, i32* %11
br label %49
49: ; preds = %66, %48
%50 = load i32, i32* %11
%51 = icmp slt i32 %50, 8
br i1 %51, label %52, label %69
52: ; preds = %49
%53 = load i8*, i8** %10
%54 = getelementptr inbounds i8, i8* %53, i64 0
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = load i32, i32* %11
%58 = ashr i32 %56, %57
%59 = srem i32 %58, 2
%60 = icmp ne i32 %59, 0
%61 = zext i1 %60 to i64
%62 = select i1 %60, i32 1, i32 0
store i32 %62, i32* %12
%63 = load i32, i32* %12
%64 = load i32, i32* %8
%65 = add nsw i32 %64, %63
store i32 %65, i32* %8
br label %66
66: ; preds = %52
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %49
69: ; preds = %49
%70 = load i8*, i8** %10
%71 = call i32 @free(i8* %70)
br label %72
72: ; preds = %69
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
store i32 %74, i32* %9
br label %29
75: ; preds = %29
%76 = load i32, i32* %8
store i32 %76, i32* %4
br label %77
77: ; preds = %75, %45, %24, %18
%78 = load i32, i32* %4
ret i32 %78
}

LLVM IR (-O2):
@str = [55 x i8] c"Error: computeHammingDistance received null arguments.\00"
@str.3 = [59 x i8] c"Error: computeHammingDistance call to xorDataBlock failed.\00"
@str.4 = [61 x i8] c"Error: computeHammingDistance number of bytes less than one.\00"
define i32 @computeHammingDistance(i8* %0, i8* %1, i32 %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
br i1 %6, label %7, label %46
7: ; preds = %3
%8 = icmp slt i32 %2, 1
br i1 %8, label %46, label %9
9: ; preds = %7
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %18
%12 = phi i64 [ 0, %9 ], [ %44, %18 ]
%13 = phi i32 [ 0, %9 ], [ %42, %18 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %12
%15 = getelementptr inbounds i8, i8* %1, i64 %12
%16 = tail call i8* @xorDataBlock(i8* %14, i32 1, i8* %15, i32 1)
%17 = icmp eq i8* %16, null
br i1 %17, label %46, label %18
18: ; preds = %11
%19 = load i8, i8* %16
%20 = zext i8 %19 to i32
%21 = and i32 %20, 1
%22 = add nsw i32 %21, %13
%23 = lshr i32 %20, 1
%24 = and i32 %23, 1
%25 = add nsw i32 %24, %22
%26 = lshr i32 %20, 2
%27 = and i32 %26, 1
%28 = add nsw i32 %27, %25
%29 = lshr i32 %20, 3
%30 = and i32 %29, 1
%31 = add nsw i32 %30, %28
%32 = lshr i32 %20, 4
%33 = and i32 %32, 1
%34 = add nsw i32 %33, %31
%35 = lshr i32 %20, 5
%36 = and i32 %35, 1
%37 = add nsw i32 %36, %34
%38 = lshr i32 %20, 6
%39 = and i32 %38, 1
%40 = add nsw i32 %39, %37
%41 = lshr i32 %20, 7
%42 = add nsw i32 %41, %40
%43 = tail call i32 @free(i8* %16)
%44 = add nuw nsw i64 %12, 1
%45 = icmp eq i64 %44, %10
br i1 %45, label %50, label %11
46: ; preds = %11, %7, %3
%47 = phi i8* [ getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([61 x i8], [61 x i8]* @str.4, i64 0, i64 0), %7 ], [ getelementptr inbounds ([59 x i8], [59 x i8]* @str.3, i64 0, i64 0), %11 ]
%48 = phi i32 [ 0, %3 ], [ 0, %7 ], [ %13, %11 ]
%49 = tail call i32 @puts(i8* dereferenceable(1) %47)
br label %50
50: ; preds = %18, %46
%51 = phi i32 [ %48, %46 ], [ %42, %18 ]
ret i32 %51
}