#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 double clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ FMindex(char *, char *, char *, char *, int, int, int *);
double clock();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, int, double);
int rand();
char *substring(char *, int, int);
double vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc(
    int lengthOfInput, int duzinaAbecede, char *S, char *B, char *abeceda,
    int brojTestnihPrimjerka, int zadanaDuzinaPodnizaUlaznogNiza,
    double *tablicaVrijednosti, int C[]) {
  int i = 0;
  clock_t beginStatTime, endStatTime;
  int randPocetak = 0;
  double sum = 0;
  double aritmetickaSredina = 0;
  char *randomPodNiz;
  for (i = 0; i < brojTestnihPrimjerka; i++) {
    randPocetak = rand() % (lengthOfInput - zadanaDuzinaPodnizaUlaznogNiza - 2);
    randomPodNiz = substring(S, randPocetak, zadanaDuzinaPodnizaUlaznogNiza);
    beginStatTime = clock();
    FMindex(randomPodNiz, S, B, abeceda, lengthOfInput, duzinaAbecede, C);
    endStatTime = clock();
    printf("\n%4d. %.10f", i + 1,
           ((double)endStatTime - beginStatTime) / CLOCKS_PER_SEC);
    sum = sum + (((double)endStatTime - beginStatTime) / CLOCKS_PER_SEC);
    *(tablicaVrijednosti + i) =
        (((double)endStatTime - beginStatTime) / CLOCKS_PER_SEC);
    free(randomPodNiz);
  }
  aritmetickaSredina = (double)sum / i;
  return aritmetickaSredina;
}


x86 assembly (clang, -O0):
<vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12a3 <vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc+0x143>
mov    $0x0,%al
call   1080 <rand@plt>
mov    -0x4(%rbp),%ecx
sub    0x10(%rbp),%ecx
sub    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    0x10(%rbp),%edx
call   1070 <substring@plt>
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1050 <clock@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x4(%rbp),%r8d
mov    -0x8(%rbp),%r9d
mov    0x20(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <FMindex@plt>
mov    $0x0,%al
call   1050 <clock@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%esi
add    $0x1,%esi
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    0x2db1(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdbe(%rip),%rdi
call   1060 <printf@plt>
movsd  -0x48(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
mov    0x2d8b(%rip),%rax
divsd  (%rax),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    0x2d6d(%rip),%rax
divsd  (%rax),%xmm0
mov    0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ae <vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc+0x4e>
movsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edi,0x14(%rsp)
test   %r9d,%r9d
jle    12ac <vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc+0x14c>
mov    %r8,%r12
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %r9d,%eax
mov    %rax,0x30(%rsp)
mov    0x14(%rsp),%eax
sub    0x80(%rsp),%eax
add    $0xfffffffe,%eax
mov    %eax,0x2c(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
xor    %r15d,%r15d
mov    %r8,0x40(%rsp)
mov    %rdx,0x38(%rsp)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
cltd
idivl  0x2c(%rsp)
mov    %rbp,%rdi
mov    %edx,%esi
mov    0x80(%rsp),%edx
call   1070 <substring@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1050 <clock@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x90(%rsp),%rax
mov    %rax,(%rsp)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    0x14(%rsp),%r8d
mov    %r14d,%r9d
call   1040 <FMindex@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %r14d,%r12d
lea    0x1(%r15),%r14
subsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
mov    0x2db5(%rip),%rbp
divsd  0x0(%rbp),%xmm0
lea    0xdc9(%rip),%rdi
mov    %r14d,%esi
call   1060 <printf@plt>
movsd  0x18(%rsp),%xmm1
divsd  0x0(%rbp),%xmm1
movsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
mov    0x88(%rsp),%rax
movsd  %xmm1,(%rax,%r15,8)
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14,%r15
cmp    %r14,0x30(%rsp)
mov    %r12d,%r14d
mov    0x38(%rsp),%rbp
mov    0x40(%rsp),%r12
jne    11c0 <vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc+0x60>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x30(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    12b4 <vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc+0x154>
movsd  0xd4c(%rip),%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"\0A%4d. %.10f\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define double @vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc(i32 %0, i32 %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6, double* %7, i32* %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca double*
%18 = alloca i32*
%19 = alloca i32
%20 = alloca double
%21 = alloca double
%22 = alloca i32
%23 = alloca double
%24 = alloca double
%25 = alloca i8*
store i32 %0, i32* %10
store i32 %1, i32* %11
store i8* %2, i8** %12
store i8* %3, i8** %13
store i8* %4, i8** %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store double* %7, double** %17
store i32* %8, i32** %18
store i32 0, i32* %19
store i32 0, i32* %22
store double 0.000000e+00, double* %23
store double 0.000000e+00, double* %24
store i32 0, i32* %19
br label %26
26: ; preds = %77, %9
%27 = load i32, i32* %19
%28 = load i32, i32* %15
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %80
30: ; preds = %26
%31 = call i32 (...) @rand()
%32 = load i32, i32* %10
%33 = load i32, i32* %16
%34 = sub nsw i32 %32, %33
%35 = sub nsw i32 %34, 2
%36 = srem i32 %31, %35
store i32 %36, i32* %22
%37 = load i8*, i8** %12
%38 = load i32, i32* %22
%39 = load i32, i32* %16
%40 = call i8* @substring(i8* %37, i32 %38, i32 %39)
store i8* %40, i8** %25
%41 = call double (...) @clock()
store double %41, double* %20
%42 = load i8*, i8** %25
%43 = load i8*, i8** %12
%44 = load i8*, i8** %13
%45 = load i8*, i8** %14
%46 = load i32, i32* %10
%47 = load i32, i32* %11
%48 = load i32*, i32** %18
%49 = call i32 @FMindex(i8* %42, i8* %43, i8* %44, i8* %45, i32 %46, i32 %47, i32* %48)
%50 = call double (...) @clock()
store double %50, double* %21
%51 = load i32, i32* %19
%52 = add nsw i32 %51, 1
%53 = load double, double* %21
%54 = load double, double* %20
%55 = fsub double %53, %54
%56 = load double, double* @CLOCKS_PER_SEC
%57 = fdiv double %55, %56
%58 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %52, double %57)
%59 = load double, double* %23
%60 = load double, double* %21
%61 = load double, double* %20
%62 = fsub double %60, %61
%63 = load double, double* @CLOCKS_PER_SEC
%64 = fdiv double %62, %63
%65 = fadd double %59, %64
store double %65, double* %23
%66 = load double, double* %21
%67 = load double, double* %20
%68 = fsub double %66, %67
%69 = load double, double* @CLOCKS_PER_SEC
%70 = fdiv double %68, %69
%71 = load double*, double** %17
%72 = load i32, i32* %19
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
store double %70, double* %74
%75 = load i8*, i8** %25
%76 = call i32 @free(i8* %75)
br label %77
77: ; preds = %30
%78 = load i32, i32* %19
%79 = add nsw i32 %78, 1
store i32 %79, i32* %19
br label %26
80: ; preds = %26
%81 = load double, double* %23
%82 = load i32, i32* %19
%83 = sitofp i32 %82 to double
%84 = fdiv double %81, %83
store double %84, double* %24
%85 = load double, double* %24
ret double %85
}

LLVM IR (-O2):
@.str = [12 x i8] c"\0A%4d. %.10f\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define double @vrijemeZaRandomPodnizoveUlazaZadaneDuljineOcc(i32 %0, i32 %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6, double* nocapture writeonly %7, i32* %8) {
%10 = icmp sgt i32 %5, 0
br i1 %10, label %11, label %39
11: ; preds = %9
%12 = add i32 %0, -2
%13 = sub i32 %12, %6
%14 = zext i32 %5 to i64
br label %15
15: ; preds = %11, %15
%16 = phi i64 [ 0, %11 ], [ %24, %15 ]
%17 = phi double [ 0.000000e+00, %11 ], [ %32, %15 ]
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, %13
%20 = tail call i8* @substring(i8* %2, i32 %19, i32 %6)
%21 = tail call double (...) @clock()
%22 = tail call i32 @FMindex(i8* %20, i8* %2, i8* %3, i8* %4, i32 %0, i32 %1, i32* %8)
%23 = tail call double (...) @clock()
%24 = add nuw nsw i64 %16, 1
%25 = fsub double %23, %21
%26 = load double, double* @CLOCKS_PER_SEC
%27 = fdiv double %25, %26
%28 = trunc i64 %24 to i32
%29 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %28, double %27)
%30 = load double, double* @CLOCKS_PER_SEC
%31 = fdiv double %25, %30
%32 = fadd double %17, %31
%33 = getelementptr inbounds double, double* %7, i64 %16
store double %31, double* %33
%34 = tail call i32 @free(i8* %20)
%35 = icmp eq i64 %24, %14
br i1 %35, label %36, label %15
36: ; preds = %15
%37 = sitofp i32 %5 to double
%38 = fdiv double %32, %37
br label %39
39: ; preds = %36, %9
%40 = phi double [ %38, %36 ], [ 0x7FF8000000000000, %9 ]
ret double %40
}