#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 int levenshtein(char const *, char const *);
scalar_t__ strlen(char const *);
float levenshtein_similarity(const char *str1, const char *str2) {
  unsigned int lev_dist = levenshtein(str1, str2);
  float max_len = (float)strlen(str1);
  float str2_len = (float)strlen(str2);
  if (max_len < str2_len)
    max_len = str2_len;
  if (max_len == 0)
    return ((float)1.0);
  else
    return ((float)1.0 - ((float)lev_dist / max_len));
}


x86 assembly (clang, -O0):
<levenshtein_similarity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <levenshtein@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm1
movss  -0x24(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1183 <levenshtein_similarity+0x63>
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11ac <levenshtein_similarity+0x8c>
jp     11ac <levenshtein_similarity+0x8c>
movss  0xe5e(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ca <levenshtein_similarity+0xaa>
mov    -0x1c(%rbp),%eax
cvtsi2ss %rax,%xmm1
divss  -0x20(%rbp),%xmm1
movss  0xe3f(%rip),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<levenshtein_similarity>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <levenshtein@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <strlen@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
maxss  0xc(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1173 <levenshtein_similarity+0x53>
jp     1173 <levenshtein_similarity+0x53>
movss  0xe8f(%rip),%xmm0
jmp    118e <levenshtein_similarity+0x6e>
mov    %r14d,%eax
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
divss  %xmm0,%xmm1
movss  0xe76(%rip),%xmm0
subss  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define float @levenshtein_similarity(i8* %0, i8* %1) {
%3 = alloca float
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca float
%8 = alloca float
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 @levenshtein(i8* %9, i8* %10)
store i32 %11, i32* %6
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = sitofp i64 %13 to float
store float %14, float* %7
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
%17 = sitofp i64 %16 to float
store float %17, float* %8
%18 = load float, float* %7
%19 = load float, float* %8
%20 = fcmp olt float %18, %19
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = load float, float* %8
store float %22, float* %7
br label %23
23: ; preds = %21, %2
%24 = load float, float* %7
%25 = fcmp oeq float %24, 0.000000e+00
br i1 %25, label %26, label %27
26: ; preds = %23
store float 1.000000e+00, float* %3
br label %33
27: ; preds = %23
%28 = load i32, i32* %6
%29 = uitofp i32 %28 to float
%30 = load float, float* %7
%31 = fdiv float %29, %30
%32 = fsub float 1.000000e+00, %31
store float %32, float* %3
br label %33
33: ; preds = %27, %26
%34 = load float, float* %3
ret float %34
}

LLVM IR (-O2):
define float @levenshtein_similarity(i8* %0, i8* %1) {
%3 = tail call i32 @levenshtein(i8* %0, i8* %1)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = sitofp i64 %4 to float
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = sitofp i64 %6 to float
%8 = fcmp olt float %5, %7
%9 = select i1 %8, float %7, float %5
%10 = fcmp oeq float %9, 0.000000e+00
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = uitofp i32 %3 to float
%13 = fdiv float %12, %9
%14 = fsub float 1.000000e+00, %13
br label %15
15: ; preds = %2, %11
%16 = phi float [ %14, %11 ], [ 1.000000e+00, %2 ]
ret float %16
}