#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*/ Insercao(int, int *);
int /*<<< orphan*/ Mergesort(int /*<<< orphan*/, int, int *);
int /*<<< orphan*/ Quicksort(int /*<<< orphan*/, int, int *);
int /*<<< orphan*/ Selecao(int, int *);
double abst(double);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int num_buscas(int *, int *, int, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, double *);
double tempo();
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vetor_copy(int *, int *, int);
int /*<<< orphan*/ vetor_rand(int *, int);
int main(int argc, char **argv) {
  double duracao, tempo_inicial, tempo_total, inicio_temp, tempo_ordenacao_sel,
      tempo_ordenacao_ins, tempo_ordenacao_merge, tempo_ordenacao_quick;
  int n, *v, *v_aux, buscas_sel, buscas_ins, buscas_merge, buscas_quick;
  char algoritmo;
  srand(time(NULL));
  if (argc != 3) {
    printf("Uso: %s tipo duracao\n", argv[0]);
    printf("   tipo: s(elecao) ou i(nsercao) ou m(ergesort) ou q(uicksort) ou "
           "t(odos)\n");
    printf("   duracao: duracao em segundos\n");
    return (0);
  }
  algoritmo = argv[1][0];
  if (algoritmo != 's' && algoritmo != 'i' && algoritmo != 'm' &&
      algoritmo != 'q' && algoritmo != 't') {
    printf("opcao nao valida\n");
    return (-1);
  }
  sscanf(argv[2], "%lf", &duracao);
  printf("|-------------------------[EP1 - Vale a pena "
         "ordenar?]--------------------|\n"
         "|  Algoritmo escolhido: %10s     Duracao dos testes: %9.2f      |\n"
         "|            Tempos de Ordenacao                 Numero de Buscas    "
         "     |\n"
         "|            Coloque seu nome aqui para identificacao!               "
         "     |\n"
         "|--------------------------------------------------------------------"
         "-----|\n"
         "|   n   | Insercao Selecao Merge. Quick. | Insercao Selecao Merge. "
         "Quick. |\n"
         "|-------|------------------------------------------------------------"
         "-----|\n",
         algoritmo == 's'   ? "selecao"
         : algoritmo == 'i' ? "insercao"
         : algoritmo == 'm' ? "mergesort"
         : algoritmo == 'q' ? "quicksort"
                            : "todos",
         duracao);
  tempo_inicial = tempo();
  tempo_total = 0;
  for (n = 2000; tempo_total < duracao; n += 2000) {
    v = malloc(n * sizeof(int));
    if (v == NULL) {
      printf("Erro na alocacao de memoria para o vetor v com %d elementos.\n",
             n);
      return (-1);
    }
    v_aux = malloc(n * sizeof(int));
    if (v_aux == NULL) {
      printf(
          "Erro na alocacao de memoria para o vetor v_aux com %d elementos.\n",
          n);
      return (-1);
    }
    vetor_rand(v, n);
    vetor_copy(v, v_aux, n);
    if (algoritmo == 's' || algoritmo == 't') {
      inicio_temp = tempo();
      Selecao(n, v_aux);
      tempo_ordenacao_sel = tempo() - inicio_temp;
      buscas_sel = num_buscas(v, v_aux, n, tempo_ordenacao_sel);
      if (algoritmo != 's')
        vetor_copy(v, v_aux, n);
    }
    if (algoritmo == 'i' || algoritmo == 't') {
      inicio_temp = tempo();
      Insercao(n, v_aux);
      tempo_ordenacao_ins = tempo() - inicio_temp;
      buscas_ins = num_buscas(v, v_aux, n, tempo_ordenacao_ins);
      if (algoritmo != 'i')
        vetor_copy(v, v_aux, n);
    }
    if (algoritmo == 'm' || algoritmo == 't') {
      inicio_temp = tempo();
      Mergesort(0, n - 1, v_aux);
      tempo_ordenacao_merge = abst(tempo() - inicio_temp);
      buscas_merge = num_buscas(v, v_aux, n, tempo_ordenacao_merge);
      if (algoritmo != 'm')
        vetor_copy(v, v_aux, n);
    }
    if (algoritmo == 'q' || algoritmo == 't') {
      inicio_temp = tempo();
      Quicksort(0, n - 1, v_aux);
      tempo_ordenacao_quick = abst(tempo() - inicio_temp);
      buscas_quick = num_buscas(v, v_aux, n, tempo_ordenacao_quick);
    }
    free(v);
    free(v_aux);
    tempo_total = tempo() - tempo_inicial;
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
cmpl   $0x3,-0x8(%rbp)
je     1260 <main+0x70>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1677 <main+0x487>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%al
mov    %al,-0x79(%rbp)
movsbl -0x79(%rbp),%eax
cmp    $0x73,%eax
je     12c8 <main+0xd8>
movsbl -0x79(%rbp),%eax
cmp    $0x69,%eax
je     12c8 <main+0xd8>
movsbl -0x79(%rbp),%eax
cmp    $0x6d,%eax
je     12c8 <main+0xd8>
movsbl -0x79(%rbp),%eax
cmp    $0x71,%eax
je     12c8 <main+0xd8>
movsbl -0x79(%rbp),%eax
cmp    $0x74,%eax
je     12c8 <main+0xd8>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <main+0x487>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdbd(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   10e0 <sscanf@plt>
movsbl -0x79(%rbp),%eax
cmp    $0x73,%eax
jne    1300 <main+0x110>
lea    0xfaf(%rip),%rax
mov    %rax,-0x88(%rbp)
jmp    137c <main+0x18c>
movsbl -0x79(%rbp),%eax
cmp    $0x69,%eax
jne    1320 <main+0x130>
lea    0xf97(%rip),%rax
mov    %rax,-0x90(%rbp)
jmp    136e <main+0x17e>
movsbl -0x79(%rbp),%eax
cmp    $0x6d,%eax
jne    1340 <main+0x150>
lea    0xf80(%rip),%rax
mov    %rax,-0x98(%rbp)
jmp    1360 <main+0x170>
movsbl -0x79(%rbp),%edx
lea    0xf7d(%rip),%rax
lea    0xf6c(%rip),%rcx
cmp    $0x71,%edx
cmove  %rcx,%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
lea    0xd09(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10f0 <tempo@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x7d0,-0x54(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1670 <main+0x480>
movslq -0x54(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1400 <main+0x210>
mov    -0x54(%rbp),%esi
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <main+0x487>
movslq -0x54(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    143b <main+0x24b>
mov    -0x54(%rbp),%esi
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <main+0x487>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%esi
call   1070 <vetor_rand@plt>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   10a0 <vetor_copy@plt>
movsbl -0x79(%rbp),%eax
cmp    $0x73,%eax
je     1471 <main+0x281>
movsbl -0x79(%rbp),%eax
cmp    $0x74,%eax
jne    14d4 <main+0x2e4>
mov    $0x0,%al
call   10f0 <tempo@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x68(%rbp),%rsi
call   10c0 <Selecao@plt>
mov    $0x0,%al
call   10f0 <tempo@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x54(%rbp),%edx
movsd  -0x38(%rbp),%xmm0
call   1110 <num_buscas@plt>
mov    %eax,-0x6c(%rbp)
movsbl -0x79(%rbp),%eax
cmp    $0x73,%eax
je     14cf <main+0x2df>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   10a0 <vetor_copy@plt>
jmp    14d4 <main+0x2e4>
movsbl -0x79(%rbp),%eax
cmp    $0x69,%eax
je     14ee <main+0x2fe>
movsbl -0x79(%rbp),%eax
cmp    $0x74,%eax
jne    1551 <main+0x361>
mov    $0x0,%al
call   10f0 <tempo@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x68(%rbp),%rsi
call   1090 <Insercao@plt>
mov    $0x0,%al
call   10f0 <tempo@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x54(%rbp),%edx
movsd  -0x40(%rbp),%xmm0
call   1110 <num_buscas@plt>
mov    %eax,-0x70(%rbp)
movsbl -0x79(%rbp),%eax
cmp    $0x69,%eax
je     154c <main+0x35c>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   10a0 <vetor_copy@plt>
jmp    1551 <main+0x361>
movsbl -0x79(%rbp),%eax
cmp    $0x6d,%eax
je     156b <main+0x37b>
movsbl -0x79(%rbp),%eax
cmp    $0x74,%eax
jne    15d8 <main+0x3e8>
mov    $0x0,%al
call   10f0 <tempo@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x54(%rbp),%esi
sub    $0x1,%esi
mov    -0x68(%rbp),%rdx
xor    %edi,%edi
call   1040 <Mergesort@plt>
mov    $0x0,%al
call   10f0 <tempo@plt>
subsd  -0x30(%rbp),%xmm0
call   1100 <abst@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x54(%rbp),%edx
movsd  -0x48(%rbp),%xmm0
call   1110 <num_buscas@plt>
mov    %eax,-0x74(%rbp)
movsbl -0x79(%rbp),%eax
cmp    $0x6d,%eax
je     15d3 <main+0x3e3>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   10a0 <vetor_copy@plt>
jmp    15d8 <main+0x3e8>
movsbl -0x79(%rbp),%eax
cmp    $0x71,%eax
je     15f2 <main+0x402>
movsbl -0x79(%rbp),%eax
cmp    $0x74,%eax
jne    163d <main+0x44d>
mov    $0x0,%al
call   10f0 <tempo@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x54(%rbp),%esi
sub    $0x1,%esi
mov    -0x68(%rbp),%rdx
xor    %edi,%edi
call   1050 <Quicksort@plt>
mov    $0x0,%al
call   10f0 <tempo@plt>
subsd  -0x30(%rbp),%xmm0
call   1100 <abst@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x54(%rbp),%edx
movsd  -0x50(%rbp),%xmm0
call   1110 <num_buscas@plt>
mov    %eax,-0x78(%rbp)
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   10f0 <tempo@plt>
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x54(%rbp),%eax
add    $0x7d0,%eax
mov    %eax,-0x54(%rbp)
jmp    13b1 <main+0x1c1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
cmp    $0x3,%ebx
jne    127e <main+0x7e>
mov    0x8(%r14),%rax
mov    (%rax),%r12b
lea    -0x69(%r12),%eax
cmp    $0xb,%al
ja     1501 <main+0x301>
movzbl %al,%eax
mov    $0xd11,%ecx
bt     %rax,%rcx
jae    1501 <main+0x301>
mov    0x10(%r14),%rdi
lea    0xdbd(%rip),%rsi
lea    0x8(%rsp),%rdx
call   10f0 <sscanf@plt>
cmp    $0x69,%r12b
je     12ac <main+0xac>
cmp    $0x6d,%r12b
je     12b5 <main+0xb5>
cmp    $0x73,%r12b
jne    12be <main+0xbe>
lea    0xfa9(%rip),%rsi
jmp    12d4 <main+0xd4>
mov    (%r14),%rsi
lea    0xd78(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x104b(%rip),%rdi
call   1050 <puts@plt>
lea    0x1089(%rip),%rdi
call   1050 <puts@plt>
jmp    152d <main+0x32d>
lea    0xf7a(%rip),%rsi
jmp    12d4 <main+0xd4>
lea    0xf7a(%rip),%rsi
jmp    12d4 <main+0xd4>
cmp    $0x71,%r12b
lea    0xf77(%rip),%rax
lea    0xf7a(%rip),%rsi
cmove  %rax,%rsi
movsd  0x8(%rsp),%xmm0
lea    0xd39(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1100 <tempo@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    152d <main+0x32d>
lea    -0x73(%r12),%r13d
mov    $0x7d0,%ebx
mov    $0x1f40,%r14d
jmp    1393 <main+0x193>
nopl   (%rax)
xor    %eax,%eax
call   1100 <tempo@plt>
movsd  %xmm0,(%rsp)
lea    -0x1(%rbx),%esi
xor    %edi,%edi
mov    %rbp,%rdx
call   1060 <Quicksort@plt>
xor    %eax,%eax
call   1100 <tempo@plt>
subsd  (%rsp),%xmm0
call   1110 <abst@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1120 <num_buscas@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1100 <tempo@plt>
subsd  0x10(%rsp),%xmm0
add    $0x7d0,%ebx
movsd  0x8(%rsp),%xmm1
add    $0x1f40,%r14d
ucomisd %xmm0,%xmm1
jbe    152d <main+0x32d>
mov    %r14d,%edi
call   10e0 <malloc@plt>
test   %rax,%rax
je     150f <main+0x30f>
mov    %rax,%r15
mov    %r14d,%edi
call   10e0 <malloc@plt>
test   %rax,%rax
je     1518 <main+0x318>
mov    %rax,%rbp
mov    %r15,%rdi
mov    %ebx,%esi
call   1080 <vetor_rand@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   10b0 <vetor_copy@plt>
cmp    $0x1,%r13b
ja     1420 <main+0x220>
xor    %eax,%eax
call   1100 <tempo@plt>
movsd  %xmm0,(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
call   10d0 <Selecao@plt>
xor    %eax,%eax
call   1100 <tempo@plt>
subsd  (%rsp),%xmm0
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1120 <num_buscas@plt>
cmp    $0x73,%r12b
je     1357 <main+0x157>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   10b0 <vetor_copy@plt>
jmp    143a <main+0x23a>
cmp    $0x71,%r12b
je     1320 <main+0x120>
cmp    $0x6d,%r12b
je     149a <main+0x29a>
cmp    $0x69,%r12b
jne    1357 <main+0x157>
xor    %eax,%eax
call   1100 <tempo@plt>
movsd  %xmm0,(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
call   10a0 <Insercao@plt>
xor    %eax,%eax
call   1100 <tempo@plt>
subsd  (%rsp),%xmm0
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1120 <num_buscas@plt>
cmp    $0x69,%r12b
je     1357 <main+0x157>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   10b0 <vetor_copy@plt>
cmp    $0x74,%r12b
je     149a <main+0x29a>
cmp    $0x71,%r12b
je     1320 <main+0x120>
cmp    $0x6d,%r12b
jne    1357 <main+0x157>
xor    %eax,%eax
call   1100 <tempo@plt>
movsd  %xmm0,(%rsp)
lea    -0x1(%rbx),%esi
xor    %edi,%edi
mov    %rbp,%rdx
call   1040 <Mergesort@plt>
xor    %eax,%eax
call   1100 <tempo@plt>
subsd  (%rsp),%xmm0
call   1110 <abst@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1120 <num_buscas@plt>
cmp    $0x6d,%r12b
je     1357 <main+0x157>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   10b0 <vetor_copy@plt>
cmp    $0x74,%r12b
je     1320 <main+0x120>
cmp    $0x71,%r12b
je     1320 <main+0x120>
jmp    1357 <main+0x157>
lea    0xdc8(%rip),%rdi
call   1050 <puts@plt>
jmp    1528 <main+0x328>
lea    0xd3a(%rip),%rdi
jmp    151f <main+0x31f>
lea    0xd6f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Uso: %s tipo duracao\0A\00"
@.str.1 = [75 x i8] c" tipo: s(elecao) ou i(nsercao) ou m(ergesort) ou q(uicksort) ou t(odos)\0A\00"
@.str.2 = [33 x i8] c" duracao: duracao em segundos\0A\00"
@.str.3 = [18 x i8] c"opcao nao valida\0A\00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [523 x i8] c"|-------------------------[EP1 - Vale a pena ordenar?]--------------------|\0A| Algoritmo escolhido: %10s Duracao dos testes: %9.2f |\0A| Tempos de Ordenacao Numero de Buscas |\0A| Coloque seu nome aqui para identificacao! |\0A|-------------------------------------------------------------------------|\0A| n | Insercao Selecao Merge. Quick. | Insercao Selecao Merge. Quick. |\0A|-------|-----------------------------------------------------------------|\0A\00"
@.str.6 = [8 x i8] c"selecao\00"
@.str.7 = [9 x i8] c"insercao\00"
@.str.8 = [10 x i8] c"mergesort\00"
@.str.9 = [10 x i8] c"quicksort\00"
@.str.10 = [6 x i8] c"todos\00"
@.str.11 = [62 x i8] c"Erro na alocacao de memoria para o vetor v com %d elementos.\0A\00"
@.str.12 = [66 x i8] c"Erro na alocacao de memoria para o vetor v_aux com %d elementos.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = call i32 @time(i32* null)
%23 = call i32 @srand(i32 %22)
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 3
br i1 %25, label %26, label %33
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %254
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
store i8 %38, i8* %21
%39 = load i8, i8* %21
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 115
br i1 %41, label %42, label %60
42: ; preds = %33
%43 = load i8, i8* %21
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 105
br i1 %45, label %46, label %60
46: ; preds = %42
%47 = load i8, i8* %21
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 109
br i1 %49, label %50, label %60
50: ; preds = %46
%51 = load i8, i8* %21
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 113
br i1 %53, label %54, label %60
54: ; preds = %50
%55 = load i8, i8* %21
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %56, 116
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %254
60: ; preds = %54, %50, %46, %42, %33
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 2
%63 = load i8*, i8** %62
%64 = call i32 @sscanf(i8* %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %6)
%65 = load i8, i8* %21
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 115
br i1 %67, label %68, label %69
68: ; preds = %60
br label %89
69: ; preds = %60
%70 = load i8, i8* %21
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 105
br i1 %72, label %73, label %74
73: ; preds = %69
br label %87
74: ; preds = %69
%75 = load i8, i8* %21
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 109
br i1 %77, label %78, label %79
78: ; preds = %74
br label %85
79: ; preds = %74
%80 = load i8, i8* %21
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 113
%83 = zext i1 %82 to i64
%84 = select i1 %82, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0)
br label %85
85: ; preds = %79, %78
%86 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), %78 ], [ %84, %79 ]
br label %87
87: ; preds = %85, %73
%88 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), %73 ], [ %86, %85 ]
br label %89
89: ; preds = %87, %68
%90 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %68 ], [ %88, %87 ]
%91 = load double, double* %6
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([523 x i8], [523 x i8]* @.str.5, i64 0, i64 0), i8* %90, double %91)
%93 = call double (...) @tempo()
store double %93, double* %7
store double 0.000000e+00, double* %8
store i32 2000, i32* %14
br label %94
94: ; preds = %250, %89
%95 = load double, double* %8
%96 = load double, double* %6
%97 = fcmp olt double %95, %96
br i1 %97, label %98, label %253
98: ; preds = %94
%99 = load i32, i32* %14
%100 = sext i32 %99 to i64
%101 = mul i64 %100, 4
%102 = trunc i64 %101 to i32
%103 = call i32* @malloc(i32 %102)
store i32* %103, i32** %15
%104 = load i32*, i32** %15
%105 = icmp eq i32* %104, null
br i1 %105, label %106, label %109
106: ; preds = %98
%107 = load i32, i32* %14
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.11, i64 0, i64 0), i32 %107)
store i32 -1, i32* %3
br label %254
109: ; preds = %98
%110 = load i32, i32* %14
%111 = sext i32 %110 to i64
%112 = mul i64 %111, 4
%113 = trunc i64 %112 to i32
%114 = call i32* @malloc(i32 %113)
store i32* %114, i32** %16
%115 = load i32*, i32** %16
%116 = icmp eq i32* %115, null
br i1 %116, label %117, label %120
117: ; preds = %109
%118 = load i32, i32* %14
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.12, i64 0, i64 0), i32 %118)
store i32 -1, i32* %3
br label %254
120: ; preds = %109
%121 = load i32*, i32** %15
%122 = load i32, i32* %14
%123 = call i32 @vetor_rand(i32* %121, i32 %122)
%124 = load i32*, i32** %15
%125 = load i32*, i32** %16
%126 = load i32, i32* %14
%127 = call i32 @vetor_copy(i32* %124, i32* %125, i32 %126)
%128 = load i8, i8* %21
%129 = sext i8 %128 to i32
%130 = icmp eq i32 %129, 115
br i1 %130, label %135, label %131
131: ; preds = %120
%132 = load i8, i8* %21
%133 = sext i8 %132 to i32
%134 = icmp eq i32 %133, 116
br i1 %134, label %135, label %157
135: ; preds = %131, %120
%136 = call double (...) @tempo()
store double %136, double* %9
%137 = load i32, i32* %14
%138 = load i32*, i32** %16
%139 = call i32 @Selecao(i32 %137, i32* %138)
%140 = call double (...) @tempo()
%141 = load double, double* %9
%142 = fsub double %140, %141
store double %142, double* %10
%143 = load i32*, i32** %15
%144 = load i32*, i32** %16
%145 = load i32, i32* %14
%146 = load double, double* %10
%147 = call i32 @num_buscas(i32* %143, i32* %144, i32 %145, double %146)
store i32 %147, i32* %17
%148 = load i8, i8* %21
%149 = sext i8 %148 to i32
%150 = icmp ne i32 %149, 115
br i1 %150, label %151, label %156
151: ; preds = %135
%152 = load i32*, i32** %15
%153 = load i32*, i32** %16
%154 = load i32, i32* %14
%155 = call i32 @vetor_copy(i32* %152, i32* %153, i32 %154)
br label %156
156: ; preds = %151, %135
br label %157
157: ; preds = %156, %131
%158 = load i8, i8* %21
%159 = sext i8 %158 to i32
%160 = icmp eq i32 %159, 105
br i1 %160, label %165, label %161
161: ; preds = %157
%162 = load i8, i8* %21
%163 = sext i8 %162 to i32
%164 = icmp eq i32 %163, 116
br i1 %164, label %165, label %187
165: ; preds = %161, %157
%166 = call double (...) @tempo()
store double %166, double* %9
%167 = load i32, i32* %14
%168 = load i32*, i32** %16
%169 = call i32 @Insercao(i32 %167, i32* %168)
%170 = call double (...) @tempo()
%171 = load double, double* %9
%172 = fsub double %170, %171
store double %172, double* %11
%173 = load i32*, i32** %15
%174 = load i32*, i32** %16
%175 = load i32, i32* %14
%176 = load double, double* %11
%177 = call i32 @num_buscas(i32* %173, i32* %174, i32 %175, double %176)
store i32 %177, i32* %18
%178 = load i8, i8* %21
%179 = sext i8 %178 to i32
%180 = icmp ne i32 %179, 105
br i1 %180, label %181, label %186
181: ; preds = %165
%182 = load i32*, i32** %15
%183 = load i32*, i32** %16
%184 = load i32, i32* %14
%185 = call i32 @vetor_copy(i32* %182, i32* %183, i32 %184)
br label %186
186: ; preds = %181, %165
br label %187
187: ; preds = %186, %161
%188 = load i8, i8* %21
%189 = sext i8 %188 to i32
%190 = icmp eq i32 %189, 109
br i1 %190, label %195, label %191
191: ; preds = %187
%192 = load i8, i8* %21
%193 = sext i8 %192 to i32
%194 = icmp eq i32 %193, 116
br i1 %194, label %195, label %219
195: ; preds = %191, %187
%196 = call double (...) @tempo()
store double %196, double* %9
%197 = load i32, i32* %14
%198 = sub nsw i32 %197, 1
%199 = load i32*, i32** %16
%200 = call i32 @Mergesort(i32 0, i32 %198, i32* %199)
%201 = call double (...) @tempo()
%202 = load double, double* %9
%203 = fsub double %201, %202
%204 = call double @abst(double %203)
store double %204, double* %12
%205 = load i32*, i32** %15
%206 = load i32*, i32** %16
%207 = load i32, i32* %14
%208 = load double, double* %12
%209 = call i32 @num_buscas(i32* %205, i32* %206, i32 %207, double %208)
store i32 %209, i32* %19
%210 = load i8, i8* %21
%211 = sext i8 %210 to i32
%212 = icmp ne i32 %211, 109
br i1 %212, label %213, label %218
213: ; preds = %195
%214 = load i32*, i32** %15
%215 = load i32*, i32** %16
%216 = load i32, i32* %14
%217 = call i32 @vetor_copy(i32* %214, i32* %215, i32 %216)
br label %218
218: ; preds = %213, %195
br label %219
219: ; preds = %218, %191
%220 = load i8, i8* %21
%221 = sext i8 %220 to i32
%222 = icmp eq i32 %221, 113
br i1 %222, label %227, label %223
223: ; preds = %219
%224 = load i8, i8* %21
%225 = sext i8 %224 to i32
%226 = icmp eq i32 %225, 116
br i1 %226, label %227, label %242
227: ; preds = %223, %219
%228 = call double (...) @tempo()
store double %228, double* %9
%229 = load i32, i32* %14
%230 = sub nsw i32 %229, 1
%231 = load i32*, i32** %16
%232 = call i32 @Quicksort(i32 0, i32 %230, i32* %231)
%233 = call double (...) @tempo()
%234 = load double, double* %9
%235 = fsub double %233, %234
%236 = call double @abst(double %235)
store double %236, double* %13
%237 = load i32*, i32** %15
%238 = load i32*, i32** %16
%239 = load i32, i32* %14
%240 = load double, double* %13
%241 = call i32 @num_buscas(i32* %237, i32* %238, i32 %239, double %240)
store i32 %241, i32* %20
br label %242
242: ; preds = %227, %223
%243 = load i32*, i32** %15
%244 = call i32 @free(i32* %243)
%245 = load i32*, i32** %16
%246 = call i32 @free(i32* %245)
%247 = call double (...) @tempo()
%248 = load double, double* %7
%249 = fsub double %247, %248
store double %249, double* %8
br label %250
250: ; preds = %242
%251 = load i32, i32* %14
%252 = add nsw i32 %251, 2000
store i32 %252, i32* %14
br label %94
253: ; preds = %94
store i32 0, i32* %3
br label %254
254: ; preds = %253, %117, %106, %58, %26
%255 = load i32, i32* %3
ret i32 %255
}

LLVM IR (-O2):
@.str = [22 x i8] c"Uso: %s tipo duracao\0A\00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [523 x i8] c"|-------------------------[EP1 - Vale a pena ordenar?]--------------------|\0A| Algoritmo escolhido: %10s Duracao dos testes: %9.2f |\0A| Tempos de Ordenacao Numero de Buscas |\0A| Coloque seu nome aqui para identificacao! |\0A|-------------------------------------------------------------------------|\0A| n | Insercao Selecao Merge. Quick. | Insercao Selecao Merge. Quick. |\0A|-------|-----------------------------------------------------------------|\0A\00"
@.str.6 = [8 x i8] c"selecao\00"
@.str.7 = [9 x i8] c"insercao\00"
@.str.8 = [10 x i8] c"mergesort\00"
@.str.9 = [10 x i8] c"quicksort\00"
@.str.10 = [6 x i8] c"todos\00"
@.str.11 = [62 x i8] c"Erro na alocacao de memoria para o vetor v com %d elementos.\0A\00"
@.str.12 = [66 x i8] c"Erro na alocacao de memoria para o vetor v_aux com %d elementos.\0A\00"
@str = [17 x i8] c"opcao nao valida\00"
@str.13 = [74 x i8] c" tipo: s(elecao) ou i(nsercao) ou m(ergesort) ou q(uicksort) ou t(odos)\00"
@str.14 = [32 x i8] c" duracao: duracao em segundos\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = icmp eq i32 %0, 3
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str.13, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.14, i64 0, i64 0))
br label %99
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
switch i8 %16, label %17 [
i8 116, label %19
i8 115, label %19
i8 113, label %19
i8 109, label %19
i8 105, label %19
]
17: ; preds = %13
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %99
19: ; preds = %13, %13, %13, %13, %13
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %3)
switch i8 %16, label %23 [
i8 115, label %28
i8 105, label %26
i8 109, label %27
]
23: ; preds = %19
%24 = icmp eq i8 %16, 113
%25 = select i1 %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0)
br label %28
26: ; preds = %19
br label %28
27: ; preds = %19
br label %28
28: ; preds = %19, %27, %26, %23
%29 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %19 ], [ %25, %23 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), %26 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), %27 ]
%30 = load double, double* %3
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([523 x i8], [523 x i8]* @.str.5, i64 0, i64 0), i8* %29, double %30)
%32 = call double (...) @tempo()
%33 = load double, double* %3
%34 = fcmp ogt double %33, 0.000000e+00
br i1 %34, label %35, label %99
35: ; preds = %28
%36 = add nsw i8 %16, -115
%37 = icmp ult i8 %36, 2
%38 = icmp eq i8 %16, 115
%39 = icmp eq i8 %16, 105
%40 = icmp eq i8 %16, 109
br label %41
41: ; preds = %35, %91
%42 = phi i32 [ 2000, %35 ], [ %96, %91 ]
%43 = shl i32 %42, 2
%44 = call i32* @malloc(i32 %43)
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.11, i64 0, i64 0), i32 %42)
br label %99
48: ; preds = %41
%49 = call i32* @malloc(i32 %43)
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.12, i64 0, i64 0), i32 %42)
br label %99
53: ; preds = %48
%54 = call i32 @vetor_rand(i32* %44, i32 %42)
%55 = call i32 @vetor_copy(i32* %44, i32* %49, i32 %42)
br i1 %37, label %56, label %64
56: ; preds = %53
%57 = call double (...) @tempo()
%58 = call i32 @Selecao(i32 %42, i32* %49)
%59 = call double (...) @tempo()
%60 = fsub double %59, %57
%61 = call i32 @num_buscas(i32* %44, i32* %49, i32 %42, double %60)
br i1 %38, label %91, label %62
62: ; preds = %56
%63 = call i32 @vetor_copy(i32* %44, i32* %49, i32 %42)
br label %65
64: ; preds = %53
switch i8 %16, label %91 [
i8 113, label %83
i8 105, label %65
i8 109, label %73
]
65: ; preds = %62, %64
%66 = call double (...) @tempo()
%67 = call i32 @Insercao(i32 %42, i32* %49)
%68 = call double (...) @tempo()
%69 = fsub double %68, %66
%70 = call i32 @num_buscas(i32* %44, i32* %49, i32 %42, double %69)
br i1 %39, label %91, label %71
71: ; preds = %65
%72 = call i32 @vetor_copy(i32* %44, i32* %49, i32 %42)
switch i8 %16, label %91 [
i8 116, label %73
i8 109, label %73
i8 113, label %83
]
73: ; preds = %64, %71, %71
%74 = call double (...) @tempo()
%75 = add nsw i32 %42, -1
%76 = call i32 @Mergesort(i32 0, i32 %75, i32* %49)
%77 = call double (...) @tempo()
%78 = fsub double %77, %74
%79 = call double @abst(double %78)
%80 = call i32 @num_buscas(i32* %44, i32* %49, i32 %42, double %79)
br i1 %40, label %91, label %81
81: ; preds = %73
%82 = call i32 @vetor_copy(i32* %44, i32* %49, i32 %42)
switch i8 %16, label %91 [
i8 116, label %83
i8 113, label %83
]
83: ; preds = %64, %71, %81, %81
%84 = call double (...) @tempo()
%85 = add nsw i32 %42, -1
%86 = call i32 @Quicksort(i32 0, i32 %85, i32* %49)
%87 = call double (...) @tempo()
%88 = fsub double %87, %84
%89 = call double @abst(double %88)
%90 = call i32 @num_buscas(i32* %44, i32* %49, i32 %42, double %89)
br label %91
91: ; preds = %73, %65, %56, %64, %71, %81, %83
%92 = call i32 @free(i32* %44)
%93 = call i32 @free(i32* %49)
%94 = call double (...) @tempo()
%95 = fsub double %94, %32
%96 = add nuw nsw i32 %42, 2000
%97 = load double, double* %3
%98 = fcmp olt double %95, %97
br i1 %98, label %41, label %99
99: ; preds = %91, %28, %51, %46, %17, %8
%100 = phi i32 [ 0, %8 ], [ -1, %17 ], [ -1, %46 ], [ -1, %51 ], [ 0, %28 ], [ 0, %91 ]
ret i32 %100
}