#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 NGramMatch(char *, char *, int, int, int *);
int /*<<< orphan*/ lprintf(int, char *, char *);
int /*<<< orphan*/ make_search_string(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int FuzzyMatching(char *RefStr, char *MatchStr) {
  char TextPara[1000];
  int TextLen, SearchStrLen;
  int NGram1Len, NGram2Len;
  int MatchCount1, MatchCount2;
  int MaxMatch1, MaxMatch2;
  double Similarity;
  TextPara[0] = ' ';
  SearchStrLen = strlen(RefStr);
  NGram1Len = 3;
  NGram2Len = (SearchStrLen < 7) ? 2 : 5;
  TextLen = strlen(MatchStr);
  if (TextLen < 1000 - 2) {
    strcpy(&TextPara[1], MatchStr);
    make_search_string(TextPara);
    MatchCount1 =
        NGramMatch(TextPara, RefStr, SearchStrLen, NGram1Len, &MaxMatch1);
    MatchCount2 =
        NGramMatch(TextPara, RefStr, SearchStrLen, NGram2Len, &MaxMatch2);
    Similarity = 100.0 * (double)(MatchCount1 + MatchCount2) /
                 (double)(MaxMatch1 + MaxMatch2);
    return (int)Similarity;
  } else {
    lprintf(2, "Comment too long: %s\n", MatchStr);
    return 0;
  }
}


x86 assembly (clang, -O0):
<FuzzyMatching>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x20,-0x400(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x408(%rbp)
movl   $0x3,-0x40c(%rbp)
mov    -0x408(%rbp),%edx
mov    $0x5,%eax
mov    $0x2,%ecx
cmp    $0x7,%edx
cmovl  %ecx,%eax
mov    %eax,-0x410(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x404(%rbp)
cmpl   $0x3e6,-0x404(%rbp)
jge    1278 <FuzzyMatching+0x128>
lea    -0x400(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x400(%rbp),%rdi
call   1070 <make_search_string@plt>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x408(%rbp),%edx
mov    -0x40c(%rbp),%ecx
lea    -0x41c(%rbp),%r8
call   1040 <NGramMatch@plt>
mov    %eax,-0x414(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x408(%rbp),%edx
mov    -0x410(%rbp),%ecx
lea    -0x420(%rbp),%r8
call   1040 <NGramMatch@plt>
mov    %eax,-0x418(%rbp)
mov    -0x414(%rbp),%eax
add    -0x418(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xdb8(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x41c(%rbp),%eax
add    -0x420(%rbp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x428(%rbp)
ff
cvttsd2si -0x428(%rbp),%eax
ff
mov    %eax,-0x4(%rbp)
jmp    1294 <FuzzyMatching+0x144>
mov    -0x18(%rbp),%rdx
mov    $0x2,%edi
lea    0xd80(%rip),%rsi
call   1060 <lprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FuzzyMatching>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
movb   $0x20,0x10(%rsp)
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmp    $0x3e5,%eax
jg     1200 <FuzzyMatching+0xb0>
xor    %eax,%eax
cmp    $0x7,%r14d
setge  %al
lea    (%rax,%rax,2),%r15d
add    $0x2,%r15d
lea    0x11(%rsp),%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1070 <make_search_string@plt>
lea    0xc(%rsp),%r8
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    $0x3,%ecx
call   1040 <NGramMatch@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%r8
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
call   1040 <NGramMatch@plt>
add    %ebp,%eax
cvtsi2sd %eax,%xmm0
mulsd  0xe16(%rip),%xmm0
mov    0x8(%rsp),%eax
add    0xc(%rsp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
jmp    1216 <FuzzyMatching+0xc6>
lea    0xe01(%rip),%rsi
mov    $0x2,%edi
mov    %rbp,%rdx
call   1060 <lprintf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Comment too long: %s\0A\00"
define i32 @FuzzyMatching(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1000 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
store i8* %0, i8** %4
store i8* %1, i8** %5
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
store i8 32, i8* %16
%17 = load i8*, i8** %4
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %8
store i32 3, i32* %9
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 7
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 2, i32 5
store i32 %22, i32* %10
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 998
br i1 %26, label %27, label %55
27: ; preds = %2
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 1
%29 = load i8*, i8** %5
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%32 = call i32 @make_search_string(i8* %31)
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%34 = load i8*, i8** %4
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%37 = call i32 @NGramMatch(i8* %33, i8* %34, i32 %35, i32 %36, i32* %13)
store i32 %37, i32* %11
%38 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%39 = load i8*, i8** %4
%40 = load i32, i32* %8
%41 = load i32, i32* %10
%42 = call i32 @NGramMatch(i8* %38, i8* %39, i32 %40, i32 %41, i32* %14)
store i32 %42, i32* %12
%43 = load i32, i32* %11
%44 = load i32, i32* %12
%45 = add nsw i32 %43, %44
%46 = sitofp i32 %45 to double
%47 = fmul double 1.000000e+02, %46
%48 = load i32, i32* %13
%49 = load i32, i32* %14
%50 = add nsw i32 %48, %49
%51 = sitofp i32 %50 to double
%52 = fdiv double %47, %51
store double %52, double* %15
%53 = load double, double* %15
%54 = fptosi double %53 to i32
store i32 %54, i32* %3
br label %58
55: ; preds = %2
%56 = load i8*, i8** %5
%57 = call i32 @lprintf(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %56)
store i32 0, i32* %3
br label %58
58: ; preds = %55, %27
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [22 x i8] c"Comment too long: %s\0A\00"
define i32 @FuzzyMatching(i8* %0, i8* %1) {
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i8 32, i8* %6
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 @strlen(i8* %1)
%11 = icmp slt i32 %10, 998
br i1 %11, label %12, label %29
12: ; preds = %2
%13 = icmp slt i32 %9, 7
%14 = select i1 %13, i32 2, i32 5
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 1
%16 = call i32 @strcpy(i8* %15, i8* %1)
%17 = call i32 @make_search_string(i8* %6)
%18 = call i32 @NGramMatch(i8* %6, i8* %0, i32 %9, i32 3, i32* %4)
%19 = call i32 @NGramMatch(i8* %6, i8* %0, i32 %9, i32 %14, i32* %5)
%20 = add nsw i32 %19, %18
%21 = sitofp i32 %20 to double
%22 = fmul double %21, 1.000000e+02
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = add nsw i32 %24, %23
%26 = sitofp i32 %25 to double
%27 = fdiv double %22, %26
%28 = fptosi double %27 to i32
br label %31
29: ; preds = %2
%30 = tail call i32 @lprintf(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %31
31: ; preds = %29, %12
%32 = phi i32 [ %28, %12 ], [ 0, %29 ]
ret i32 %32
}