#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 strlen(char *);
unsigned short hamming(char a[], char b[]) {
  unsigned short total = 0;
  for (int i = 0; i < strlen(a); i++)
    total += (a[i] != b[i]);
  return total;
}


x86 assembly (clang, -O0):
<hamming>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x0,-0x12(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1183 <hamming+0x73>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
setne  %al
and    $0x1,%al
movzbl %al,%ecx
movzwl -0x12(%rbp),%eax
add    %ecx,%eax
mov    %ax,-0x12(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112d <hamming+0x1d>
movzwl -0x12(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hamming>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    1155 <hamming+0x45>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
xor    %ecx,%ecx
cmp    (%r14,%rbx,1),%al
setne  %cl
add    %ecx,%ebp
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1130 <hamming+0x20>
jmp    1157 <hamming+0x47>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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