#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 vrijemeZaRandomPodnizoveUlazaOcc(int lengthOfInput, int duzinaAbecede,
                                        char *S, char *B, char *abeceda,
                                        int brojTestnihPrimjerka, int C[]) {
  int i = 0;
  clock_t beginStatTime, endStatTime;
  int randPocetak = 0, randKraj = 0;
  double sum = 0;
  double aritmetickaSredina = 0;
  char *randomPodNiz;
  for (i = 0; i < brojTestnihPrimjerka; i++) {
    randPocetak = rand() % lengthOfInput;
    randKraj = randPocetak + rand() % (lengthOfInput - randPocetak);
    randomPodNiz = substring(S, randPocetak, randKraj - randPocetak);
    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);
    free(randomPodNiz);
  }
  aritmetickaSredina = (double)sum / i;
  return aritmetickaSredina;
}


x86 assembly (clang, -O0):
<vrijemeZaRandomPodnizoveUlazaOcc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%rax
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)
movl   $0x0,-0x40(%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    129a <vrijemeZaRandomPodnizoveUlazaOcc+0x13a>
mov    $0x0,%al
call   1080 <rand@plt>
cltd
idivl  -0x4(%rbp)
mov    %edx,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    -0x4(%rbp),%ecx
sub    -0x3c(%rbp),%ecx
cltd
idiv   %ecx
mov    -0x5c(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x40(%rbp),%edx
sub    -0x3c(%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    0x10(%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    0x2d98(%rip),%rax
divsd  (%rax),%xmm0
lea    0xda5(%rip),%rdi
call   1060 <printf@plt>
movsd  -0x48(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
mov    0x2d72(%rip),%rax
divsd  (%rax),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ae <vrijemeZaRandomPodnizoveUlazaOcc+0x4e>
movsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vrijemeZaRandomPodnizoveUlazaOcc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
test   %r9d,%r9d
jle    12a2 <vrijemeZaRandomPodnizoveUlazaOcc+0x142>
mov    %r8,%rbx
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %r9d,0x24(%rsp)
mov    %r9d,%eax
neg    %eax
mov    %rax,0x30(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    $0x1,%r14d
mov    %esi,0x2c(%rsp)
mov    %edi,0x28(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
cltd
mov    0x28(%rsp),%r13d
idiv   %r13d
mov    %r12,%r15
mov    %rbx,%r12
mov    %edx,%ebx
xor    %eax,%eax
call   1080 <rand@plt>
mov    %r13d,%ecx
sub    %ebx,%ecx
cltd
idiv   %ecx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12,%rbx
mov    %r15,%r12
call   1070 <substring@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <clock@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x70(%rsp),%rax
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r13d,%r8d
mov    0x2c(%rsp),%r9d
call   1040 <FMindex@plt>
xor    %eax,%eax
call   1050 <clock@plt>
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    0x2db5(%rip),%r13
divsd  0x0(%r13),%xmm0
lea    0xdc8(%rip),%rdi
mov    %r14d,%esi
call   1060 <printf@plt>
movsd  0x10(%rsp),%xmm1
divsd  0x0(%r13),%xmm1
movsd  0x18(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x30(%rsp),%rax
add    %r14d,%eax
add    $0x1,%eax
mov    %r14d,%ecx
add    $0x1,%ecx
mov    %ecx,%r14d
cmp    $0x1,%eax
jne    11b0 <vrijemeZaRandomPodnizoveUlazaOcc+0x50>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x24(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    12aa <vrijemeZaRandomPodnizoveUlazaOcc+0x14a>
movsd  0xd56(%rip),%xmm0
add    $0x38,%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 @vrijemeZaRandomPodnizoveUlazaOcc(i32 %0, i32 %1, i8* %2, i8* %3, i8* %4, i32 %5, i32* %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca double
%22 = alloca i8*
store i32 %0, i32* %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i32 %5, i32* %13
store i32* %6, i32** %14
store i32 0, i32* %15
store i32 0, i32* %18
store i32 0, i32* %19
store double 0.000000e+00, double* %20
store double 0.000000e+00, double* %21
store i32 0, i32* %15
br label %23
23: ; preds = %71, %7
%24 = load i32, i32* %15
%25 = load i32, i32* %13
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %74
27: ; preds = %23
%28 = call i32 (...) @rand()
%29 = load i32, i32* %8
%30 = srem i32 %28, %29
store i32 %30, i32* %18
%31 = load i32, i32* %18
%32 = call i32 (...) @rand()
%33 = load i32, i32* %8
%34 = load i32, i32* %18
%35 = sub nsw i32 %33, %34
%36 = srem i32 %32, %35
%37 = add nsw i32 %31, %36
store i32 %37, i32* %19
%38 = load i8*, i8** %10
%39 = load i32, i32* %18
%40 = load i32, i32* %19
%41 = load i32, i32* %18
%42 = sub nsw i32 %40, %41
%43 = call i8* @substring(i8* %38, i32 %39, i32 %42)
store i8* %43, i8** %22
%44 = call double (...) @clock()
store double %44, double* %16
%45 = load i8*, i8** %22
%46 = load i8*, i8** %10
%47 = load i8*, i8** %11
%48 = load i8*, i8** %12
%49 = load i32, i32* %8
%50 = load i32, i32* %9
%51 = load i32*, i32** %14
%52 = call i32 @FMindex(i8* %45, i8* %46, i8* %47, i8* %48, i32 %49, i32 %50, i32* %51)
%53 = call double (...) @clock()
store double %53, double* %17
%54 = load i32, i32* %15
%55 = add nsw i32 %54, 1
%56 = load double, double* %17
%57 = load double, double* %16
%58 = fsub double %56, %57
%59 = load double, double* @CLOCKS_PER_SEC
%60 = fdiv double %58, %59
%61 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %55, double %60)
%62 = load double, double* %20
%63 = load double, double* %17
%64 = load double, double* %16
%65 = fsub double %63, %64
%66 = load double, double* @CLOCKS_PER_SEC
%67 = fdiv double %65, %66
%68 = fadd double %62, %67
store double %68, double* %20
%69 = load i8*, i8** %22
%70 = call i32 @free(i8* %69)
br label %71
71: ; preds = %27
%72 = load i32, i32* %15
%73 = add nsw i32 %72, 1
store i32 %73, i32* %15
br label %23
74: ; preds = %23
%75 = load double, double* %20
%76 = load i32, i32* %15
%77 = sitofp i32 %76 to double
%78 = fdiv double %75, %77
store double %78, double* %21
%79 = load double, double* %21
ret double %79
}

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