#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(unsigned char, unsigned char);
int hash_hamdist(unsigned char *x, unsigned char *y, int hash_len,
                 unsigned int max) {
  unsigned int dist = 0;
  int i;
  for (i = 0; i < hash_len; i++) {
    dist += hamdist(x[i], y[i]);
    if (dist >= max) {
      return -1;
    }
  }
  return dist;
}


x86 assembly (clang, -O0):
<hash_hamdist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1196 <hash_hamdist+0x86>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl %dl,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <hamdist@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jb     1183 <hash_hamdist+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <hash_hamdist+0x8c>
jmp    1188 <hash_hamdist+0x78>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1134 <hash_hamdist+0x24>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_hamdist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1154 <hash_hamdist+0x44>
mov    %ecx,%r14d
mov    %rsi,%r15
mov    %rdi,%r13
mov    %edx,%r12d
xor    %ebx,%ebx
xor    %eax,%eax
nop
mov    %eax,%ebp
movzbl 0x0(%r13,%rbx,1),%edi
movzbl (%r15,%rbx,1),%esi
call   1030 <hamdist@plt>
add    %ebp,%eax
cmp    %r14d,%eax
jae    1158 <hash_hamdist+0x48>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <hash_hamdist+0x20>
jmp    115d <hash_hamdist+0x4d>
xor    %eax,%eax
jmp    115d <hash_hamdist+0x4d>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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