#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 */
unsigned char *alloca(int);
int atoi(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ hexStringToBin(unsigned char *, char const *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
double normalizedHammingDistance(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
double handleInput(const char *a, const char *b, const char *c) {
  int bitcount, len;
  unsigned char *str1, *str2;
  bitcount = atoi(c);
  if (bitcount == 0) {
    fprintf(stderr, "invalid bitcount %s\n", c);
    return -1;
  }
  len = strlen(a) / 2 + strlen(a) % 2;
  bitcount = ((bitcount) < (len * 8) ? (bitcount) : (len * 8));
  str1 = alloca(len);
  memset(str1, 0, len);
  if (!hexStringToBin(str1, a)) {
    fprintf(stderr, "invalid hex string %s\n", a);
    return -1;
  }
  len = strlen(b) / 2 + strlen(b) % 2;
  bitcount = ((bitcount) < (len * 8) ? (bitcount) : (len * 8));
  str2 = alloca(len);
  memset(str2, 0, len);
  if (!hexStringToBin(str2, b)) {
    fprintf(stderr, "invalid hex string %s\n", b);
    return -1;
  }
  return normalizedHammingDistance(str1, str2, bitcount);
}


x86 assembly (clang, -O0):
<handleInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11c5 <handleInput+0x55>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1050 <fprintf@plt>
movsd  0xe45(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1340 <handleInput+0x1d0>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x3c(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
shl    $0x3,%ecx
cmp    %ecx,%eax
jge    120e <handleInput+0x9e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    1217 <handleInput+0xa7>
mov    -0x28(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
call   1060 <alloca@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <hexStringToBin@plt>
cmp    $0x0,%eax
jne    1278 <handleInput+0x108>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdbc(%rip),%rsi
call   1050 <fprintf@plt>
movsd  0xd92(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1340 <handleInput+0x1d0>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x44(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
shl    $0x3,%ecx
cmp    %ecx,%eax
jge    12c1 <handleInput+0x151>
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    12ca <handleInput+0x15a>
mov    -0x28(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
call   1060 <alloca@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <hexStringToBin@plt>
cmp    $0x0,%eax
jne    132b <handleInput+0x1bb>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd09(%rip),%rsi
call   1050 <fprintf@plt>
movsd  0xcdf(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1340 <handleInput+0x1d0>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1080 <normalizedHammingDistance@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleInput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdx,%rdi
call   1090 <atoi@plt>
test   %eax,%eax
je     1266 <handleInput+0xf6>
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
add    %eax,%ebx
lea    0x0(,%rbx,8),%r13d
cmp    %r13d,%ebp
cmovl  %ebp,%r13d
mov    %ebx,%edi
call   1060 <alloca@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <hexStringToBin@plt>
test   %eax,%eax
je     127b <handleInput+0x10b>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
shr    $0x1f,%eax
add    %ebx,%eax
and    $0xfffffffe,%eax
sub    %eax,%ebx
add    %ebp,%ebx
mov    %ebx,%edi
call   1060 <alloca@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <hexStringToBin@plt>
test   %eax,%eax
je     1290 <handleInput+0x120>
shl    $0x3,%ebx
cmp    %ebx,%r13d
cmovl  %r13d,%ebx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <normalizedHammingDistance@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    %rbx,%rdx
jmp    12a3 <handleInput+0x133>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    %r12,%rdx
jmp    12a3 <handleInput+0x133>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
movsd  0xd50(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"invalid bitcount %s\0A\00"
@.str.1 = [23 x i8] c"invalid hex string %s\0A\00"
define double @handleInput(i8* %0, i8* %1, i8* %2) {
%4 = alloca double
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %7
%13 = call i32 @atoi(i8* %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %7
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %18)
store double -1.000000e+00, double* %4
br label %89
20: ; preds = %3
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = sdiv i32 %22, 2
%24 = load i8*, i8** %5
%25 = call i32 @strlen(i8* %24)
%26 = srem i32 %25, 2
%27 = add nsw i32 %23, %26
store i32 %27, i32* %9
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = mul nsw i32 %29, 8
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = load i32, i32* %8
br label %37
34: ; preds = %20
%35 = load i32, i32* %9
%36 = mul nsw i32 %35, 8
br label %37
37: ; preds = %34, %32
%38 = phi i32 [ %33, %32 ], [ %36, %34 ]
store i32 %38, i32* %8
%39 = load i32, i32* %9
%40 = call i8* @alloca(i32 %39)
store i8* %40, i8** %10
%41 = load i8*, i8** %10
%42 = load i32, i32* %9
%43 = call i32 @memset(i8* %41, i32 0, i32 %42)
%44 = load i8*, i8** %10
%45 = load i8*, i8** %5
%46 = call i32 @hexStringToBin(i8* %44, i8* %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %37
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %5
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %50)
store double -1.000000e+00, double* %4
br label %89
52: ; preds = %37
%53 = load i8*, i8** %6
%54 = call i32 @strlen(i8* %53)
%55 = sdiv i32 %54, 2
%56 = load i8*, i8** %6
%57 = call i32 @strlen(i8* %56)
%58 = srem i32 %57, 2
%59 = add nsw i32 %55, %58
store i32 %59, i32* %9
%60 = load i32, i32* %8
%61 = load i32, i32* %9
%62 = mul nsw i32 %61, 8
%63 = icmp slt i32 %60, %62
br i1 %63, label %64, label %66
64: ; preds = %52
%65 = load i32, i32* %8
br label %69
66: ; preds = %52
%67 = load i32, i32* %9
%68 = mul nsw i32 %67, 8
br label %69
69: ; preds = %66, %64
%70 = phi i32 [ %65, %64 ], [ %68, %66 ]
store i32 %70, i32* %8
%71 = load i32, i32* %9
%72 = call i8* @alloca(i32 %71)
store i8* %72, i8** %11
%73 = load i8*, i8** %11
%74 = load i32, i32* %9
%75 = call i32 @memset(i8* %73, i32 0, i32 %74)
%76 = load i8*, i8** %11
%77 = load i8*, i8** %6
%78 = call i32 @hexStringToBin(i8* %76, i8* %77)
%79 = icmp ne i32 %78, 0
br i1 %79, label %84, label %80
80: ; preds = %69
%81 = load i32, i32* @stderr
%82 = load i8*, i8** %6
%83 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %82)
store double -1.000000e+00, double* %4
br label %89
84: ; preds = %69
%85 = load i8*, i8** %10
%86 = load i8*, i8** %11
%87 = load i32, i32* %8
%88 = call double @normalizedHammingDistance(i8* %85, i8* %86, i32 %87)
store double %88, double* %4
br label %89
89: ; preds = %84, %80, %48, %16
%90 = load double, double* %4
ret double %90
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"invalid bitcount %s\0A\00"
@.str.1 = [23 x i8] c"invalid hex string %s\0A\00"
define double @handleInput(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @atoi(i8* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %43
9: ; preds = %3
%10 = tail call i32 @strlen(i8* %0)
%11 = sdiv i32 %10, 2
%12 = tail call i32 @strlen(i8* %0)
%13 = srem i32 %12, 2
%14 = add nsw i32 %13, %11
%15 = shl nsw i32 %14, 3
%16 = icmp slt i32 %4, %15
%17 = select i1 %16, i32 %4, i32 %15
%18 = tail call i8* @alloca(i32 %14)
%19 = tail call i32 @memset(i8* %18, i32 0, i32 %14)
%20 = tail call i32 @hexStringToBin(i8* %18, i8* %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %9
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %43
25: ; preds = %9
%26 = tail call i32 @strlen(i8* %1)
%27 = sdiv i32 %26, 2
%28 = tail call i32 @strlen(i8* %1)
%29 = srem i32 %28, 2
%30 = add nsw i32 %29, %27
%31 = shl nsw i32 %30, 3
%32 = tail call i8* @alloca(i32 %30)
%33 = tail call i32 @memset(i8* %32, i32 0, i32 %30)
%34 = tail call i32 @hexStringToBin(i8* %32, i8* %1)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %25
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %43
39: ; preds = %25
%40 = icmp slt i32 %17, %31
%41 = select i1 %40, i32 %17, i32 %31
%42 = tail call double @normalizedHammingDistance(i8* %18, i8* %32, i32 %41)
br label %43
43: ; preds = %39, %36, %22, %6
%44 = phi double [ -1.000000e+00, %6 ], [ %42, %39 ], [ -1.000000e+00, %36 ], [ -1.000000e+00, %22 ]
ret double %44
}