#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 */
struct istate_s {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ReportScanHit(int, int, double, int (*)(int, int, double));
int /*<<< orphan*/ allocate_mx(struct istate_s *, int, int, int ****, int ****);
int /*<<< orphan*/ free_mx(int ***, int ***, int, int);
int /*<<< orphan*/ init_mx(struct istate_s *, int, int, int ***, int ***);
int /*<<< orphan*/ recurse_mx(struct istate_s *, int, int *, int *, char *, int,
                              int, int ***, int ***, int,
                              int (*)(int, int, double));
int strlen(char *);
int FastViterbiScan(struct istate_s *icm, int statenum, int *minb, int *maxb,
                    char *seq, int window, double thresh,
                    int (*gotone_f)(int, int, double)) {
  int ***amx;
  int ***bmx;
  int N;
  int ithresh;
  N = strlen(seq);
  seq--;
  ithresh = (int)(thresh * 1000.0);
  if (!allocate_mx(icm, statenum, window, &amx, &bmx))
    return 0;
  if (!init_mx(icm, statenum, window, amx, bmx))
    return 0;
  if (!recurse_mx(icm, statenum, minb, maxb, seq, N, window, amx, bmx, ithresh,
                  gotone_f))
    return 0;
  ReportScanHit(-1, -1, 0.0, gotone_f);
  free_mx(amx, bmx, statenum, window);
  return 1;
}


x86 assembly (clang, -O0):
<FastViterbiScan>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
mov    %rdx,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
mov    %r9d,-0x44(%rbp)
movsd  %xmm0,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x40(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
movsd  0xe52(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    -0x58(%rbp),%rcx
lea    -0x60(%rbp),%r8
call   1080 <allocate_mx@plt>
cmp    $0x0,%eax
jne    11e6 <FastViterbiScan+0x86>
movl   $0x0,-0x14(%rbp)
jmp    129c <FastViterbiScan+0x13c>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x58(%rbp),%rcx
mov    -0x60(%rbp),%r8
call   1070 <init_mx@plt>
cmp    $0x0,%eax
jne    1212 <FastViterbiScan+0xb2>
movl   $0x0,-0x14(%rbp)
jmp    129c <FastViterbiScan+0x13c>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x64(%rbp),%r9d
mov    -0x44(%rbp),%r14d
mov    -0x58(%rbp),%rbx
mov    -0x60(%rbp),%r11
mov    -0x68(%rbp),%r10d
mov    0x10(%rbp),%rax
mov    %r14d,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1060 <recurse_mx@plt>
cmp    $0x0,%eax
jne    126f <FastViterbiScan+0x10f>
movl   $0x0,-0x14(%rbp)
jmp    129c <FastViterbiScan+0x13c>
mov    0x10(%rbp),%rdx
mov    $0xffffffff,%esi
xorps  %xmm0,%xmm0
mov    %esi,%edi
call   1050 <ReportScanHit@plt>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x44(%rbp),%ecx
call   1040 <free_mx@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<FastViterbiScan>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm0,0x10(%rsp)
mov    %r9d,%r15d
mov    %r8,%rbx
mov    %rcx,0x20(%rsp)
mov    %rdx,0x18(%rsp)
mov    %esi,%ebp
mov    %rdi,%r12
mov    %r8,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
lea    0x8(%rsp),%rcx
mov    %rsp,%r8
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1080 <allocate_mx@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     124d <FastViterbiScan+0xed>
mov    0x8(%rsp),%rcx
mov    (%rsp),%r8
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1070 <init_mx@plt>
test   %eax,%eax
je     124d <FastViterbiScan+0xed>
mov    0x60(%rsp),%r9
add    $0xffffffffffffffff,%rbx
movsd  0x10(%rsp),%xmm0
mulsd  0xe1b(%rip),%xmm0
cvttsd2si %xmm0,%eax
sub    $0x8,%rsp
mov    %r12,%rdi
mov    %ebp,%esi
mov    0x20(%rsp),%rdx
mov    0x28(%rsp),%rcx
mov    %rbx,%r8
mov    %r9,%rbx
mov    %r13d,%r9d
push   %rbx
push   %rax
push   0x18(%rsp)
push   0x28(%rsp)
push   %r15
call   1060 <recurse_mx@plt>
add    $0x30,%rsp
test   %eax,%eax
je     124d <FastViterbiScan+0xed>
xorpd  %xmm0,%xmm0
mov    $0xffffffff,%edi
mov    $0xffffffff,%esi
mov    %rbx,%rdx
call   1050 <ReportScanHit@plt>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
call   1040 <free_mx@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.istate_s = type { i32 }
define i32 @FastViterbiScan(%struct.istate_s* %0, i32 %1, i32* %2, i32* %3, i8* %4, i32 %5, double %6, i32 (i32, i32, double)* %7) {
%9 = alloca i32
%10 = alloca %struct.istate_s*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca double
%17 = alloca i32 (i32, i32, double)*
%18 = alloca i32***
%19 = alloca i32***
%20 = alloca i32
%21 = alloca i32
store %struct.istate_s* %0, %struct.istate_s** %10
store i32 %1, i32* %11
store i32* %2, i32** %12
store i32* %3, i32** %13
store i8* %4, i8** %14
store i32 %5, i32* %15
store double %6, double* %16
store i32 (i32, i32, double)* %7, i32 (i32, i32, double)** %17
%22 = load i8*, i8** %14
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %20
%24 = load i8*, i8** %14
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %14
%26 = load double, double* %16
%27 = fmul double %26, 1.000000e+03
%28 = fptosi double %27 to i32
store i32 %28, i32* %21
%29 = load %struct.istate_s*, %struct.istate_s** %10
%30 = load i32, i32* %11
%31 = load i32, i32* %15
%32 = call i32 @allocate_mx(%struct.istate_s* %29, i32 %30, i32 %31, i32**** %18, i32**** %19)
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %8
store i32 0, i32* %9
br label %67
35: ; preds = %8
%36 = load %struct.istate_s*, %struct.istate_s** %10
%37 = load i32, i32* %11
%38 = load i32, i32* %15
%39 = load i32***, i32**** %18
%40 = load i32***, i32**** %19
%41 = call i32 @init_mx(%struct.istate_s* %36, i32 %37, i32 %38, i32*** %39, i32*** %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %35
store i32 0, i32* %9
br label %67
44: ; preds = %35
%45 = load %struct.istate_s*, %struct.istate_s** %10
%46 = load i32, i32* %11
%47 = load i32*, i32** %12
%48 = load i32*, i32** %13
%49 = load i8*, i8** %14
%50 = load i32, i32* %20
%51 = load i32, i32* %15
%52 = load i32***, i32**** %18
%53 = load i32***, i32**** %19
%54 = load i32, i32* %21
%55 = load i32 (i32, i32, double)*, i32 (i32, i32, double)** %17
%56 = call i32 @recurse_mx(%struct.istate_s* %45, i32 %46, i32* %47, i32* %48, i8* %49, i32 %50, i32 %51, i32*** %52, i32*** %53, i32 %54, i32 (i32, i32, double)* %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %59, label %58
58: ; preds = %44
store i32 0, i32* %9
br label %67
59: ; preds = %44
%60 = load i32 (i32, i32, double)*, i32 (i32, i32, double)** %17
%61 = call i32 @ReportScanHit(i32 -1, i32 -1, double 0.000000e+00, i32 (i32, i32, double)* %60)
%62 = load i32***, i32**** %18
%63 = load i32***, i32**** %19
%64 = load i32, i32* %11
%65 = load i32, i32* %15
%66 = call i32 @free_mx(i32*** %62, i32*** %63, i32 %64, i32 %65)
store i32 1, i32* %9
br label %67
67: ; preds = %59, %58, %43, %34
%68 = load i32, i32* %9
ret i32 %68
}

LLVM IR (-O2):
%struct.istate_s = type { i32 }
define i32 @FastViterbiScan(%struct.istate_s* %0, i32 %1, i32* %2, i32* %3, i8* %4, i32 %5, double %6, i32 (i32, i32, double)* %7) {
%9 = alloca i32***
%10 = alloca i32***
%11 = bitcast i32**** %9 to i8*
%12 = bitcast i32**** %10 to i8*
%13 = tail call i32 @strlen(i8* %4)
%14 = getelementptr inbounds i8, i8* %4, i64 -1
%15 = fmul double %6, 1.000000e+03
%16 = fptosi double %15 to i32
%17 = call i32 @allocate_mx(%struct.istate_s* %0, i32 %1, i32 %5, i32**** %9, i32**** %10)
%18 = icmp eq i32 %17, 0
br i1 %18, label %34, label %19
19: ; preds = %8
%20 = load i32***, i32**** %9
%21 = load i32***, i32**** %10
%22 = call i32 @init_mx(%struct.istate_s* %0, i32 %1, i32 %5, i32*** %20, i32*** %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %19
%25 = load i32***, i32**** %9
%26 = load i32***, i32**** %10
%27 = call i32 @recurse_mx(%struct.istate_s* %0, i32 %1, i32* %2, i32* %3, i8* %14, i32 %13, i32 %5, i32*** %25, i32*** %26, i32 %16, i32 (i32, i32, double)* %7)
%28 = icmp eq i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = call i32 @ReportScanHit(i32 -1, i32 -1, double 0.000000e+00, i32 (i32, i32, double)* %7)
%31 = load i32***, i32**** %9
%32 = load i32***, i32**** %10
%33 = call i32 @free_mx(i32*** %31, i32*** %32, i32 %1, i32 %5)
br label %34
34: ; preds = %24, %19, %8, %29
%35 = phi i32 [ 1, %29 ], [ 0, %8 ], [ 0, %19 ], [ 0, %24 ]
ret i32 %35
}