#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*/ intercambiar(int *, int *);
int burbuja(int *vector, unsigned int tope, unsigned int *compar,
            unsigned int *inter) {
  unsigned int vuelta, posicion;
  *compar = 0;
  *inter = 0;
  for (vuelta = 0; vuelta < tope; vuelta++) {
    for (posicion = 0; posicion < tope - 1; posicion++) {
      if (vector[posicion] > vector[posicion + 1]) {
        intercambiar(&vector[posicion], &vector[posicion + 1]);
        (*inter)++;
      }
      (*compar)++;
    }
  }
  return vuelta;
}


x86 assembly (clang, -O0):
<burbuja>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11e2 <burbuja+0xd2>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    11cf <burbuja+0xbf>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%edx
add    $0x1,%edx
mov    %edx,%edx
cmp    (%rcx,%rdx,4),%eax
jle    11b6 <burbuja+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <intercambiar@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1155 <burbuja+0x45>
jmp    11d4 <burbuja+0xc4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1142 <burbuja+0x32>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<burbuja>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
movl   $0x0,(%rdx)
movl   $0x0,(%rcx)
mov    %rsi,0x8(%rsp)
test   %esi,%esi
je     11a8 <burbuja+0x98>
mov    %rcx,%r15
mov    %rdx,%r13
mov    0x8(%rsp),%rax
lea    -0x1(%rax),%r14d
addq   $0x4,0x10(%rsp)
xor    %r12d,%r12d
jmp    116b <burbuja+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12d
cmp    0x8(%rsp),%r12d
je     11a8 <burbuja+0x98>
test   %r14,%r14
je     1160 <burbuja+0x50>
mov    %r14,%rbp
mov    0x10(%rsp),%rbx
jmp    118f <burbuja+0x7f>
nopw   0x0(%rax,%rax,1)
addl   $0x1,0x0(%r13)
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
je     1160 <burbuja+0x50>
mov    -0x4(%rbx),%eax
cmp    (%rbx),%eax
jle    1180 <burbuja+0x70>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
call   1030 <intercambiar@plt>
addl   $0x1,(%r15)
jmp    1180 <burbuja+0x70>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @burbuja(i32* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%11 = load i32*, i32** %7
store i32 0, i32* %11
%12 = load i32*, i32** %8
store i32 0, i32* %12
store i32 0, i32* %9
br label %13
13: ; preds = %58, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %6
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %61
17: ; preds = %13
store i32 0, i32* %10
br label %18
18: ; preds = %54, %17
%19 = load i32, i32* %10
%20 = load i32, i32* %6
%21 = sub i32 %20, 1
%22 = icmp ult i32 %19, %21
br i1 %22, label %23, label %57
23: ; preds = %18
%24 = load i32*, i32** %5
%25 = load i32, i32* %10
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = load i32*, i32** %5
%30 = load i32, i32* %10
%31 = add i32 %30, 1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %29, i64 %32
%34 = load i32, i32* %33
%35 = icmp sgt i32 %28, %34
br i1 %35, label %36, label %50
36: ; preds = %23
%37 = load i32*, i32** %5
%38 = load i32, i32* %10
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32*, i32** %5
%42 = load i32, i32* %10
%43 = add i32 %42, 1
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %41, i64 %44
%46 = call i32 @intercambiar(i32* %40, i32* %45)
%47 = load i32*, i32** %8
%48 = load i32, i32* %47
%49 = add i32 %48, 1
store i32 %49, i32* %47
br label %50
50: ; preds = %36, %23
%51 = load i32*, i32** %7
%52 = load i32, i32* %51
%53 = add i32 %52, 1
store i32 %53, i32* %51
br label %54
54: ; preds = %50
%55 = load i32, i32* %10
%56 = add i32 %55, 1
store i32 %56, i32* %10
br label %18
57: ; preds = %18
br label %58
58: ; preds = %57
%59 = load i32, i32* %9
%60 = add i32 %59, 1
store i32 %60, i32* %9
br label %13
61: ; preds = %13
%62 = load i32, i32* %9
ret i32 %62
}

LLVM IR (-O2):
define i32 @burbuja(i32* %0, i32 %1, i32* nocapture %2, i32* nocapture %3) {
store i32 0, i32* %2
store i32 0, i32* %3
%5 = icmp eq i32 %1, 0
br i1 %5, label %31, label %6
6: ; preds = %4
%7 = add i32 %1, -1
%8 = icmp eq i32 %7, 0
%9 = zext i32 %7 to i64
br label %10
10: ; preds = %6, %28
%11 = phi i32 [ 0, %6 ], [ %29, %28 ]
br i1 %8, label %28, label %12
12: ; preds = %10, %24
%13 = phi i64 [ %16, %24 ], [ 0, %10 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = add nuw nsw i64 %13, 1
%17 = getelementptr inbounds i32, i32* %0, i64 %16
%18 = load i32, i32* %17
%19 = icmp sgt i32 %15, %18
br i1 %19, label %20, label %24
20: ; preds = %12
%21 = tail call i32 @intercambiar(i32* %14, i32* %17)
%22 = load i32, i32* %3
%23 = add i32 %22, 1
store i32 %23, i32* %3
br label %24
24: ; preds = %20, %12
%25 = load i32, i32* %2
%26 = add i32 %25, 1
store i32 %26, i32* %2
%27 = icmp eq i64 %16, %9
br i1 %27, label %28, label %12
28: ; preds = %24, %10
%29 = add nuw i32 %11, 1
%30 = icmp eq i32 %29, %1
br i1 %30, label %31, label %10
31: ; preds = %28, %4
ret i32 %1
}