#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
float count_motif_occurrences_prob(char *, char *, float);
int count_perfect_matches(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char **);
int /*<<< orphan*/ printf(char *, char *);
float *count_motif_occurrences(char *motif, char *input_filename_upstream,
                               int n_transcripts, float score_threshold,
                               float *n) {
  float curr_score;
  int i;
  int motif_length;
  char upstream_sequence[2000];
  FILE *input_file_upstream;
  char *search_string;
  char *current_string;
  int curr_n;
  for (i = 1; i <= n_transcripts; i++)
    n[i] = -1;
  input_file_upstream = fopen(input_filename_upstream, "r");
  if (input_file_upstream == NULL) {
    printf(
        "ERROR! I could not open your input upstream file %s. Exiting now...\n",
        input_filename_upstream);
    exit(1);
  }
  if (score_threshold > 0.99) {
    for (i = 1; i <= n_transcripts; i++) {
      fscanf(input_file_upstream, "%s\n", &upstream_sequence);
      curr_n = count_perfect_matches(upstream_sequence, motif);
      n[i] = curr_n;
    }
  } else {
    for (i = 1; i <= n_transcripts; i++) {
      fscanf(input_file_upstream, "%s\n", &upstream_sequence);
      curr_score = count_motif_occurrences_prob(motif, upstream_sequence,
                                                score_threshold);
      n[i] = n[i] + curr_score + 1.0;
    }
  }
  fclose(input_file_upstream);
  return n;
}


x86 assembly (clang, -O0):
<count_motif_occurrences>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movss  %xmm0,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11c5 <count_motif_occurrences+0x55>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  0xe5e(%rip),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1196 <count_motif_occurrences+0x26>
mov    -0x10(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x808(%rbp)
cmpq   $0x0,-0x808(%rbp)
jne    1204 <count_motif_occurrences+0x94>
mov    -0x10(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdeb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    128a <count_motif_occurrences+0x11a>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1285 <count_motif_occurrences+0x115>
mov    -0x808(%rbp),%rdi
lea    -0x800(%rbp),%rdx
lea    0xe14(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x800(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <count_perfect_matches@plt>
mov    %eax,-0x81c(%rbp)
cvtsi2ssl -0x81c(%rbp),%xmm0
ff
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1226 <count_motif_occurrences+0xb6>
jmp    1317 <count_motif_occurrences+0x1a7>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1312 <count_motif_occurrences+0x1a2>
mov    -0x808(%rbp),%rdi
lea    -0x800(%rbp),%rdx
lea    0xda9(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x800(%rbp),%rsi
movss  -0x18(%rbp),%xmm0
call   1060 <count_motif_occurrences_prob@plt>
movss  %xmm0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
addss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd19(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1291 <count_motif_occurrences+0x121>
jmp    1317 <count_motif_occurrences+0x1a7>
mov    -0x808(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_motif_occurrences>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7e8,%rsp
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbp
test   %edx,%edx
jle    1260 <count_motif_occurrences+0xf0>
mov    %r14d,%eax
mov    $0x1,%ecx
cmp    $0x8,%r14d
jb     1248 <count_motif_occurrences+0xd8>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
lea    -0x8(%rcx),%rsi
mov    %rsi,%rdi
shr    $0x3,%rdi
add    $0x1,%rdi
mov    %edi,%edx
and    $0x3,%edx
cmp    $0x18,%rsi
jae    11ca <count_motif_occurrences+0x5a>
xor    %esi,%esi
jmp    1212 <count_motif_occurrences+0xa2>
and    $0xfffffffffffffffc,%rdi
xor    %esi,%esi
movaps 0xe29(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
movups %xmm1,0x4(%rbx,%rsi,4)
movups %xmm1,0x14(%rbx,%rsi,4)
movups %xmm1,0x24(%rbx,%rsi,4)
movups %xmm1,0x34(%rbx,%rsi,4)
movups %xmm1,0x44(%rbx,%rsi,4)
movups %xmm1,0x54(%rbx,%rsi,4)
movups %xmm1,0x64(%rbx,%rsi,4)
movups %xmm1,0x74(%rbx,%rsi,4)
add    $0x20,%rsi
add    $0xfffffffffffffffc,%rdi
jne    11e0 <count_motif_occurrences+0x70>
test   %rdx,%rdx
je     123f <count_motif_occurrences+0xcf>
movaps 0xde2(%rip),%xmm1
xchg   %ax,%ax
lea    0x0(,%rsi,4),%rdi
or     $0x4,%rdi
movups %xmm1,(%rbx,%rdi,1)
movups %xmm1,0x10(%rbx,%rdi,1)
add    $0x8,%rsi
add    $0xffffffffffffffff,%rdx
jne    1220 <count_motif_occurrences+0xb0>
cmp    %rcx,%rax
je     1260 <count_motif_occurrences+0xf0>
or     $0x1,%rcx
add    $0x1,%rax
nopl   0x0(%rax)
movl   $0xbf800000,(%rbx,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1250 <count_motif_occurrences+0xe0>
movss  %xmm0,0xc(%rsp)
lea    0xdaf(%rip),%rsi
mov    %r12,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     136d <count_motif_occurrences+0x1fd>
mov    %rax,%r13
movss  0xc(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
ucomisd 0xd7a(%rip),%xmm0
jbe    12f5 <count_motif_occurrences+0x185>
test   %r14d,%r14d
jle    1350 <count_motif_occurrences+0x1e0>
mov    %rbp,%r12
add    $0x1,%r14d
mov    $0x1,%r15d
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
lea    0xd99(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fscanf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1090 <count_perfect_matches@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,(%rbx,%r15,4)
add    $0x1,%r15
cmp    %r15,%r14
jne    12c0 <count_motif_occurrences+0x150>
jmp    1350 <count_motif_occurrences+0x1e0>
test   %r14d,%r14d
jle    1350 <count_motif_occurrences+0x1e0>
mov    %rbp,%r15
add    $0x1,%r14d
mov    $0x1,%r12d
lea    0x10(%rsp),%rbp
nopl   0x0(%rax)
mov    %r13,%rdi
lea    0xd49(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fscanf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
movss  0xc(%rsp),%xmm0
call   1060 <count_motif_occurrences_prob@plt>
addss  (%rbx,%r12,4),%xmm0
addss  0xcd7(%rip),%xmm0
movss  %xmm0,(%rbx,%r12,4)
add    $0x1,%r12
cmp    %r12,%r14
jne    1310 <count_motif_occurrences+0x1a0>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
add    $0x7e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcaa(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [69 x i8] c"ERROR! I could not open your input upstream file %s. Exiting now...\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define float* @count_motif_occurrences(i8* %0, i8* %1, i32 %2, float %3, float* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca float
%10 = alloca float*
%11 = alloca float
%12 = alloca i32
%13 = alloca i32
%14 = alloca [2000 x i8]
%15 = alloca i32*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store float %3, float* %9
store float* %4, float** %10
store i32 1, i32* %12
br label %19
19: ; preds = %28, %5
%20 = load i32, i32* %12
%21 = load i32, i32* %8
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load float*, float** %10
%25 = load i32, i32* %12
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds float, float* %24, i64 %26
store float -1.000000e+00, float* %27
br label %28
28: ; preds = %23
%29 = load i32, i32* %12
%30 = add nsw i32 %29, 1
store i32 %30, i32* %12
br label %19
31: ; preds = %19
%32 = load i8*, i8** %7
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %33, i32** %15
%34 = load i32*, i32** %15
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i8*, i8** %7
%38 = call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %31
%41 = load float, float* %9
%42 = fpext float %41 to double
%43 = fcmp ogt double %42, 0x3FEFAE147AE147AE
br i1 %43, label %44, label %66
44: ; preds = %40
store i32 1, i32* %12
br label %45
45: ; preds = %62, %44
%46 = load i32, i32* %12
%47 = load i32, i32* %8
%48 = icmp sle i32 %46, %47
br i1 %48, label %49, label %65
49: ; preds = %45
%50 = load i32*, i32** %15
%51 = bitcast [2000 x i8]* %14 to i8**
%52 = call i32 @fscanf(i32* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %51)
%53 = getelementptr inbounds [2000 x i8], [2000 x i8]* %14, i64 0, i64 0
%54 = load i8*, i8** %6
%55 = call i32 @count_perfect_matches(i8* %53, i8* %54)
store i32 %55, i32* %18
%56 = load i32, i32* %18
%57 = sitofp i32 %56 to float
%58 = load float*, float** %10
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds float, float* %58, i64 %60
store float %57, float* %61
br label %62
62: ; preds = %49
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
store i32 %64, i32* %12
br label %45
65: ; preds = %45
br label %97
66: ; preds = %40
store i32 1, i32* %12
br label %67
67: ; preds = %93, %66
%68 = load i32, i32* %12
%69 = load i32, i32* %8
%70 = icmp sle i32 %68, %69
br i1 %70, label %71, label %96
71: ; preds = %67
%72 = load i32*, i32** %15
%73 = bitcast [2000 x i8]* %14 to i8**
%74 = call i32 @fscanf(i32* %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %73)
%75 = load i8*, i8** %6
%76 = getelementptr inbounds [2000 x i8], [2000 x i8]* %14, i64 0, i64 0
%77 = load float, float* %9
%78 = call float @count_motif_occurrences_prob(i8* %75, i8* %76, float %77)
store float %78, float* %11
%79 = load float*, float** %10
%80 = load i32, i32* %12
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds float, float* %79, i64 %81
%83 = load float, float* %82
%84 = load float, float* %11
%85 = fadd float %83, %84
%86 = fpext float %85 to double
%87 = fadd double %86, 1.000000e+00
%88 = fptrunc double %87 to float
%89 = load float*, float** %10
%90 = load i32, i32* %12
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds float, float* %89, i64 %91
store float %88, float* %92
br label %93
93: ; preds = %71
%94 = load i32, i32* %12
%95 = add nsw i32 %94, 1
store i32 %95, i32* %12
br label %67
96: ; preds = %67
br label %97
97: ; preds = %96, %65
%98 = load i32*, i32** %15
%99 = call i32 @fclose(i32* %98)
%100 = load float*, float** %10
ret float* %100
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [69 x i8] c"ERROR! I could not open your input upstream file %s. Exiting now...\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define float* @count_motif_occurrences(i8* %0, i8* %1, i32 %2, float %3, float* returned %4) {
%6 = alloca [2000 x i8]
%7 = getelementptr inbounds [2000 x i8], [2000 x i8]* %6, i64 0, i64 0
%8 = icmp slt i32 %2, 1
br i1 %8, label %73, label %9
9: ; preds = %5
%10 = add nuw i32 %2, 1
%11 = zext i32 %10 to i64
%12 = add nsw i64 %11, -1
%13 = icmp ult i64 %12, 8
br i1 %13, label %66, label %14
14: ; preds = %9
%15 = and i64 %12, -8
%16 = or i64 %15, 1
%17 = add nsw i64 %15, -8
%18 = lshr exact i64 %17, 3
%19 = add nuw nsw i64 %18, 1
%20 = and i64 %19, 3
%21 = icmp ult i64 %17, 24
br i1 %21, label %50, label %22
22: ; preds = %14
%23 = and i64 %19, 4611686018427387900
br label %24
24: ; preds = %24, %22
%25 = phi i64 [ 0, %22 ], [ %47, %24 ]
%26 = phi i64 [ 0, %22 ], [ %48, %24 ]
%27 = or i64 %25, 1
%28 = getelementptr inbounds float, float* %4, i64 %27
%29 = bitcast float* %28 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %29
%30 = getelementptr inbounds float, float* %28, i64 4
%31 = bitcast float* %30 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %31
%32 = or i64 %25, 9
%33 = getelementptr inbounds float, float* %4, i64 %32
%34 = bitcast float* %33 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %34
%35 = getelementptr inbounds float, float* %33, i64 4
%36 = bitcast float* %35 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %36
%37 = or i64 %25, 17
%38 = getelementptr inbounds float, float* %4, i64 %37
%39 = bitcast float* %38 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %39
%40 = getelementptr inbounds float, float* %38, i64 4
%41 = bitcast float* %40 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %41
%42 = or i64 %25, 25
%43 = getelementptr inbounds float, float* %4, i64 %42
%44 = bitcast float* %43 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %44
%45 = getelementptr inbounds float, float* %43, i64 4
%46 = bitcast float* %45 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %46
%47 = add nuw i64 %25, 32
%48 = add i64 %26, 4
%49 = icmp eq i64 %48, %23
br i1 %49, label %50, label %24
50: ; preds = %24, %14
%51 = phi i64 [ 0, %14 ], [ %47, %24 ]
%52 = icmp eq i64 %20, 0
br i1 %52, label %64, label %53
53: ; preds = %50, %53
%54 = phi i64 [ %61, %53 ], [ %51, %50 ]
%55 = phi i64 [ %62, %53 ], [ 0, %50 ]
%56 = or i64 %54, 1
%57 = getelementptr inbounds float, float* %4, i64 %56
%58 = bitcast float* %57 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %58
%59 = getelementptr inbounds float, float* %57, i64 4
%60 = bitcast float* %59 to <4 x float>*
store <4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x float>* %60
%61 = add nuw i64 %54, 8
%62 = add i64 %55, 1
%63 = icmp eq i64 %62, %20
br i1 %63, label %64, label %53
64: ; preds = %53, %50
%65 = icmp eq i64 %12, %15
br i1 %65, label %73, label %66
66: ; preds = %9, %64
%67 = phi i64 [ 1, %9 ], [ %16, %64 ]
br label %68
68: ; preds = %66, %68
%69 = phi i64 [ %71, %68 ], [ %67, %66 ]
%70 = getelementptr inbounds float, float* %4, i64 %69
store float -1.000000e+00, float* %70
%71 = add nuw nsw i64 %69, 1
%72 = icmp eq i64 %71, %11
br i1 %72, label %73, label %68
73: ; preds = %68, %64, %5
%74 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%75 = icmp eq i32* %74, null
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = tail call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%78 = tail call i32 @exit(i32 1)
unreachable
79: ; preds = %73
%80 = fpext float %3 to double
%81 = fcmp ogt double %80, 0x3FEFAE147AE147AE
br i1 %81, label %87, label %82
82: ; preds = %79
br i1 %8, label %110, label %83
83: ; preds = %82
%84 = bitcast [2000 x i8]* %6 to i8**
%85 = add nuw i32 %2, 1
%86 = zext i32 %85 to i64
br label %100
87: ; preds = %79
br i1 %8, label %110, label %88
88: ; preds = %87
%89 = bitcast [2000 x i8]* %6 to i8**
%90 = add nuw i32 %2, 1
%91 = zext i32 %90 to i64
br label %92
92: ; preds = %88, %92
%93 = phi i64 [ 1, %88 ], [ %98, %92 ]
%94 = call i32 @fscanf(i32* %74, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %89)
%95 = call i32 @count_perfect_matches(i8* %7, i8* %0)
%96 = sitofp i32 %95 to float
%97 = getelementptr inbounds float, float* %4, i64 %93
store float %96, float* %97
%98 = add nuw nsw i64 %93, 1
%99 = icmp eq i64 %98, %91
br i1 %99, label %110, label %92
100: ; preds = %83, %100
%101 = phi i64 [ 1, %83 ], [ %108, %100 ]
%102 = call i32 @fscanf(i32* %74, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %84)
%103 = call float @count_motif_occurrences_prob(i8* %0, i8* %7, float %3)
%104 = getelementptr inbounds float, float* %4, i64 %101
%105 = load float, float* %104
%106 = fadd float %103, %105
%107 = fadd float %106, 1.000000e+00
store float %107, float* %104
%108 = add nuw nsw i64 %101, 1
%109 = icmp eq i64 %108, %86
br i1 %109, label %110, label %100
110: ; preds = %100, %92, %82, %87
%111 = call i32 @fclose(i32* %74)
ret float* %4
}