#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 */
int /*<<< orphan*/ addStrings(char *, char *);
double atof(char *);
int /*<<< orphan*/ free(char *);
int indexOf(char *, int /*<<< orphan*/, int /*<<< orphan*/, int);
int indexOfChar(char *, char, int, int);
int strlen(char *);
char *substring(char *, int, int);
double getProbability(char *s, char *ngram) {
  int slen = strlen(s);
  int ngIndex = indexOf(s, addStrings(ngram, ":"), 0, slen);
  if (ngIndex < 0)
    return 0.5;
  ngIndex += strlen(ngram) + 1;
  int endingIndex = indexOfChar(s, '\n', ngIndex, slen);
  if (endingIndex == -1)
    endingIndex = strlen(s);
  double p;
  char *sp = substring(s, ngIndex, endingIndex);
  p = atof(sp);
  free(sp);
  return p;
}


x86 assembly (clang, -O0):
<getProbability>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <addStrings@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x1c(%rbp),%ecx
xor    %edx,%edx
call   1070 <indexOf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11d3 <getProbability+0x63>
movsd  0xe37(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1246 <getProbability+0xd6>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    $0xa,%esi
call   1090 <indexOfChar@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1212 <getProbability+0xa2>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1060 <substring@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getProbability>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xe7c(%rip),%rsi
mov    %r15,%rdi
call   1080 <addStrings@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   1070 <indexOf@plt>
test   %eax,%eax
js     1200 <getProbability+0x90>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <strlen@plt>
add    %eax,%ebp
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1090 <indexOfChar@plt>
cmp    $0xffffffff,%eax
jne    11d5 <getProbability+0x65>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1060 <substring@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <atof@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
jmp    1208 <getProbability+0x98>
movsd  0xdf8(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
define double @getProbability(i8* %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %6
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = call i32 @addStrings(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %6
%17 = call i32 @indexOf(i8* %13, i32 %15, i32 0, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %2
store double 5.000000e-01, double* %3
br label %46
21: ; preds = %2
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %7
%26 = add nsw i32 %25, %24
store i32 %26, i32* %7
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = load i32, i32* %6
%30 = call i32 @indexOfChar(i8* %27, i8 signext 10, i32 %28, i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %21
%34 = load i8*, i8** %4
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %8
br label %36
36: ; preds = %33, %21
%37 = load i8*, i8** %4
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = call i8* @substring(i8* %37, i32 %38, i32 %39)
store i8* %40, i8** %10
%41 = load i8*, i8** %10
%42 = call double @atof(i8* %41)
store double %42, double* %9
%43 = load i8*, i8** %10
%44 = call i32 @free(i8* %43)
%45 = load double, double* %9
store double %45, double* %3
br label %46
46: ; preds = %36, %20
%47 = load double, double* %3
ret double %47
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
define double @getProbability(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @addStrings(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @indexOf(i8* %0, i32 %4, i32 0, i32 %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %1)
%9 = add nuw i32 %5, 1
%10 = add i32 %9, %8
%11 = tail call i32 @indexOfChar(i8* %0, i8 signext 10, i32 %10, i32 %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @strlen(i8* %0)
br label %15
15: ; preds = %13, %7
%16 = phi i32 [ %14, %13 ], [ %11, %7 ]
%17 = tail call i8* @substring(i8* %0, i32 %10, i32 %16)
%18 = tail call double @atof(i8* %17)
%19 = tail call i32 @free(i8* %17)
br label %20
20: ; preds = %2, %15
%21 = phi double [ %18, %15 ], [ 5.000000e-01, %2 ]
ret double %21
}