#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 */
double calc_read_prob(double const *, int, char const *, int, int, int *);
double log_sum_exp(double *, int);
double calc_prob_region(const double *matrix, int read_length, const char *seq,
                        int seq_length, int pos, int start, int end,
                        int *seqnt_map) {
  if (start < 0)
    start = 0;
  else if (start >= seq_length)
    start = seq_length - 1;
  if (end < 0)
    end = 0;
  else if (end >= seq_length)
    end = seq_length - 1;
  int i;
  double p[end - start];
  for (i = start; i < end; i++) {
    p[i - start] =
        calc_read_prob(matrix, read_length, seq, seq_length, i, seqnt_map);
  }
  return log_sum_exp(p, end - start);
}


x86 assembly (clang, -O0):
<calc_prob_region>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    115b <calc_prob_region+0x3b>
movl   $0x0,-0x24(%rbp)
jmp    1175 <calc_prob_region+0x55>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1170 <calc_prob_region+0x50>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1175 <calc_prob_region+0x55>
cmpl   $0x0,0x10(%rbp)
jge    118b <calc_prob_region+0x6b>
movl   $0x0,0x10(%rbp)
jmp    11a5 <calc_prob_region+0x85>
mov    0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11a0 <calc_prob_region+0x80>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,0x10(%rbp)
jmp    11a5 <calc_prob_region+0x85>
mov    0x10(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    %ecx,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    121e <calc_prob_region+0xfe>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    0x18(%rbp),%r9
call   1030 <calc_read_prob@plt>
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    -0x24(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d7 <calc_prob_region+0xb7>
mov    -0x40(%rbp),%rdi
mov    0x10(%rbp),%esi
sub    -0x24(%rbp),%esi
call   1040 <log_sum_exp@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_prob_region>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    -0x1(%rcx),%r10d
cmp    %ecx,%r9d
mov    %r10d,%ebx
cmovl  %r9d,%ebx
xor    %r8d,%r8d
test   %r9d,%r9d
cmovs  %r8d,%ebx
mov    0x10(%rbp),%eax
cmp    %ecx,%eax
cmovl  %eax,%r10d
test   %eax,%eax
cmovs  %r8d,%r10d
mov    %r10d,%eax
sub    %ebx,%eax
lea    0xf(,%rax,8),%r8
and    $0xfffffffffffffff0,%r8
mov    %rsp,%rax
sub    %r8,%rax
mov    %rax,-0x38(%rbp)
mov    %rax,%rsp
mov    %r10d,%eax
sub    %ebx,%eax
mov    %eax,-0x2c(%rbp)
jle    11ce <calc_prob_region+0xae>
mov    %rdx,%r13
mov    %esi,%r14d
mov    %rdi,%r12
mov    -0x38(%rbp),%r15
mov    %rcx,-0x40(%rbp)
mov    %r10d,-0x30(%rbp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r13,%rdx
mov    %ebx,%r8d
mov    0x18(%rbp),%r9
call   1030 <calc_read_prob@plt>
mov    -0x30(%rbp),%r10d
mov    -0x40(%rbp),%rcx
movsd  %xmm0,(%r15)
add    $0x8,%r15
add    $0x1,%ebx
cmp    %ebx,%r10d
jne    11a0 <calc_prob_region+0x80>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <log_sum_exp@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @calc_prob_region(double* %0, i32 %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i32* %7) {
%9 = alloca double*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i64
store double* %0, double** %9
store i32 %1, i32* %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 i32* %7, i32** %16
%20 = load i32, i32* %14
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %8
store i32 0, i32* %14
br label %31
23: ; preds = %8
%24 = load i32, i32* %14
%25 = load i32, i32* %12
%26 = icmp sge i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %12
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %14
br label %30
30: ; preds = %27, %23
br label %31
31: ; preds = %30, %22
%32 = load i32, i32* %15
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 0, i32* %15
br label %43
35: ; preds = %31
%36 = load i32, i32* %15
%37 = load i32, i32* %12
%38 = icmp sge i32 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* %12
%41 = sub nsw i32 %40, 1
store i32 %41, i32* %15
br label %42
42: ; preds = %39, %35
br label %43
43: ; preds = %42, %34
%44 = load i32, i32* %15
%45 = load i32, i32* %14
%46 = sub nsw i32 %44, %45
%47 = zext i32 %46 to i64
%48 = call i8* @llvm.stacksave()
store i8* %48, i8** %18
%49 = alloca double, i64 %47
store i64 %47, i64* %19
%50 = load i32, i32* %14
store i32 %50, i32* %17
br label %51
51: ; preds = %68, %43
%52 = load i32, i32* %17
%53 = load i32, i32* %15
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %71
55: ; preds = %51
%56 = load double*, double** %9
%57 = load i32, i32* %10
%58 = load i8*, i8** %11
%59 = load i32, i32* %12
%60 = load i32, i32* %17
%61 = load i32*, i32** %16
%62 = call double @calc_read_prob(double* %56, i32 %57, i8* %58, i32 %59, i32 %60, i32* %61)
%63 = load i32, i32* %17
%64 = load i32, i32* %14
%65 = sub nsw i32 %63, %64
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %49, i64 %66
store double %62, double* %67
br label %68
68: ; preds = %55
%69 = load i32, i32* %17
%70 = add nsw i32 %69, 1
store i32 %70, i32* %17
br label %51
71: ; preds = %51
%72 = load i32, i32* %15
%73 = load i32, i32* %14
%74 = sub nsw i32 %72, %73
%75 = call double @log_sum_exp(double* %49, i32 %74)
%76 = load i8*, i8** %18
ret double %75
}

LLVM IR (-O2):
define double @calc_prob_region(double* %0, i32 %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i32* %7) {
%9 = icmp slt i32 %5, 0
%10 = icmp slt i32 %5, %3
%11 = add nsw i32 %3, -1
%12 = select i1 %10, i32 %5, i32 %11
%13 = select i1 %9, i32 0, i32 %12
%14 = icmp slt i32 %6, 0
%15 = icmp slt i32 %6, %3
%16 = select i1 %15, i32 %6, i32 %11
%17 = select i1 %14, i32 0, i32 %16
%18 = sub nsw i32 %17, %13
%19 = zext i32 %18 to i64
%20 = alloca double, i64 %19
%21 = icmp sgt i32 %17, %13
br i1 %21, label %22, label %33
22: ; preds = %8
%23 = sext i32 %13 to i64
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ %23, %22 ], [ %30, %24 ]
%26 = trunc i64 %25 to i32
%27 = tail call double @calc_read_prob(double* %0, i32 %1, i8* %2, i32 %3, i32 %26, i32* %7)
%28 = sub nsw i64 %25, %23
%29 = getelementptr inbounds double, double* %20, i64 %28
store double %27, double* %29
%30 = add nsw i64 %25, 1
%31 = trunc i64 %30 to i32
%32 = icmp eq i32 %17, %31
br i1 %32, label %33, label %24
33: ; preds = %24, %8
%34 = call double @log_sum_exp(double* %20, i32 %18)
ret double %34
}