#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*/ burbuja(int *, unsigned int, unsigned int *, unsigned int *);
int /*<<< orphan*/ burbujaMejorada(int *, unsigned int, unsigned int *,
                                   unsigned int *);
int /*<<< orphan*/ copiar(int *, int *, unsigned int);
int /*<<< orphan*/ llenarRandom(int *, unsigned int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int /*<<< orphan*/ seleccionMinimo(int *, unsigned int, unsigned int *,
                                   unsigned int *);
int /*<<< orphan*/ ver(int *, unsigned int);
void main() {
  unsigned int tope, comparaciones, intercambios;
  printf("Ingrese el nro entero de elementos del vector para crearlos "
         "aleatoriamente.\nn=");
  scanf("%d", &tope);
  int *vector = malloc(sizeof(int) * tope);
  int *auxiliar = malloc(sizeof(int) * tope);
  llenarRandom(vector, tope);
  copiar(vector, auxiliar, tope);
  printf("Vector Original:\n");
  ver(vector, tope);
  seleccionMinimo(auxiliar, tope, &comparaciones, &intercambios);
  printf("\nOrdenado mediante Selection Sort (minimo) en %d comparaciones y %d "
         "intercambios\n",
         comparaciones, intercambios);
  ver(auxiliar, tope);
  copiar(vector, auxiliar, tope);
  burbuja(auxiliar, tope, &comparaciones, &intercambios);
  printf("\nOrdenado mediante Burbujeo en %d comparaciones y %d intercambios\n",
         comparaciones, intercambios);
  ver(auxiliar, tope);
  copiar(vector, auxiliar, tope);
  burbujaMejorada(auxiliar, tope, &comparaciones, &intercambios);
  printf("\nOrdenado mediante Burbujeo Mejorado en %d comparaciones y %d "
         "intercambios\n",
         comparaciones, intercambios);
  ver(auxiliar, tope);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x4(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1030 <llenarRandom@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1080 <copiar@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   10a0 <ver@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%esi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   1040 <seleccionMinimo@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   10a0 <ver@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1080 <copiar@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%esi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   10b0 <burbuja@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   10a0 <ver@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1080 <copiar@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%esi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   1060 <burbujaMejorada@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   10a0 <ver@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe8f(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0xc(%rsp),%r15d
lea    0x0(,%r15,4),%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <llenarRandom@plt>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <copiar@plt>
lea    0xf27(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   10b0 <ver@plt>
mov    0xc(%rsp),%esi
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
call   1050 <seleccionMinimo@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
lea    0xe0a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   10b0 <ver@plt>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <copiar@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
call   10c0 <burbuja@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   10b0 <ver@plt>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <copiar@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
call   1070 <burbujaMejorada@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   10b0 <ver@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [79 x i8] c"Ingrese el nro entero de elementos del vector para crearlos aleatoriamente.\0An=\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"Vector Original:\0A\00"
@.str.3 = [82 x i8] c"\0AOrdenado mediante Selection Sort (minimo) en %d comparaciones y %d intercambios\0A\00"
@.str.4 = [67 x i8] c"\0AOrdenado mediante Burbujeo en %d comparaciones y %d intercambios\0A\00"
@.str.5 = [76 x i8] c"\0AOrdenado mediante Burbujeo Mejorado en %d comparaciones y %d intercambios\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = zext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i32* @malloc(i32 %11)
store i32* %12, i32** %4
%13 = load i32, i32* %1
%14 = zext i32 %13 to i64
%15 = mul i64 4, %14
%16 = trunc i64 %15 to i32
%17 = call i32* @malloc(i32 %16)
store i32* %17, i32** %5
%18 = load i32*, i32** %4
%19 = load i32, i32* %1
%20 = call i32 @llenarRandom(i32* %18, i32 %19)
%21 = load i32*, i32** %4
%22 = load i32*, i32** %5
%23 = load i32, i32* %1
%24 = call i32 @copiar(i32* %21, i32* %22, i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32*, i32** %4
%27 = load i32, i32* %1
%28 = call i32 @ver(i32* %26, i32 %27)
%29 = load i32*, i32** %5
%30 = load i32, i32* %1
%31 = call i32 @seleccionMinimo(i32* %29, i32 %30, i32* %2, i32* %3)
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33)
%35 = load i32*, i32** %5
%36 = load i32, i32* %1
%37 = call i32 @ver(i32* %35, i32 %36)
%38 = load i32*, i32** %4
%39 = load i32*, i32** %5
%40 = load i32, i32* %1
%41 = call i32 @copiar(i32* %38, i32* %39, i32 %40)
%42 = load i32*, i32** %5
%43 = load i32, i32* %1
%44 = call i32 @burbuja(i32* %42, i32 %43, i32* %2, i32* %3)
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), i32 %45, i32 %46)
%48 = load i32*, i32** %5
%49 = load i32, i32* %1
%50 = call i32 @ver(i32* %48, i32 %49)
%51 = load i32*, i32** %4
%52 = load i32*, i32** %5
%53 = load i32, i32* %1
%54 = call i32 @copiar(i32* %51, i32* %52, i32 %53)
%55 = load i32*, i32** %5
%56 = load i32, i32* %1
%57 = call i32 @burbujaMejorada(i32* %55, i32 %56, i32* %2, i32* %3)
%58 = load i32, i32* %2
%59 = load i32, i32* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.5, i64 0, i64 0), i32 %58, i32 %59)
%61 = load i32*, i32** %5
%62 = load i32, i32* %1
%63 = call i32 @ver(i32* %61, i32 %62)
ret void
}

LLVM IR (-O2):
@.str = [79 x i8] c"Ingrese el nro entero de elementos del vector para crearlos aleatoriamente.\0An=\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [82 x i8] c"\0AOrdenado mediante Selection Sort (minimo) en %d comparaciones y %d intercambios\0A\00"
@.str.4 = [67 x i8] c"\0AOrdenado mediante Burbujeo en %d comparaciones y %d intercambios\0A\00"
@.str.5 = [76 x i8] c"\0AOrdenado mediante Burbujeo Mejorado en %d comparaciones y %d intercambios\0A\00"
@str = [17 x i8] c"Vector Original:\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = shl i32 %9, 2
%11 = call i32* @malloc(i32 %10)
%12 = call i32* @malloc(i32 %10)
%13 = call i32 @llenarRandom(i32* %11, i32 %9)
%14 = load i32, i32* %1
%15 = call i32 @copiar(i32* %11, i32* %12, i32 %14)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%17 = load i32, i32* %1
%18 = call i32 @ver(i32* %11, i32 %17)
%19 = load i32, i32* %1
%20 = call i32 @seleccionMinimo(i32* %12, i32 %19, i32* %2, i32* %3)
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %1
%25 = call i32 @ver(i32* %12, i32 %24)
%26 = load i32, i32* %1
%27 = call i32 @copiar(i32* %11, i32* %12, i32 %26)
%28 = load i32, i32* %1
%29 = call i32 @burbuja(i32* %12, i32 %28, i32* %2, i32* %3)
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %31)
%33 = load i32, i32* %1
%34 = call i32 @ver(i32* %12, i32 %33)
%35 = load i32, i32* %1
%36 = call i32 @copiar(i32* %11, i32* %12, i32 %35)
%37 = load i32, i32* %1
%38 = call i32 @burbujaMejorada(i32* %12, i32 %37, i32* %2, i32* %3)
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @.str.5, i64 0, i64 0), i32 %39, i32 %40)
%42 = load i32, i32* %1
%43 = call i32 @ver(i32* %12, i32 %42)
ret void
}