#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__ count_bits(char);
unsigned int get_hamming_distance(char *str1, char *str2, unsigned int length) {
  unsigned int count = 0;
  for (unsigned int i = 0; i < length; ++i) {
    count += count_bits(str1[i] ^ str2[i]);
  }
  return count;
}


x86 assembly (clang, -O0):
<get_hamming_distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1177 <get_hamming_distance+0x67>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
movsbl %al,%edi
call   1030 <count_bits@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <get_hamming_distance+0x21>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hamming_distance>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
je     114e <get_hamming_distance+0x3e>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
movzbl (%r14,%rbx,1),%eax
xor    (%r15,%rbx,1),%al
movsbl %al,%edi
call   1030 <count_bits@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <get_hamming_distance+0x20>
jmp    1150 <get_hamming_distance+0x40>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_hamming_distance(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %33, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i32, i32* %8
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i8*, i8** %5
%21 = load i32, i32* %8
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = xor i32 %19, %25
%27 = trunc i32 %26 to i8
%28 = call i64 @count_bits(i8 signext %27)
%29 = load i32, i32* %7
%30 = zext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %7
br label %33
33: ; preds = %13
%34 = load i32, i32* %8
%35 = add i32 %34, 1
store i32 %35, i32* %8
br label %9
36: ; preds = %9
%37 = load i32, i32* %7
ret i32 %37
}

LLVM IR (-O2):
define i32 @get_hamming_distance(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %9
7: ; preds = %9, %3
%8 = phi i32 [ 0, %3 ], [ %19, %9 ]
ret i32 %8
9: ; preds = %5, %9
%10 = phi i64 [ 0, %5 ], [ %20, %9 ]
%11 = phi i32 [ 0, %5 ], [ %19, %9 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %1, i64 %10
%15 = load i8, i8* %14
%16 = xor i8 %15, %13
%17 = tail call i64 @count_bits(i8 signext %16)
%18 = trunc i64 %17 to i32
%19 = add i32 %11, %18
%20 = add nuw nsw i64 %10, 1
%21 = icmp eq i64 %20, %6
br i1 %21, label %7, label %9
}