#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*/ benchmark_bubble_sort(int *, int);
int /*<<< orphan*/ benchmark_cocktail_sort(int *, int);
int /*<<< orphan*/ benchmark_comb_sort(int *, int);
int /*<<< orphan*/ benchmark_gnome_sort(int *, int);
int /*<<< orphan*/ benchmark_quick_sort(int *, int);
int /*<<< orphan*/ benchmark_selection_sort(int *, int);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ printf(char *, ...);
int rand();
int main() {
  int vetor_original[50000], i;
  for (i = 0; i < 50000; i++)
    vetor_original[i] = rand() % 100000;
  printf("/*** BENCHMARK METODOS DE ORDENACAO ***\\\n");
  printf("Testando com vetor com %d itens.\n\n", 50000);
  printf("SELECTION SORT\n");
  benchmark_selection_sort(vetor_original, 50000);
  printf("BUBBLE SORT\n");
  benchmark_bubble_sort(vetor_original, 50000);
  printf("QUICK SORT\n");
  benchmark_quick_sort(vetor_original, 50000);
  printf("GNOME SORT\n");
  benchmark_gnome_sort(vetor_original, 50000);
  printf("COCKTAIL SORT\n");
  benchmark_cocktail_sort(vetor_original, 50000);
  printf("COMB SORT\n");
  benchmark_comb_sort(vetor_original, 50000);
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x30d54(%rbp)
cmpl   $0xc350,-0x30d54(%rbp)
jge    11ed <main+0x5d>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x186a0,%ecx
cltd
idiv   %ecx
movslq -0x30d54(%rbp),%rax
mov    %edx,-0x30d50(%rbp,%rax,4)
mov    -0x30d54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30d54(%rbp)
jmp    11ac <main+0x1c>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
mov    $0xc350,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30d50(%rbp),%rdi
mov    $0xc350,%esi
call   1080 <benchmark_selection_sort@plt>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30d50(%rbp),%rdi
mov    $0xc350,%esi
call   1090 <benchmark_bubble_sort@plt>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30d50(%rbp),%rdi
mov    $0xc350,%esi
call   1030 <benchmark_quick_sort@plt>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30d50(%rbp),%rdi
mov    $0xc350,%esi
call   1070 <benchmark_gnome_sort@plt>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30d50(%rbp),%rdi
mov    $0xc350,%esi
call   10b0 <benchmark_cocktail_sort@plt>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30d50(%rbp),%rdi
mov    $0xc350,%esi
call   1040 <benchmark_comb_sort@plt>
mov    $0x0,%al
call   1060 <getch@plt>
xor    %eax,%eax
add    $0x30d60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30d40,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <rand@plt>
cltq
imul   $0x14f8b589,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2d,%rcx
add    %edx,%ecx
imul   $0x186a0,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0xc350,%rbx
jne    11b0 <main+0x10>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
lea    0xe08(%rip),%rdi
mov    $0xc350,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc350,%esi
call   1090 <benchmark_selection_sort@plt>
lea    0xe34(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xc350,%esi
call   10a0 <benchmark_bubble_sort@plt>
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xc350,%esi
call   1030 <benchmark_quick_sort@plt>
lea    0xe19(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xc350,%esi
call   1080 <benchmark_gnome_sort@plt>
lea    0xe0b(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xc350,%esi
call   10c0 <benchmark_cocktail_sort@plt>
lea    0xe00(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xc350,%esi
call   1050 <benchmark_comb_sort@plt>
xor    %eax,%eax
call   1070 <getch@plt>
xor    %eax,%eax
add    $0x30d40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"/*** BENCHMARK METODOS DE ORDENACAO ***\\\0A\00"
@.str.1 = [35 x i8] c"Testando com vetor com %d itens.\0A\0A\00"
@.str.2 = [16 x i8] c"SELECTION SORT\0A\00"
@.str.3 = [13 x i8] c"BUBBLE SORT\0A\00"
@.str.4 = [12 x i8] c"QUICK SORT\0A\00"
@.str.5 = [12 x i8] c"GNOME SORT\0A\00"
@.str.6 = [15 x i8] c"COCKTAIL SORT\0A\00"
@.str.7 = [11 x i8] c"COMB SORT\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50000 x i32]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %13, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 50000
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 100000
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 %11
store i32 %9, i32* %12
br label %13
13: ; preds = %7
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %4
16: ; preds = %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 50000)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 0
%21 = call i32 @benchmark_selection_sort(i32* %20, i32 50000)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%23 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 0
%24 = call i32 @benchmark_bubble_sort(i32* %23, i32 50000)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%26 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 0
%27 = call i32 @benchmark_quick_sort(i32* %26, i32 50000)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%29 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 0
%30 = call i32 @benchmark_gnome_sort(i32* %29, i32 50000)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%32 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 0
%33 = call i32 @benchmark_cocktail_sort(i32* %32, i32 50000)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%35 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 0
%36 = call i32 @benchmark_comb_sort(i32* %35, i32 50000)
%37 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [35 x i8] c"Testando com vetor com %d itens.\0A\0A\00"
@str = [41 x i8] c"/*** BENCHMARK METODOS DE ORDENACAO ***\\\00"
@str.8 = [15 x i8] c"SELECTION SORT\00"
@str.9 = [12 x i8] c"BUBBLE SORT\00"
@str.10 = [11 x i8] c"QUICK SORT\00"
@str.11 = [11 x i8] c"GNOME SORT\00"
@str.12 = [14 x i8] c"COCKTAIL SORT\00"
@str.13 = [10 x i8] c"COMB SORT\00"
define i32 @main() {
%1 = alloca [50000 x i32]
%2 = bitcast [50000 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %8, %3 ]
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 100000
%7 = getelementptr inbounds [50000 x i32], [50000 x i32]* %1, i64 0, i64 %4
store i32 %6, i32* %7
%8 = add nuw nsw i64 %4, 1
%9 = icmp eq i64 %8, 50000
br i1 %9, label %10, label %3
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 50000)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
%14 = getelementptr inbounds [50000 x i32], [50000 x i32]* %1, i64 0, i64 0
%15 = call i32 @benchmark_selection_sort(i32* %14, i32 50000)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
%17 = call i32 @benchmark_bubble_sort(i32* %14, i32 50000)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.10, i64 0, i64 0))
%19 = call i32 @benchmark_quick_sort(i32* %14, i32 50000)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.11, i64 0, i64 0))
%21 = call i32 @benchmark_gnome_sort(i32* %14, i32 50000)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.12, i64 0, i64 0))
%23 = call i32 @benchmark_cocktail_sort(i32* %14, i32 50000)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.13, i64 0, i64 0))
%25 = call i32 @benchmark_comb_sort(i32* %14, i32 50000)
%26 = call i32 (...) @getch()
ret i32 0
}