#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 atoi(char *);
int /*<<< orphan*/ ordena_bolha(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int *vetor_aloca(int);
int /*<<< orphan*/ vetor_libera(int *);
int main(int argc, char **argv) {
  int n = 20;
  int *v;
  int i;
  if (argc > 1)
    n = atoi(argv[1]);
  printf("alocando %d elementos ...\n", n);
  v = vetor_aloca(n);
  srand(time(NULL));
  for (i = 0; i < n; i++)
    v[i] = rand() % n;
  printf("iniciando ordenacao dos %d elementos ...\n", n);
  ordena_bolha(v, n);
  for (i = 0; i < n; i++)
    printf("%d ", v[i]);
  printf("\n");
  printf("liberando memoria ...\n");
  vetor_libera(v);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x14,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b7 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <vetor_aloca@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121b <main+0x9b>
mov    $0x0,%al
call   10a0 <rand@plt>
cltd
idivl  -0x14(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11eb <main+0x6b>
mov    -0x14(%rbp),%esi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <ordena_bolha@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1272 <main+0xf2>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    123f <main+0xbf>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <vetor_libera@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x14,%r14d
cmp    $0x2,%edi
jl     11be <main+0x1e>
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
lea    0xe3b(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1080 <vetor_aloca@plt>
mov    %rax,%r15
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
test   %r14d,%r14d
jle    1269 <main+0xc9>
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   10c0 <rand@plt>
cltd
idiv   %r14d
mov    %edx,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1200 <main+0x60>
lea    0xdfc(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1090 <ordena_bolha@plt>
test   %r14d,%r14d
jle    1285 <main+0xe5>
lea    0xe05(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1250 <main+0xb0>
jmp    1285 <main+0xe5>
lea    0xdab(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1090 <ordena_bolha@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdb3(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   10b0 <vetor_libera@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"alocando %d elementos ...\0A\00"
@.str.1 = [42 x i8] c"iniciando ordenacao dos %d elementos ...\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [23 x i8] c"liberando memoria ...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 20, i32* %6
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
br label %16
16: ; preds = %11, %2
%17 = load i32, i32* %6
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %6
%20 = call i32* @vetor_aloca(i32 %19)
store i32* %20, i32** %7
%21 = call i32 @time(i32* null)
%22 = call i32 @srand(i32 %21)
store i32 0, i32* %8
br label %23
23: ; preds = %35, %16
%24 = load i32, i32* %8
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = call i32 (...) @rand()
%29 = load i32, i32* %6
%30 = srem i32 %28, %29
%31 = load i32*, i32** %7
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 %30, i32* %34
br label %35
35: ; preds = %27
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %23
38: ; preds = %23
%39 = load i32, i32* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32*, i32** %7
%42 = load i32, i32* %6
%43 = call i32 @ordena_bolha(i32* %41, i32 %42)
store i32 0, i32* %8
br label %44
44: ; preds = %55, %38
%45 = load i32, i32* %8
%46 = load i32, i32* %6
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %58
48: ; preds = %44
%49 = load i32*, i32** %7
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %48
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %44
58: ; preds = %44
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%61 = load i32*, i32** %7
%62 = call i32 @vetor_libera(i32* %61)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"alocando %d elementos ...\0A\00"
@.str.1 = [42 x i8] c"iniciando ordenacao dos %d elementos ...\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@str = [22 x i8] c"liberando memoria ...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %4, %2
%9 = phi i32 [ %7, %4 ], [ 20, %2 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32* @vetor_aloca(i32 %9)
%12 = tail call i32 @time(i32* null)
%13 = tail call i32 @srand(i32 %12)
%14 = icmp sgt i32 %9, 0
br i1 %14, label %15, label %36
15: ; preds = %8
%16 = zext i32 %9 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %22, %17 ]
%19 = tail call i32 (...) @rand()
%20 = srem i32 %19, %9
%21 = getelementptr inbounds i32, i32* %11, i64 %18
store i32 %20, i32* %21
%22 = add nuw nsw i64 %18, 1
%23 = icmp eq i64 %22, %16
br i1 %23, label %24, label %17
24: ; preds = %17
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%26 = tail call i32 @ordena_bolha(i32* %11, i32 %9)
br i1 %14, label %27, label %39
27: ; preds = %24
%28 = zext i32 %9 to i64
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ 0, %27 ], [ %34, %29 ]
%31 = getelementptr inbounds i32, i32* %11, i64 %30
%32 = load i32, i32* %31
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = add nuw nsw i64 %30, 1
%35 = icmp eq i64 %34, %28
br i1 %35, label %39, label %29
36: ; preds = %8
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%38 = tail call i32 @ordena_bolha(i32* %11, i32 %9)
br label %39
39: ; preds = %29, %36, %24
%40 = tail call i32 @putchar(i32 10)
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%42 = tail call i32 @vetor_libera(i32* %11)
ret i32 0
}