#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 /*<<< orphan*/ initcharmatrix();
int score(char *, char *);
float scorefactor(char *, char *);
char *bestmatch(char *commandstring, char **possibilities,
                int possibilitycount) {
  initcharmatrix();
  float sfactor = 0;
  float tmpscore = 0;
  float maxscore = 0;
  int maxscoreid = 0;
  int btresults = 0;
  for (int i = 0; i < possibilitycount; ++i) {
    sfactor = scorefactor(commandstring, possibilities[i]);
    if (possibilities[i]) {
      btresults = score(commandstring, possibilities[i]);
      tmpscore = btresults * sfactor;
      if (tmpscore >= maxscore) {
        maxscoreid = i;
        maxscore = tmpscore;
      }
    }
  }
  return possibilities[maxscoreid];
}


x86 assembly (clang, -O0):
<bestmatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1030 <initcharmatrix@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    120e <bestmatch+0xde>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <scorefactor@plt>
movss  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11fb <bestmatch+0xcb>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <score@plt>
mov    %eax,-0x28(%rbp)
cvtsi2ssl -0x28(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
ucomiss -0x20(%rbp),%xmm0
jb     11f6 <bestmatch+0xc6>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    11fb <bestmatch+0xcb>
jmp    1200 <bestmatch+0xd0>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1177 <bestmatch+0x47>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bestmatch>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %r12d,%r12d
xor    %eax,%eax
call   1030 <initcharmatrix@plt>
test   %r15d,%r15d
jle    11cb <bestmatch+0x9b>
mov    %r15d,%r15d
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    1179 <bestmatch+0x49>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     11cb <bestmatch+0x9b>
mov    (%rbx,%rbp,8),%rsi
mov    %r14,%rdi
call   1040 <scorefactor@plt>
mov    (%rbx,%rbp,8),%rsi
test   %rsi,%rsi
je     1170 <bestmatch+0x40>
mov    %r14,%rdi
movss  %xmm0,0x8(%rsp)
call   1050 <score@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x8(%rsp),%xmm0
ucomiss 0xc(%rsp),%xmm0
jb     1170 <bestmatch+0x40>
movss  %xmm0,0xc(%rsp)
mov    %ebp,%r12d
jmp    1170 <bestmatch+0x40>
movslq %r12d,%rax
mov    (%rbx,%rax,8),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @bestmatch(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
%13 = call i32 (...) @initcharmatrix()
store float 0.000000e+00, float* %7
store float 0.000000e+00, float* %8
store float 0.000000e+00, float* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %14
14: ; preds = %52, %3
%15 = load i32, i32* %12
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %55
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i8**, i8*** %5
%21 = load i32, i32* %12
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call float @scorefactor(i8* %19, i8* %24)
store float %25, float* %7
%26 = load i8**, i8*** %5
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %51
32: ; preds = %18
%33 = load i8*, i8** %4
%34 = load i8**, i8*** %5
%35 = load i32, i32* %12
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @score(i8* %33, i8* %38)
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = sitofp i32 %40 to float
%42 = load float, float* %7
%43 = fmul float %41, %42
store float %43, float* %8
%44 = load float, float* %8
%45 = load float, float* %9
%46 = fcmp oge float %44, %45
br i1 %46, label %47, label %50
47: ; preds = %32
%48 = load i32, i32* %12
store i32 %48, i32* %10
%49 = load float, float* %8
store float %49, float* %9
br label %50
50: ; preds = %47, %32
br label %51
51: ; preds = %50, %18
br label %52
52: ; preds = %51
%53 = load i32, i32* %12
%54 = add nsw i32 %53, 1
store i32 %54, i32* %12
br label %14
55: ; preds = %14
%56 = load i8**, i8*** %5
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
ret i8* %60
}

LLVM IR (-O2):
define i8* @bestmatch(i8* %0, i8** nocapture %1, i32 %2) {
%4 = tail call i32 (...) @initcharmatrix()
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = zext i32 %2 to i64
br label %13
8: ; preds = %29, %3
%9 = phi i32 [ 0, %3 ], [ %31, %29 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
ret i8* %12
13: ; preds = %6, %29
%14 = phi i64 [ 0, %6 ], [ %32, %29 ]
%15 = phi i32 [ 0, %6 ], [ %31, %29 ]
%16 = phi float [ 0.000000e+00, %6 ], [ %30, %29 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %14
%18 = load i8*, i8** %17
%19 = tail call float @scorefactor(i8* %0, i8* %18)
%20 = load i8*, i8** %17
%21 = icmp eq i8* %20, null
br i1 %21, label %29, label %22
22: ; preds = %13
%23 = tail call i32 @score(i8* %0, i8* %20)
%24 = sitofp i32 %23 to float
%25 = fmul float %19, %24
%26 = fcmp ult float %25, %16
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = trunc i64 %14 to i32
br label %29
29: ; preds = %13, %27, %22
%30 = phi float [ %25, %27 ], [ %16, %22 ], [ %16, %13 ]
%31 = phi i32 [ %28, %27 ], [ %15, %22 ], [ %15, %13 ]
%32 = add nuw nsw i64 %14, 1
%33 = icmp eq i64 %32, %7
br i1 %33, label %8, label %13
}