#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 scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ mostrarArreglo(int *, int);
int /*<<< orphan*/ printf(char *, ...);
void burbujaM(int *ar, int cantidad) {
  int aux, i, j;
  unsigned long comparaciones = 0;
  clock_t inicio = clock();
  for (i = 0; i < cantidad; i++) {
    for (j = i + 1; j < cantidad; j++) {
      if (ar[i] > ar[j]) {
        aux = ar[i];
        ar[i] = ar[j];
        ar[j] = aux;
      }
      comparaciones++;
    }
  }
  clock_t fin = clock();
  mostrarArreglo(ar, cantidad);
  printf("\n\nMETODO BURBUJA MEJORADA");
  printf("\n\nEl tiempo que tardo la ordenacion fue de %Lf milisegundos\n",
         ((double)(fin - inicio)) / CLOCKS_PER_SEC * 1000);
  printf("El numero de comparaciones fue %lu", comparaciones);
}


x86 assembly (clang, -O0):
<burbujaM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f5 <burbujaM+0xc5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e2 <burbujaM+0xb2>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11c8 <burbujaM+0x98>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116e <burbujaM+0x3e>
jmp    11e7 <burbujaM+0xb7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <burbujaM+0x29>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <mostrarArreglo@plt>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dba(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xdc6(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xddd(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<burbujaM>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbp
xor    %r13d,%r13d
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    11ad <burbujaM+0x7d>
mov    %r15d,%r8d
lea    0x4(%rbp),%rcx
lea    -0x1(%r8),%rdx
xor    %r9d,%r9d
xor    %r13d,%r13d
jmp    1180 <burbujaM+0x50>
cs nopw 0x0(%rax,%rax,1)
add    %rbx,%r13
add    $0x4,%rcx
add    $0xffffffffffffffff,%rdx
cmp    %r8,%r9
je     11ad <burbujaM+0x7d>
mov    %r9,%rdi
add    $0x1,%r9
cmp    %r8,%r9
jae    1173 <burbujaM+0x43>
xor    %ebx,%ebx
jmp    1199 <burbujaM+0x69>
add    $0x1,%rbx
cmp    %rbx,%rdx
je     1170 <burbujaM+0x40>
mov    0x0(%rbp,%rdi,4),%eax
mov    (%rcx,%rbx,4),%esi
cmp    %esi,%eax
jle    1190 <burbujaM+0x60>
mov    %esi,0x0(%rbp,%rdi,4)
mov    %eax,(%rcx,%rbx,4)
jmp    1190 <burbujaM+0x60>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %r15d,%esi
call   1030 <mostrarArreglo@plt>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
sub    %r14,%r12
cvtsi2sd %r12,%xmm0
mov    0x2e09(%rip),%rax
divsd  (%rax),%xmm0
mulsd  0xe15(%rip),%xmm0
lea    0xe30(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe5f(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"\0A\0AMETODO BURBUJA MEJORADA\00"
@.str.1 = [61 x i8] c"\0A\0AEl tiempo que tardo la ordenacion fue de %Lf milisegundos\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [35 x i8] c"El numero de comparaciones fue %lu\00"
define void @burbujaM(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32* %0, i32** %3
store i32 %1, i32* %4
store i64 0, i64* %8
%11 = call i64 (...) @clock()
store i64 %11, i64* %9
store i32 0, i32* %6
br label %12
12: ; preds = %62, %2
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %65
16: ; preds = %12
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %7
br label %19
19: ; preds = %58, %16
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %61
23: ; preds = %19
%24 = load i32*, i32** %3
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = load i32*, i32** %3
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = icmp sgt i32 %28, %33
br i1 %34, label %35, label %55
35: ; preds = %23
%36 = load i32*, i32** %3
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
store i32 %40, i32* %5
%41 = load i32*, i32** %3
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = load i32*, i32** %3
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
%50 = load i32, i32* %5
%51 = load i32*, i32** %3
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 %50, i32* %54
br label %55
55: ; preds = %35, %23
%56 = load i64, i64* %8
%57 = add i64 %56, 1
store i64 %57, i64* %8
br label %58
58: ; preds = %55
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %19
61: ; preds = %19
br label %62
62: ; preds = %61
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %12
65: ; preds = %12
%66 = call i64 (...) @clock()
store i64 %66, i64* %10
%67 = load i32*, i32** %3
%68 = load i32, i32* %4
%69 = call i32 @mostrarArreglo(i32* %67, i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%71 = load i64, i64* %10
%72 = load i64, i64* %9
%73 = sub nsw i64 %71, %72
%74 = sitofp i64 %73 to double
%75 = load double, double* @CLOCKS_PER_SEC
%76 = fdiv double %74, %75
%77 = fmul double %76, 1.000000e+03
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), double %77)
%79 = load i64, i64* %8
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i64 %79)
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"\0A\0AMETODO BURBUJA MEJORADA\00"
@.str.1 = [61 x i8] c"\0A\0AEl tiempo que tardo la ordenacion fue de %Lf milisegundos\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [35 x i8] c"El numero de comparaciones fue %lu\00"
define void @burbujaM(i32* %0, i32 %1) {
%3 = tail call i64 (...) @clock()
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %32
5: ; preds = %2
%6 = zext i32 %1 to i64
%7 = zext i32 %1 to i64
br label %12
8: ; preds = %28, %12
%9 = phi i64 [ %15, %12 ], [ %29, %28 ]
%10 = add nuw nsw i64 %14, 1
%11 = icmp eq i64 %16, %7
br i1 %11, label %32, label %12
12: ; preds = %5, %8
%13 = phi i64 [ 0, %5 ], [ %16, %8 ]
%14 = phi i64 [ 1, %5 ], [ %10, %8 ]
%15 = phi i64 [ 0, %5 ], [ %9, %8 ]
%16 = add nuw nsw i64 %13, 1
%17 = icmp ult i64 %16, %6
br i1 %17, label %18, label %8
18: ; preds = %12
%19 = getelementptr inbounds i32, i32* %0, i64 %13
br label %20
20: ; preds = %18, %28
%21 = phi i64 [ %14, %18 ], [ %30, %28 ]
%22 = phi i64 [ %15, %18 ], [ %29, %28 ]
%23 = load i32, i32* %19
%24 = getelementptr inbounds i32, i32* %0, i64 %21
%25 = load i32, i32* %24
%26 = icmp sgt i32 %23, %25
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 %25, i32* %19
store i32 %23, i32* %24
br label %28
28: ; preds = %27, %20
%29 = add i64 %22, 1
%30 = add nuw nsw i64 %21, 1
%31 = icmp eq i64 %30, %7
br i1 %31, label %8, label %20
32: ; preds = %8, %2
%33 = phi i64 [ 0, %2 ], [ %9, %8 ]
%34 = tail call i64 (...) @clock()
%35 = tail call i32 @mostrarArreglo(i32* %0, i32 %1)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%37 = sub nsw i64 %34, %3
%38 = sitofp i64 %37 to double
%39 = load double, double* @CLOCKS_PER_SEC
%40 = fdiv double %38, %39
%41 = fmul double %40, 1.000000e+03
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), double %41)
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i64 %33)
ret void
}