#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*/ gera(int *, int);
int /*<<< orphan*/ gera_vetor_crescente(int *, int);
int /*<<< orphan*/ gera_vetor_decrescente(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, float, ...);
int /*<<< orphan*/ selection(int *, int, float *, float *);
int main() {
  int *vetor_aleatorio;
  int *vetor_asc;
  int *vetor_desc;
  vetor_aleatorio = (int *)malloc(100000 * sizeof(int));
  vetor_asc = (int *)malloc(100000 * sizeof(int));
  vetor_desc = (int *)malloc(100000 * sizeof(int));
  float contador_comparacao = 0;
  float contador_atribuicao = 0;
  int i;
  for (i = 0; i < 10; i++) {
    printf("\nGerando os vetores, %d loop Selection...\n", i + 1);
    gera(vetor_aleatorio, 100000);
    gera_vetor_crescente(vetor_asc, 100000);
    gera_vetor_decrescente(vetor_desc, 100000);
    selection(vetor_aleatorio, 100000, &contador_comparacao,
              &contador_atribuicao);
    printf(
        "\nVetor aleatorio: Contador comparacao %.f Contador atribuicao %.f \n",
        contador_comparacao, contador_atribuicao);
    contador_comparacao = 0;
    contador_atribuicao = 0;
    selection(vetor_asc, 100000, &contador_comparacao, &contador_atribuicao);
    printf(
        "Vetor crescente: Contador comparacao %.f Contador atribuicao %.f \n",
        contador_comparacao, contador_atribuicao);
    contador_comparacao = 0;
    contador_atribuicao = 0;
    selection(vetor_desc, 100000, &contador_comparacao, &contador_atribuicao);
    printf(
        "Vetor decrescente: Contador comparacao %.f Contador atribuicao %.f \n",
        contador_comparacao, contador_atribuicao);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x61a80,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x61a80,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x61a80,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    12c0 <main+0x160>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
lea    0xe35(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x186a0,%esi
call   1080 <gera@plt>
mov    -0x18(%rbp),%rdi
mov    $0x186a0,%esi
call   1070 <gera_vetor_crescente@plt>
mov    -0x20(%rbp),%rdi
mov    $0x186a0,%esi
call   1040 <gera_vetor_decrescente@plt>
mov    -0x10(%rbp),%rdi
mov    $0x186a0,%esi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <selection@plt>
movss  -0x24(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe04(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x186a0,%esi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <selection@plt>
movss  -0x24(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe06(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x186a0,%esi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <selection@plt>
movss  -0x24(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe07(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b0 <main+0x50>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x61a80,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x61a80,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x61a80,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    $0x1,%r12d
lea    0x4(%rsp),%r13
mov    %rsp,%rbp
nop
xorps  %xmm0,%xmm0
cvtsi2ss %r12d,%xmm0
lea    0xe41(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x186a0,%esi
call   1080 <gera@plt>
mov    %r15,%rdi
mov    $0x186a0,%esi
call   1070 <gera_vetor_crescente@plt>
mov    %rbx,%rdi
mov    $0x186a0,%esi
call   1040 <gera_vetor_decrescente@plt>
mov    %r14,%rdi
mov    $0x186a0,%esi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1030 <selection@plt>
movss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe15(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    %r15,%rdi
mov    $0x186a0,%esi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1030 <selection@plt>
movss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe1a(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    %rbx,%rdi
mov    $0x186a0,%esi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1030 <selection@plt>
movss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe1e(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
add    $0x1,%r12d
cmp    $0xb,%r12d
jne    11b0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"\0AGerando os vetores, %d loop Selection...\0A\00"
@.str.1 = [68 x i8] c"\0AVetor aleatorio: Contador comparacao %.f Contador atribuicao %.f \0A\00"
@.str.2 = [67 x i8] c"Vetor crescente: Contador comparacao %.f Contador atribuicao %.f \0A\00"
@.str.3 = [69 x i8] c"Vetor decrescente: Contador comparacao %.f Contador atribuicao %.f \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca float
%6 = alloca float
%7 = alloca i32
store i32 0, i32* %1
%8 = call i64 @malloc(i32 400000)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %2
%10 = call i64 @malloc(i32 400000)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %3
%12 = call i64 @malloc(i32 400000)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %4
store float 0.000000e+00, float* %5
store float 0.000000e+00, float* %6
store i32 0, i32* %7
br label %14
14: ; preds = %46, %0
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 10
br i1 %16, label %17, label %49
17: ; preds = %14
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
%20 = sitofp i32 %19 to float
%21 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), float %20)
%22 = load i32*, i32** %2
%23 = call i32 @gera(i32* %22, i32 100000)
%24 = load i32*, i32** %3
%25 = call i32 @gera_vetor_crescente(i32* %24, i32 100000)
%26 = load i32*, i32** %4
%27 = call i32 @gera_vetor_decrescente(i32* %26, i32 100000)
%28 = load i32*, i32** %2
%29 = call i32 @selection(i32* %28, i32 100000, float* %5, float* %6)
%30 = load float, float* %5
%31 = load float, float* %6
%32 = fpext float %31 to double
%33 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), float %30, double %32)
store float 0.000000e+00, float* %5
store float 0.000000e+00, float* %6
%34 = load i32*, i32** %3
%35 = call i32 @selection(i32* %34, i32 100000, float* %5, float* %6)
%36 = load float, float* %5
%37 = load float, float* %6
%38 = fpext float %37 to double
%39 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0), float %36, double %38)
store float 0.000000e+00, float* %5
store float 0.000000e+00, float* %6
%40 = load i32*, i32** %4
%41 = call i32 @selection(i32* %40, i32 100000, float* %5, float* %6)
%42 = load float, float* %5
%43 = load float, float* %6
%44 = fpext float %43 to double
%45 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0), float %42, double %44)
br label %46
46: ; preds = %17
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %14
49: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"\0AGerando os vetores, %d loop Selection...\0A\00"
@.str.1 = [68 x i8] c"\0AVetor aleatorio: Contador comparacao %.f Contador atribuicao %.f \0A\00"
@.str.2 = [67 x i8] c"Vetor crescente: Contador comparacao %.f Contador atribuicao %.f \0A\00"
@.str.3 = [69 x i8] c"Vetor decrescente: Contador comparacao %.f Contador atribuicao %.f \0A\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = tail call i64 @malloc(i32 400000)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i64 @malloc(i32 400000)
%6 = inttoptr i64 %5 to i32*
%7 = tail call i64 @malloc(i32 400000)
%8 = inttoptr i64 %7 to i32*
%9 = bitcast float* %1 to i8*
store float 0.000000e+00, float* %1
%10 = bitcast float* %2 to i8*
store float 0.000000e+00, float* %2
br label %11
11: ; preds = %0, %11
%12 = phi i32 [ 0, %0 ], [ %13, %11 ]
%13 = add nuw nsw i32 %12, 1
%14 = sitofp i32 %13 to float
%15 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), float %14)
%16 = call i32 @gera(i32* %4, i32 100000)
%17 = call i32 @gera_vetor_crescente(i32* %6, i32 100000)
%18 = call i32 @gera_vetor_decrescente(i32* %8, i32 100000)
%19 = call i32 @selection(i32* %4, i32 100000, float* %1, float* %2)
%20 = load float, float* %1
%21 = load float, float* %2
%22 = fpext float %21 to double
%23 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), float %20, double %22)
store float 0.000000e+00, float* %1
store float 0.000000e+00, float* %2
%24 = call i32 @selection(i32* %6, i32 100000, float* %1, float* %2)
%25 = load float, float* %1
%26 = load float, float* %2
%27 = fpext float %26 to double
%28 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0), float %25, double %27)
store float 0.000000e+00, float* %1
store float 0.000000e+00, float* %2
%29 = call i32 @selection(i32* %8, i32 100000, float* %1, float* %2)
%30 = load float, float* %1
%31 = load float, float* %2
%32 = fpext float %31 to double
%33 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0), float %30, double %32)
%34 = icmp eq i32 %13, 10
br i1 %34, label %35, label %11
35: ; preds = %11
ret i32 0
}