#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 log(double);
int s2i(char *);
int strlen(char *);
double log_cum_back(char *seq, double *a_cp, int order, double *logcumback) {
  int i;
  int len = strlen(seq);
  int ipos;
  for (i = ipos = 0, logcumback[0] = 0; i < len; i++) {
    int lp = ((ipos + 1) < (order + 1) ? (ipos + 1) : (order + 1));
    char *wa = &seq[i - lp + 1];
    char *wa_end = &seq[i + 1];
    char save = *wa_end;
    *wa_end = '\0';
    int index = s2i(wa);
    double log_pwa;
    if (index < 0) {
      log_pwa = 0;
      ipos = 0;
    } else {
      log_pwa = log(a_cp[index]);
      ipos++;
    }
    logcumback[i + 1] = logcumback[i] + log_pwa;
    *wa_end = save;
  }
  return (logcumback[i]);
}


x86 assembly (clang, -O0):
<log_cum_back>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1269 <log_cum_back+0x139>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    119a <log_cum_back+0x6a>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11a3 <log_cum_back+0x73>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    -0x30(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x41(%rbp)
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   1030 <s2i@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    120e <log_cum_back+0xde>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x2c(%rbp)
jmp    122e <log_cum_back+0xfe>
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x50(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x41(%rbp),%cl
mov    -0x40(%rbp),%rax
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116c <log_cum_back+0x3c>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_cum_back>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r13
mov    %edx,0x4(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbp
call   1040 <strlen@plt>
movq   $0x0,0x0(%r13)
test   %eax,%eax
jle    11e6 <log_cum_back+0xb6>
mov    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    11a2 <log_cum_back+0x72>
add    $0x1,%r14d
mov    %eax,%eax
mov    0x10(%rsp),%rcx
movsd  (%rcx,%rax,8),%xmm0
call   1050 <log@plt>
addsd  0x0(%r13,%rbx,8),%xmm0
movsd  %xmm0,0x8(%r13,%rbx,8)
mov    %r15b,0x1(%rbp,%rbx,1)
mov    %r12,%rbx
cmp    %r12,0x8(%rsp)
je     11d8 <log_cum_back+0xa8>
mov    0x4(%rsp),%eax
cmp    %eax,%r14d
cmovl  %r14d,%eax
mov    %ebx,%ecx
sub    %eax,%ecx
movslq %ecx,%rdi
add    %rbp,%rdi
lea    0x1(%rbx),%r12
movzbl 0x1(%rbp,%rbx,1),%r15d
movb   $0x0,0x1(%rbp,%rbx,1)
call   1030 <s2i@plt>
test   %eax,%eax
jns    1170 <log_cum_back+0x40>
xorpd  %xmm0,%xmm0
xor    %r14d,%r14d
jmp    1185 <log_cum_back+0x55>
mov    0x8(%rsp),%rax
movsd  0x0(%r13,%rax,8),%xmm0
jmp    11e9 <log_cum_back+0xb9>
xorps  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @log_cum_back(i8* %0, double* %1, i32 %2, double* %3) {
%5 = alloca i8*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8
%16 = alloca i32
%17 = alloca double
store i8* %0, i8** %5
store double* %1, double** %6
store i32 %2, i32* %7
store double* %3, double** %8
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %10
store i32 0, i32* %11
store i32 0, i32* %9
%20 = load double*, double** %8
%21 = getelementptr inbounds double, double* %20, i64 0
store double 0.000000e+00, double* %21
br label %22
22: ; preds = %84, %4
%23 = load i32, i32* %9
%24 = load i32, i32* %10
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %87
26: ; preds = %22
%27 = load i32, i32* %11
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 1
br label %38
35: ; preds = %26
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
br label %38
38: ; preds = %35, %32
%39 = phi i32 [ %34, %32 ], [ %37, %35 ]
store i32 %39, i32* %12
%40 = load i8*, i8** %5
%41 = load i32, i32* %9
%42 = load i32, i32* %12
%43 = sub nsw i32 %41, %42
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %40, i64 %45
store i8* %46, i8** %13
%47 = load i8*, i8** %5
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
store i8* %51, i8** %14
%52 = load i8*, i8** %14
%53 = load i8, i8* %52
store i8 %53, i8* %15
%54 = load i8*, i8** %14
store i8 0, i8* %54
%55 = load i8*, i8** %13
%56 = call i32 @s2i(i8* %55)
store i32 %56, i32* %16
%57 = load i32, i32* %16
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %38
store double 0.000000e+00, double* %17
store i32 0, i32* %11
br label %69
60: ; preds = %38
%61 = load double*, double** %6
%62 = load i32, i32* %16
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = call double @log(double %65)
store double %66, double* %17
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %69
69: ; preds = %60, %59
%70 = load double*, double** %8
%71 = load i32, i32* %9
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
%75 = load double, double* %17
%76 = fadd double %74, %75
%77 = load double*, double** %8
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double, double* %77, i64 %80
store double %76, double* %81
%82 = load i8, i8* %15
%83 = load i8*, i8** %14
store i8 %82, i8* %83
br label %84
84: ; preds = %69
%85 = load i32, i32* %9
%86 = add nsw i32 %85, 1
store i32 %86, i32* %9
br label %22
87: ; preds = %22
%88 = load double*, double** %8
%89 = load i32, i32* %9
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds double, double* %88, i64 %90
%92 = load double, double* %91
ret double %92
}

LLVM IR (-O2):
define double @log_cum_back(i8* %0, double* nocapture %1, i32 %2, double* nocapture %3) {
%5 = tail call i32 @strlen(i8* %0)
store double 0.000000e+00, double* %3
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %40
7: ; preds = %4
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %29
%10 = phi i64 [ 0, %7 ], [ %18, %29 ]
%11 = phi i32 [ 0, %7 ], [ %30, %29 ]
%12 = icmp slt i32 %11, %2
%13 = select i1 %12, i32 %11, i32 %2
%14 = trunc i64 %10 to i32
%15 = sub i32 %14, %13
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = add nuw nsw i64 %10, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
store i8 0, i8* %19
%21 = tail call i32 @s2i(i8* %17)
%22 = icmp slt i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %9
%24 = add nsw i32 %11, 1
%25 = zext i32 %21 to i64
%26 = getelementptr inbounds double, double* %1, i64 %25
%27 = load double, double* %26
%28 = tail call double @log(double %27)
br label %29
29: ; preds = %9, %23
%30 = phi i32 [ %24, %23 ], [ 0, %9 ]
%31 = phi double [ %28, %23 ], [ 0.000000e+00, %9 ]
%32 = getelementptr inbounds double, double* %3, i64 %10
%33 = load double, double* %32
%34 = fadd double %31, %33
%35 = getelementptr inbounds double, double* %3, i64 %18
store double %34, double* %35
store i8 %20, i8* %19
%36 = icmp eq i64 %18, %8
br i1 %36, label %37, label %9
37: ; preds = %29
%38 = getelementptr inbounds double, double* %3, i64 %8
%39 = load double, double* %38
br label %40
40: ; preds = %4, %37
%41 = phi double [ %39, %37 ], [ 0.000000e+00, %4 ]
ret double %41
}