#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, char *, int, int, int ***,
                              int ***, int, int (*)(int, int, double));
int strlen(char *);
int ViterbiScan(struct istate_s *icm, int statenum, 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, 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):
<ViterbiScan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movsd  %xmm0,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
movsd  0xe61(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    -0x40(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   1080 <allocate_mx@plt>
cmp    $0x0,%eax
jne    11d7 <ViterbiScan+0x77>
movl   $0x0,-0x4(%rbp)
jmp    127a <ViterbiScan+0x11a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
call   1070 <init_mx@plt>
cmp    $0x0,%eax
jne    1203 <ViterbiScan+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    127a <ViterbiScan+0x11a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x4c(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x40(%rbp),%r9
mov    -0x48(%rbp),%r11
mov    -0x50(%rbp),%r10d
mov    -0x38(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <recurse_mx@plt>
cmp    $0x0,%eax
jne    124d <ViterbiScan+0xed>
movl   $0x0,-0x4(%rbp)
jmp    127a <ViterbiScan+0x11a>
mov    -0x38(%rbp),%rdx
mov    $0xffffffff,%esi
xorps  %xmm0,%xmm0
mov    %esi,%edi
call   1050 <ReportScanHit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1040 <free_mx@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ViterbiScan>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x20(%rsp)
movsd  %xmm0,0x18(%rsp)
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %esi,%r13d
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
call   1080 <allocate_mx@plt>
xor    %r15d,%r15d
test   %eax,%eax
je     1246 <ViterbiScan+0xe6>
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%r8
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
call   1070 <init_mx@plt>
test   %eax,%eax
je     1246 <ViterbiScan+0xe6>
movsd  0x18(%rsp),%xmm0
mulsd  0xe23(%rip),%xmm0
add    $0xffffffffffffffff,%rbx
cvttsd2si %xmm0,%eax
mov    0x10(%rsp),%r9
sub    $0x8,%rsp
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    %r12d,%r8d
mov    0x28(%rsp),%rbx
push   %rbx
push   %rax
push   0x20(%rsp)
call   1060 <recurse_mx@plt>
add    $0x20,%rsp
test   %eax,%eax
je     1246 <ViterbiScan+0xe6>
xorpd  %xmm0,%xmm0
mov    $0xffffffff,%edi
mov    $0xffffffff,%esi
mov    %rbx,%rdx
call   1050 <ReportScanHit@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
call   1040 <free_mx@plt>
mov    $0x1,%r15d
mov    %r15d,%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 @ViterbiScan(%struct.istate_s* %0, i32 %1, i8* %2, i32 %3, double %4, i32 (i32, i32, double)* %5) {
%7 = alloca i32
%8 = alloca %struct.istate_s*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca double
%13 = alloca i32 (i32, i32, double)*
%14 = alloca i32***
%15 = alloca i32***
%16 = alloca i32
%17 = alloca i32
store %struct.istate_s* %0, %struct.istate_s** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store double %4, double* %12
store i32 (i32, i32, double)* %5, i32 (i32, i32, double)** %13
%18 = load i8*, i8** %10
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %16
%20 = load i8*, i8** %10
%21 = getelementptr inbounds i8, i8* %20, i32 -1
store i8* %21, i8** %10
%22 = load double, double* %12
%23 = fmul double %22, 1.000000e+03
%24 = fptosi double %23 to i32
store i32 %24, i32* %17
%25 = load %struct.istate_s*, %struct.istate_s** %8
%26 = load i32, i32* %9
%27 = load i32, i32* %11
%28 = call i32 @allocate_mx(%struct.istate_s* %25, i32 %26, i32 %27, i32**** %14, i32**** %15)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %6
store i32 0, i32* %7
br label %61
31: ; preds = %6
%32 = load %struct.istate_s*, %struct.istate_s** %8
%33 = load i32, i32* %9
%34 = load i32, i32* %11
%35 = load i32***, i32**** %14
%36 = load i32***, i32**** %15
%37 = call i32 @init_mx(%struct.istate_s* %32, i32 %33, i32 %34, i32*** %35, i32*** %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %31
store i32 0, i32* %7
br label %61
40: ; preds = %31
%41 = load %struct.istate_s*, %struct.istate_s** %8
%42 = load i32, i32* %9
%43 = load i8*, i8** %10
%44 = load i32, i32* %16
%45 = load i32, i32* %11
%46 = load i32***, i32**** %14
%47 = load i32***, i32**** %15
%48 = load i32, i32* %17
%49 = load i32 (i32, i32, double)*, i32 (i32, i32, double)** %13
%50 = call i32 @recurse_mx(%struct.istate_s* %41, i32 %42, i8* %43, i32 %44, i32 %45, i32*** %46, i32*** %47, i32 %48, i32 (i32, i32, double)* %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %40
store i32 0, i32* %7
br label %61
53: ; preds = %40
%54 = load i32 (i32, i32, double)*, i32 (i32, i32, double)** %13
%55 = call i32 @ReportScanHit(i32 -1, i32 -1, double 0.000000e+00, i32 (i32, i32, double)* %54)
%56 = load i32***, i32**** %14
%57 = load i32***, i32**** %15
%58 = load i32, i32* %9
%59 = load i32, i32* %11
%60 = call i32 @free_mx(i32*** %56, i32*** %57, i32 %58, i32 %59)
store i32 1, i32* %7
br label %61
61: ; preds = %53, %52, %39, %30
%62 = load i32, i32* %7
ret i32 %62
}

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