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

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ median_closeModule();
int /*<<< orphan*/ median_initModule(int);
int /*<<< orphan*/ median_newObservation(int, float *);
int /*<<< orphan*/ mode_closeModule();
int /*<<< orphan*/ mode_initModule(int);
int /*<<< orphan*/ mode_newObservation(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ srand(int);
scalar_t__ *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  int obser;
  float median = 0, medianref = -1;
  char company[16] = "", mode[16] = "", companyref[16] = "";
  int nerrors = 0;
  srand((int)time(NULL));
  FILE *fin = fopen("data.txt", "r");
  FILE *fout = fopen("results.txt", "r");
  if (!fin || !fout) {
    printf("erro ao abrir ficheiro\n");
    return -1;
  }
  median_initModule(100000);
  mode_initModule(100000);
  while (!feof(fin)) {
    fscanf(fin, "%d;", &obser);
    fgets(company, sizeof(company), fin);
    if (strchr(company, '\r') != NULL)
      *strchr(company, '\r') = 0;
    if (strchr(company, '\n') != NULL)
      *strchr(company, '\n') = 0;
    fscanf(fout, "%f;", &medianref);
    fgets(companyref, sizeof(companyref), fout);
    if (strchr(companyref, '\r') != NULL)
      *strchr(companyref, '\r') = 0;
    if (strchr(companyref, '\n') != NULL)
      *strchr(companyref, '\n') = 0;
    median_newObservation(obser, &median);
    mode_newObservation(company, mode);
    if ((median != medianref)) {
      nerrors++;
      break;
    }
    if ((strcmp(mode, companyref) != 0)) {
      nerrors++;
      break;
    }
  }
  median_closeModule();
  mode_closeModule();
  fclose(fin);
  fclose(fout);
  if (nerrors) {
    printf("ERROS no calculo da mediana ou moda\n");
    return -1;
  } else
    printf("OK no calculo da mediana e moda\n");
  clock_t inicio, fim;
  double tempo;
  int score;
  int cap = 10000000;
  median_initModule(cap);
  score = 0;
  inicio = clock();
  while (1) {
    obser = rand() % (cap / 100);
    median_newObservation(obser, &median);
    fim = clock();
    tempo = (double)(fim - inicio) / CLOCKS_PER_SEC;
    if (tempo > 2)
      break;
    score++;
    if (score >= cap)
      break;
  }
  median_closeModule();
  printf("Median SCORE %d\n", score);
  char modeCompany[16];
  char name[16];
  mode_initModule(cap);
  score = 0;
  inicio = clock();
  while (1) {
    obser = rand() % (cap / 100);
    sprintf(name, "%d", obser);
    mode_newObservation(name, modeCompany);
    fim = clock();
    tempo = (double)(fim - inicio) / CLOCKS_PER_SEC;
    if (tempo > 2)
      break;
    score++;
    if (score >= cap)
      break;
  }
  mode_closeModule();
  printf("Mode SCORE %d\n", score);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xd9e(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
movl   $0x0,-0x44(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10f0 <time@plt>
mov    %eax,%edi
call   10a0 <srand@plt>
lea    0xd5b(%rip),%rdi
lea    0xd5d(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x50(%rbp)
lea    0xd4f(%rip),%rdi
lea    0xd46(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     12f2 <main+0xb2>
cmpq   $0x0,-0x58(%rbp)
jne    130c <main+0xcc>
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16b1 <main+0x471>
mov    $0x186a0,%edi
call   1150 <median_initModule@plt>
mov    $0x186a0,%edi
call   1100 <mode_initModule@plt>
mov    -0x50(%rbp),%rdi
call   10e0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    133e <main+0xfe>
jmp    14ad <main+0x26d>
mov    -0x50(%rbp),%rdi
lea    0xcf6(%rip),%rsi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1090 <fscanf@plt>
lea    -0x20(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    $0x10,%esi
call   10b0 <fgets@plt>
lea    -0x20(%rbp),%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     1393 <main+0x153>
lea    -0x20(%rbp),%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
movq   $0x0,(%rax)
lea    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     13c0 <main+0x180>
lea    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
movq   $0x0,(%rax)
mov    -0x58(%rbp),%rdi
lea    0xc78(%rip),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1090 <fscanf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    $0x10,%esi
call   10b0 <fgets@plt>
lea    -0x40(%rbp),%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     1415 <main+0x1d5>
lea    -0x40(%rbp),%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
movq   $0x0,(%rax)
lea    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     1442 <main+0x202>
lea    -0x40(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1110 <median_newObservation@plt>
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <mode_newObservation@plt>
movss  -0xc(%rbp),%xmm0
ucomiss -0x10(%rbp),%xmm0
jne    1475 <main+0x235>
jp     1475 <main+0x235>
jmp    1483 <main+0x243>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    14ad <main+0x26d>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
je     14a8 <main+0x268>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    14ad <main+0x26d>
jmp    1320 <main+0xe0>
mov    $0x0,%al
call   1140 <median_closeModule@plt>
mov    $0x0,%al
call   10d0 <mode_closeModule@plt>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x44(%rbp)
je     14f1 <main+0x2b1>
lea    0xb69(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16b1 <main+0x471>
lea    0xb74(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x989680,-0x78(%rbp)
mov    -0x78(%rbp),%edi
call   1150 <median_initModule@plt>
movl   $0x0,-0x74(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1160 <rand@plt>
mov    %eax,-0xa4(%rbp)
mov    -0x78(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xa4(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1110 <median_newObservation@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
sub    -0x60(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2a77(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  0xa81(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1596 <main+0x356>
jmp    15b5 <main+0x375>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x78(%rbp),%eax
jl     15b0 <main+0x370>
jmp    15b5 <main+0x375>
jmp    1520 <main+0x2e0>
mov    $0x0,%al
call   1140 <median_closeModule@plt>
mov    -0x74(%rbp),%esi
lea    0xac7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x78(%rbp),%edi
call   1100 <mode_initModule@plt>
movl   $0x0,-0x74(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1160 <rand@plt>
mov    %eax,-0xa8(%rbp)
mov    -0x78(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xa8(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xa80(%rip),%rsi
call   1130 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1030 <mode_newObservation@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
sub    -0x60(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2993(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  0x99d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    167a <main+0x43a>
jmp    1699 <main+0x459>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x78(%rbp),%eax
jl     1694 <main+0x454>
jmp    1699 <main+0x459>
jmp    15e7 <main+0x3a7>
mov    $0x0,%al
call   10d0 <mode_closeModule@plt>
mov    -0x74(%rbp),%esi
lea    0x9f7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
movl   $0x0,0x4(%rsp)
movl   $0xbf800000,0xc(%rsp)
bf
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
xor    %edi,%edi
call   10f0 <time@plt>
mov    %eax,%edi
call   10a0 <srand@plt>
lea    0xd83(%rip),%rdi
lea    0xd85(%rip),%rbx
mov    %rbx,%rsi
call   1120 <fopen@plt>
mov    %rax,%r13
lea    0xd75(%rip),%rdi
mov    %rbx,%rsi
call   1120 <fopen@plt>
test   %r13,%r13
je     1445 <main+0x205>
mov    %rax,%r14
test   %rax,%rax
je     1445 <main+0x205>
mov    $0x186a0,%edi
call   1150 <median_initModule@plt>
mov    $0x186a0,%edi
call   1100 <mode_initModule@plt>
lea    0x30(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0x4(%rsp),%rbp
lea    0x20(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
call   10e0 <feof@plt>
test   %eax,%eax
jne    1467 <main+0x227>
mov    %r13,%rdi
lea    0xd15(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1090 <fscanf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    %r13,%rdx
call   10b0 <fgets@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     134c <main+0x10c>
mov    %rbx,%rdi
mov    $0xd,%esi
call   1070 <strchr@plt>
movq   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1372 <main+0x132>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
movq   $0x0,(%rax)
mov    %r14,%rdi
lea    0xca7(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1090 <fscanf@plt>
mov    %r12,%rdi
mov    $0x10,%esi
mov    %r14,%rdx
call   10b0 <fgets@plt>
mov    %r12,%rdi
mov    $0xd,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     13be <main+0x17e>
mov    %r12,%rdi
mov    $0xd,%esi
call   1070 <strchr@plt>
movq   $0x0,(%rax)
mov    %r12,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     13e4 <main+0x1a4>
mov    %r12,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
movq   $0x0,(%rax)
mov    0x8(%rsp),%edi
mov    %rbp,%rsi
call   1110 <median_newObservation@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <mode_newObservation@plt>
movss  0x4(%rsp),%xmm0
ucomiss 0xc(%rsp),%xmm0
jne    141e <main+0x1de>
jp     141e <main+0x1de>
mov    %r15,%rdi
mov    %r12,%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     12f0 <main+0xb0>
xor    %eax,%eax
call   1140 <median_closeModule@plt>
xor    %eax,%eax
call   10d0 <mode_closeModule@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xc3e(%rip),%rdi
jmp    144c <main+0x20c>
lea    0xbfe(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1140 <median_closeModule@plt>
xor    %eax,%eax
call   10d0 <mode_closeModule@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xbd5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x989680,%edi
call   1150 <median_initModule@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%rbp
lea    0x4(%rsp),%r14
mov    0x2b37(%rip),%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1160 <rand@plt>
movslq %eax,%rdi
imul   $0x14f8b589,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2d,%rax
add    %ecx,%eax
imul   $0x186a0,%eax,%eax
sub    %eax,%edi
mov    %edi,0x8(%rsp)
mov    %r14,%rsi
call   1110 <median_newObservation@plt>
xor    %eax,%eax
call   1050 <clock@plt>
sub    %rbp,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x0(%r13),%xmm0
ucomisd 0xaee(%rip),%xmm0
ja     1524 <main+0x2e4>
add    $0x1,%ebx
cmp    $0x989680,%ebx
jne    14c0 <main+0x280>
mov    $0x989680,%ebx
xor    %eax,%eax
call   1140 <median_closeModule@plt>
lea    0xaf5(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x989680,%edi
call   1100 <mode_initModule@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%rbp
lea    0xae2(%rip),%r14
lea    0x40(%rsp),%r15
lea    0x50(%rsp),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1160 <rand@plt>
movslq %eax,%rdx
imul   $0x14f8b589,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2d,%rax
add    %ecx,%eax
imul   $0x186a0,%eax,%eax
sub    %eax,%edx
mov    %edx,0x8(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1130 <sprintf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <mode_newObservation@plt>
xor    %eax,%eax
call   1050 <clock@plt>
sub    %rbp,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x0(%r13),%xmm0
ucomisd 0xa30(%rip),%xmm0
ja     15e2 <main+0x3a2>
add    $0x1,%ebx
cmp    $0x989680,%ebx
jne    1570 <main+0x330>
mov    $0x989680,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   10d0 <mode_closeModule@plt>
lea    0xa49(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1456 <main+0x216>

LLVM IR (-O0):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"results.txt\00"
@.str.3 = [24 x i8] c"erro ao abrir ficheiro\0A\00"
@.str.4 = [4 x i8] c"%d;\00"
@.str.5 = [4 x i8] c"%f;\00"
@.str.6 = [37 x i8] c"ERROS no calculo da mediana ou moda\0A\00"
@.str.7 = [33 x i8] c"OK no calculo da mediana e moda\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.8 = [17 x i8] c"Median SCORE %d\0A\00"
@.str.9 = [3 x i8] c"%d\00"
@.str.10 = [15 x i8] c"Mode SCORE %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
%16 = alloca [16 x i8]
%17 = alloca [16 x i8]
store i32 0, i32* %1
store float 0.000000e+00, float* %3
store float -1.000000e+00, float* %4
%18 = bitcast [16 x i8]* %5 to i8*
%19 = bitcast [16 x i8]* %6 to i8*
%20 = bitcast [16 x i8]* %7 to i8*
store i32 0, i32* %8
%21 = call i64 @time(i32* null)
%22 = trunc i64 %21 to i32
%23 = call i32 @srand(i32 %22)
%24 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %9
%25 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %10
%26 = load i32*, i32** %9
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %0
%29 = load i32*, i32** %10
%30 = icmp ne i32* %29, null
br i1 %30, label %33, label %31
31: ; preds = %28, %0
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %182
33: ; preds = %28
%34 = call i32 @median_initModule(i32 100000)
%35 = call i32 @mode_initModule(i32 100000)
br label %36
36: ; preds = %99, %33
%37 = load i32*, i32** %9
%38 = call i32 @feof(i32* %37)
%39 = icmp ne i32 %38, 0
%40 = xor i1 %39, true
br i1 %40, label %41, label %100
41: ; preds = %36
%42 = load i32*, i32** %9
%43 = call i32 (i32*, i8*, ...) @fscanf(i32* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%45 = load i32*, i32** %9
%46 = call i32 @fgets(i8* %44, i32 16, i32* %45)
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%48 = call i64* @strchr(i8* %47, i8 signext 13)
%49 = icmp ne i64* %48, null
br i1 %49, label %50, label %53
50: ; preds = %41
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%52 = call i64* @strchr(i8* %51, i8 signext 13)
store i64 0, i64* %52
br label %53
53: ; preds = %50, %41
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%55 = call i64* @strchr(i8* %54, i8 signext 10)
%56 = icmp ne i64* %55, null
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%59 = call i64* @strchr(i8* %58, i8 signext 10)
store i64 0, i64* %59
br label %60
60: ; preds = %57, %53
%61 = load i32*, i32** %10
%62 = call i32 (i32*, i8*, ...) @fscanf(i32* %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), float* %4)
%63 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%64 = load i32*, i32** %10
%65 = call i32 @fgets(i8* %63, i32 16, i32* %64)
%66 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%67 = call i64* @strchr(i8* %66, i8 signext 13)
%68 = icmp ne i64* %67, null
br i1 %68, label %69, label %72
69: ; preds = %60
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%71 = call i64* @strchr(i8* %70, i8 signext 13)
store i64 0, i64* %71
br label %72
72: ; preds = %69, %60
%73 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%74 = call i64* @strchr(i8* %73, i8 signext 10)
%75 = icmp ne i64* %74, null
br i1 %75, label %76, label %79
76: ; preds = %72
%77 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%78 = call i64* @strchr(i8* %77, i8 signext 10)
store i64 0, i64* %78
br label %79
79: ; preds = %76, %72
%80 = load i32, i32* %2
%81 = call i32 @median_newObservation(i32 %80, float* %3)
%82 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%83 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%84 = call i32 @mode_newObservation(i8* %82, i8* %83)
%85 = load float, float* %3
%86 = load float, float* %4
%87 = fcmp une float %85, %86
br i1 %87, label %88, label %91
88: ; preds = %79
%89 = load i32, i32* %8
%90 = add nsw i32 %89, 1
store i32 %90, i32* %8
br label %100
91: ; preds = %79
%92 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%93 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%94 = call i64 @strcmp(i8* %92, i8* %93)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = load i32, i32* %8
%98 = add nsw i32 %97, 1
store i32 %98, i32* %8
br label %100
99: ; preds = %91
br label %36
100: ; preds = %96, %88, %36
%101 = call i32 (...) @median_closeModule()
%102 = call i32 (...) @mode_closeModule()
%103 = load i32*, i32** %9
%104 = call i32 @fclose(i32* %103)
%105 = load i32*, i32** %10
%106 = call i32 @fclose(i32* %105)
%107 = load i32, i32* %8
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %100
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %182
111: ; preds = %100
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %113
113: ; preds = %111
store i32 10000000, i32* %15
%114 = load i32, i32* %15
%115 = call i32 @median_initModule(i32 %114)
store i32 0, i32* %14
%116 = call i64 (...) @clock()
store i64 %116, i64* %11
br label %117
117: ; preds = %113, %141
%118 = call i32 (...) @rand()
%119 = load i32, i32* %15
%120 = sdiv i32 %119, 100
%121 = srem i32 %118, %120
store i32 %121, i32* %2
%122 = load i32, i32* %2
%123 = call i32 @median_newObservation(i32 %122, float* %3)
%124 = call i64 (...) @clock()
store i64 %124, i64* %12
%125 = load i64, i64* %12
%126 = load i64, i64* %11
%127 = sub nsw i64 %125, %126
%128 = sitofp i64 %127 to double
%129 = load double, double* @CLOCKS_PER_SEC
%130 = fdiv double %128, %129
store double %130, double* %13
%131 = load double, double* %13
%132 = fcmp ogt double %131, 2.000000e+00
br i1 %132, label %133, label %134
133: ; preds = %117
br label %142
134: ; preds = %117
%135 = load i32, i32* %14
%136 = add nsw i32 %135, 1
store i32 %136, i32* %14
%137 = load i32, i32* %14
%138 = load i32, i32* %15
%139 = icmp sge i32 %137, %138
br i1 %139, label %140, label %141
140: ; preds = %134
br label %142
141: ; preds = %134
br label %117
142: ; preds = %140, %133
%143 = call i32 (...) @median_closeModule()
%144 = load i32, i32* %14
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %144)
%146 = load i32, i32* %15
%147 = call i32 @mode_initModule(i32 %146)
store i32 0, i32* %14
%148 = call i64 (...) @clock()
store i64 %148, i64* %11
br label %149
149: ; preds = %142, %177
%150 = call i32 (...) @rand()
%151 = load i32, i32* %15
%152 = sdiv i32 %151, 100
%153 = srem i32 %150, %152
store i32 %153, i32* %2
%154 = getelementptr inbounds [16 x i8], [16 x i8]* %17, i64 0, i64 0
%155 = load i32, i32* %2
%156 = call i32 @sprintf(i8* %154, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 %155)
%157 = getelementptr inbounds [16 x i8], [16 x i8]* %17, i64 0, i64 0
%158 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 0
%159 = call i32 @mode_newObservation(i8* %157, i8* %158)
%160 = call i64 (...) @clock()
store i64 %160, i64* %12
%161 = load i64, i64* %12
%162 = load i64, i64* %11
%163 = sub nsw i64 %161, %162
%164 = sitofp i64 %163 to double
%165 = load double, double* @CLOCKS_PER_SEC
%166 = fdiv double %164, %165
store double %166, double* %13
%167 = load double, double* %13
%168 = fcmp ogt double %167, 2.000000e+00
br i1 %168, label %169, label %170
169: ; preds = %149
br label %178
170: ; preds = %149
%171 = load i32, i32* %14
%172 = add nsw i32 %171, 1
store i32 %172, i32* %14
%173 = load i32, i32* %14
%174 = load i32, i32* %15
%175 = icmp sge i32 %173, %174
br i1 %175, label %176, label %177
176: ; preds = %170
br label %178
177: ; preds = %170
br label %149
178: ; preds = %176, %169
%179 = call i32 (...) @mode_closeModule()
%180 = load i32, i32* %14
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 %180)
br label %182
182: ; preds = %178, %109, %31
%183 = load i32, i32* %1
ret i32 %183
}

LLVM IR (-O2):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"results.txt\00"
@.str.4 = [4 x i8] c"%d;\00"
@.str.5 = [4 x i8] c"%f;\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.8 = [17 x i8] c"Median SCORE %d\0A\00"
@.str.9 = [3 x i8] c"%d\00"
@.str.10 = [15 x i8] c"Mode SCORE %d\0A\00"
@str = [23 x i8] c"erro ao abrir ficheiro\00"
@str.11 = [32 x i8] c"OK no calculo da mediana e moda\00"
@str.12 = [36 x i8] c"ERROS no calculo da mediana ou moda\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca [16 x i8]
%9 = bitcast i32* %1 to i8*
%10 = bitcast float* %2 to i8*
store float 0.000000e+00, float* %2
%11 = bitcast float* %3 to i8*
store float -1.000000e+00, float* %3
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%15 = tail call i64 @time(i32* null)
%16 = trunc i64 %15 to i32
%17 = tail call i32 @srand(i32 %16)
%18 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32* %18, null
%21 = icmp ne i32* %19, null
%22 = and i1 %20, %21
br i1 %22, label %25, label %23
23: ; preds = %0
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %120
25: ; preds = %0
%26 = tail call i32 @median_initModule(i32 100000)
%27 = tail call i32 @mode_initModule(i32 100000)
br label %28
28: ; preds = %62, %25
%29 = call i32 @feof(i32* %18)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %71
31: ; preds = %28
%32 = call i32 (i32*, i8*, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%33 = call i32 @fgets(i8* %12, i32 16, i32* %18)
%34 = call i64* @strchr(i8* %12, i8 signext 13)
%35 = icmp eq i64* %34, null
br i1 %35, label %38, label %36
36: ; preds = %31
%37 = call i64* @strchr(i8* %12, i8 signext 13)
store i64 0, i64* %37
br label %38
38: ; preds = %36, %31
%39 = call i64* @strchr(i8* %12, i8 signext 10)
%40 = icmp eq i64* %39, null
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = call i64* @strchr(i8* %12, i8 signext 10)
store i64 0, i64* %42
br label %43
43: ; preds = %41, %38
%44 = call i32 (i32*, i8*, ...) @fscanf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), float* %3)
%45 = call i32 @fgets(i8* %14, i32 16, i32* %19)
%46 = call i64* @strchr(i8* %14, i8 signext 13)
%47 = icmp eq i64* %46, null
br i1 %47, label %50, label %48
48: ; preds = %43
%49 = call i64* @strchr(i8* %14, i8 signext 13)
store i64 0, i64* %49
br label %50
50: ; preds = %48, %43
%51 = call i64* @strchr(i8* %14, i8 signext 10)
%52 = icmp eq i64* %51, null
br i1 %52, label %55, label %53
53: ; preds = %50
%54 = call i64* @strchr(i8* %14, i8 signext 10)
store i64 0, i64* %54
br label %55
55: ; preds = %53, %50
%56 = load i32, i32* %1
%57 = call i32 @median_newObservation(i32 %56, float* %2)
%58 = call i32 @mode_newObservation(i8* %12, i8* %13)
%59 = load float, float* %2
%60 = load float, float* %3
%61 = fcmp une float %59, %60
br i1 %61, label %65, label %62
62: ; preds = %55
%63 = call i64 @strcmp(i8* %13, i8* %14)
%64 = icmp eq i64 %63, 0
br i1 %64, label %28, label %65
65: ; preds = %62, %55
%66 = call i32 (...) @median_closeModule()
%67 = call i32 (...) @mode_closeModule()
%68 = call i32 @fclose(i32* %18)
%69 = call i32 @fclose(i32* %19)
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.12, i64 0, i64 0))
br label %120
71: ; preds = %28
%72 = call i32 (...) @median_closeModule()
%73 = call i32 (...) @mode_closeModule()
%74 = call i32 @fclose(i32* %18)
%75 = call i32 @fclose(i32* %19)
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0))
%77 = call i32 @median_initModule(i32 10000000)
%78 = call i64 (...) @clock()
br label %79
79: ; preds = %90, %71
%80 = phi i32 [ 0, %71 ], [ %91, %90 ]
%81 = call i32 (...) @rand()
%82 = srem i32 %81, 100000
store i32 %82, i32* %1
%83 = call i32 @median_newObservation(i32 %82, float* %2)
%84 = call i64 (...) @clock()
%85 = sub nsw i64 %84, %78
%86 = sitofp i64 %85 to double
%87 = load double, double* @CLOCKS_PER_SEC
%88 = fdiv double %86, %87
%89 = fcmp ogt double %88, 2.000000e+00
br i1 %89, label %93, label %90
90: ; preds = %79
%91 = add nuw nsw i32 %80, 1
%92 = icmp eq i32 %91, 10000000
br i1 %92, label %93, label %79
93: ; preds = %90, %79
%94 = phi i32 [ %80, %79 ], [ 10000000, %90 ]
%95 = call i32 (...) @median_closeModule()
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %94)
%97 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%98 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%99 = call i32 @mode_initModule(i32 10000000)
%100 = call i64 (...) @clock()
br label %101
101: ; preds = %113, %93
%102 = phi i32 [ 0, %93 ], [ %114, %113 ]
%103 = call i32 (...) @rand()
%104 = srem i32 %103, 100000
store i32 %104, i32* %1
%105 = call i32 @sprintf(i8* %98, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 %104)
%106 = call i32 @mode_newObservation(i8* %98, i8* %97)
%107 = call i64 (...) @clock()
%108 = sub nsw i64 %107, %100
%109 = sitofp i64 %108 to double
%110 = load double, double* @CLOCKS_PER_SEC
%111 = fdiv double %109, %110
%112 = fcmp ogt double %111, 2.000000e+00
br i1 %112, label %116, label %113
113: ; preds = %101
%114 = add nuw nsw i32 %102, 1
%115 = icmp eq i32 %114, 10000000
br i1 %115, label %116, label %101
116: ; preds = %113, %101
%117 = phi i32 [ %102, %101 ], [ 10000000, %113 ]
%118 = call i32 (...) @mode_closeModule()
%119 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 %117)
br label %120
120: ; preds = %116, %65, %23
%121 = phi i32 [ -1, %65 ], [ 0, %116 ], [ -1, %23 ]
ret i32 %121
}