#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*/ troca(int *, int *);
void bubble_sort(int vetor[], int N) {
  int i;
  int j;
  j = 1;
  while (j == 1) {
    j = 0;
    for (i = 0; i < (N - 1); i++) {
      if (vetor[i + 1] < vetor[i]) {
        troca(&(vetor[i + 1]), &(vetor[i]));
        j = 1;
      }
    }
  }
}


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11b6 <bubble_sort+0xa6>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b1 <bubble_sort+0xa1>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    119e <bubble_sort+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <troca@plt>
movl   $0x1,-0x14(%rbp)
jmp    11a3 <bubble_sort+0x93>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113e <bubble_sort+0x2e>
jmp    1126 <bubble_sort+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_sort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     116f <bubble_sort+0x5f>
mov    %esi,%r14d
mov    %rdi,%r12
lea    -0x1(%r14),%r15d
xor    %ecx,%ecx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rbx
mov    0x4(%r12,%rcx,4),%edx
cmp    (%r12,%rcx,4),%edx
jge    1155 <bubble_sort+0x45>
lea    (%r12,%rcx,4),%rdi
add    $0x4,%rdi
lea    (%r12,%rcx,4),%rsi
call   1030 <troca@plt>
mov    $0x1,%eax
mov    %rbx,%rcx
cmp    %r15,%rbx
jne    1130 <bubble_sort+0x20>
cmp    $0x2,%r14d
jl     116f <bubble_sort+0x5f>
xor    %ecx,%ecx
cmp    $0x1,%eax
mov    $0x0,%eax
je     1130 <bubble_sort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @bubble_sort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1, i32* %6
br label %7
7: ; preds = %44, %2
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %45
10: ; preds = %7
store i32 0, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %41, %10
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %44
16: ; preds = %11
%17 = load i32*, i32** %3
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %17, i64 %20
%22 = load i32, i32* %21
%23 = load i32*, i32** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = icmp slt i32 %22, %27
br i1 %28, label %29, label %40
29: ; preds = %16
%30 = load i32*, i32** %3
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %30, i64 %33
%35 = load i32*, i32** %3
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = call i32 @troca(i32* %34, i32* %38)
store i32 1, i32* %6
br label %40
40: ; preds = %29, %16
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %11
44: ; preds = %11
br label %7
45: ; preds = %7
ret void
}

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