#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 */
scalar_t__ countStateChanges(char *, char *, int, char const, char const,
                             int *);
void calcTransitionProbs(double **P, char *s1, char *s2, int length,
                         int *filter, int numSelected, int alphabetSize,
                         const char *alphabet) {
  int i, j;
  for (i = 0; i < alphabetSize; i++)
    for (j = 0; j < alphabetSize; j++)
      P[i][j] = (double)(countStateChanges(s1, s2, length, alphabet[i],
                                           alphabet[j], filter)) /
                (double)numSelected;
  return;
}


x86 assembly (clang, -O0):
<calcTransitionProbs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    11d2 <calcTransitionProbs+0xc2>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    11bf <calcTransitionProbs+0xaf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    0x18(%rbp),%rax
movslq -0x34(%rbp),%r8
mov    (%rax,%r8,1),%al
mov    -0x28(%rbp),%r9
movsbl %cl,%ecx
movsbl %al,%r8d
call   1030 <countStateChanges@plt>
cvtsi2sd %rax,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1150 <calcTransitionProbs+0x40>
jmp    11c4 <calcTransitionProbs+0xb4>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    113d <calcTransitionProbs+0x2d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcTransitionProbs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x60(%rsp),%eax
test   %eax,%eax
jle    11c7 <calcTransitionProbs+0xb7>
mov    %r8,%rbx
mov    %ecx,%ebp
mov    %rdx,%r13
mov    0x68(%rsp),%r15
cvtsi2sd %r9d,%xmm1
mov    %eax,%eax
xor    %r14d,%r14d
mov    %rdi,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
mov    %rax,0x10(%rsp)
mov    %rsi,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r15,%r14,1),%ecx
movsbl (%r15,%r12,1),%r8d
mov    %rsi,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
mov    %rbx,%r9
call   1030 <countStateChanges@plt>
movsd  0x18(%rsp),%xmm1
mov    0x20(%rsp),%rdi
mov    0x8(%rsp),%rsi
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  %xmm1,%xmm0
mov    (%rdi,%r14,8),%rax
movsd  %xmm0,(%rax,%r12,8)
mov    0x10(%rsp),%rax
add    $0x1,%r12
cmp    %r12,%rax
jne    1170 <calcTransitionProbs+0x60>
add    $0x1,%r14
cmp    %rax,%r14
jne    1160 <calcTransitionProbs+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @calcTransitionProbs(double** nocapture %0, i8* %1, i8* %2, i32 %3, i32* %4, i32 %5, i32 %6, i8* nocapture %7) {
%9 = icmp sgt i32 %6, 0
br i1 %9, label %10, label %32
10: ; preds = %8
%11 = sitofp i32 %5 to double
%12 = zext i32 %6 to i64
br label %13
13: ; preds = %29, %10
%14 = phi i64 [ 0, %10 ], [ %30, %29 ]
%15 = getelementptr inbounds i8, i8* %7, i64 %14
%16 = getelementptr inbounds double*, double** %0, i64 %14
br label %17
17: ; preds = %13, %17
%18 = phi i64 [ 0, %13 ], [ %27, %17 ]
%19 = load i8, i8* %15
%20 = getelementptr inbounds i8, i8* %7, i64 %18
%21 = load i8, i8* %20
%22 = tail call i64 @countStateChanges(i8* %1, i8* %2, i32 %3, i8 signext %19, i8 signext %21, i32* %4)
%23 = sitofp i64 %22 to double
%24 = fdiv double %23, %11
%25 = load double*, double** %16
%26 = getelementptr inbounds double, double* %25, i64 %18
store double %24, double* %26
%27 = add nuw nsw i64 %18, 1
%28 = icmp eq i64 %27, %12
br i1 %28, label %29, label %17
29: ; preds = %17
%30 = add nuw nsw i64 %14, 1
%31 = icmp eq i64 %30, %12
br i1 %31, label %32, label %13
32: ; preds = %29, %8
ret void
}