#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__ hamdist_uint(char const, char const);
unsigned int hamdist_str(const char *str1, const char *str2, unsigned int len) {
  unsigned int ham_dist = 0, i = 0;
  while (i < len) {
    ham_dist += hamdist_uint(*str2, *str1);
    str1++;
    str2++;
    i++;
  }
  return ham_dist;
}


x86 assembly (clang, -O0):
<hamdist_str>:
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    1184 <hamdist_str+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
movsbl %cl,%edi
movsbl (%rax),%esi
call   1030 <hamdist_uint@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <hamdist_str+0x21>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @hamdist_str(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 = %13, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = call i64 @hamdist_uint(i8 signext %15, i8 signext %17)
%19 = load i32, i32* %7
%20 = zext i32 %19 to i64
%21 = add nsw i64 %20, %18
%22 = trunc i64 %21 to i32
store i32 %22, i32* %7
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
%27 = load i32, i32* %8
%28 = add i32 %27, 1
store i32 %28, i32* %8
br label %9
29: ; preds = %9
%30 = load i32, i32* %7
ret i32 %30
}

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