#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 unsigned long clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ bubble_sort(long *, int);
unsigned long clock();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  long n, c, d, swap;
  int lectura = 0;
  int i = 0;
  int j;
  long numeros[100];
  unsigned long micros = 0;
  float millis = 0.0;
  clock_t start, end;
  FILE *input;
  input = fopen("trail.txt", "r");
  fscanf(input, "%d", &lectura);
  while (!feof(input)) {
    numeros[i] = lectura;
    i++;
    fscanf(input, "%d", &lectura);
  }
  fclose(input);
  start = clock();
  bubble_sort(numeros, i);
  end = clock();
  micros = end - start;
  millis = micros / 1000;
  printf("%f\n", millis);
  printf("Lista en orden ascendente:\n");
  for (c = 0; c < i; c++)
    printf("%ld\n", numeros[c]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x390,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movq   $0x0,-0x368(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x36c(%rbp)
ff
lea    0xe53(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x388(%rbp)
mov    -0x388(%rbp),%rdi
lea    0xe3e(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x388(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f8 <main+0x88>
jmp    122d <main+0xbd>
movslq -0x2c(%rbp),%rcx
movslq -0x30(%rbp),%rax
mov    %rcx,-0x360(%rbp,%rax,8)
ff
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x388(%rbp),%rdi
lea    0xded(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1060 <fscanf@plt>
jmp    11d7 <main+0x67>
mov    -0x388(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
mov    %al,-0x389(%rbp)
call   1030 <clock@plt>
mov    %rax,-0x378(%rbp)
mov    -0x30(%rbp),%esi
lea    -0x360(%rbp),%rdi
call   1090 <bubble_sort@plt>
mov    -0x389(%rbp),%al
call   1030 <clock@plt>
mov    %rax,-0x380(%rbp)
mov    -0x380(%rbp),%rax
mov    -0x378(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x368(%rbp)
mov    -0x368(%rbp),%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
shr    $0x4,%rdx
cvtsi2ss %rdx,%xmm0
movss  %xmm0,-0x36c(%rbp)
ff
movss  -0x36c(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xd4d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
cmp    %rcx,%rax
jge    131b <main+0x1ab>
mov    -0x18(%rbp),%rax
mov    -0x360(%rbp,%rax,8),%rsi
ff
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    12df <main+0x16f>
xor    %eax,%eax
add    $0x390,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x338,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe63(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0xe59(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1070 <fscanf@plt>
mov    %r14,%rdi
call   1080 <feof@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    1208 <main+0x88>
xor    %ebx,%ebx
lea    0xe35(%rip),%r15
lea    0xc(%rsp),%r12
nopl   0x0(%rax)
movslq 0xc(%rsp),%rax
mov    %rax,0x10(%rsp,%rbx,8)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <fscanf@plt>
mov    %r14,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     11e0 <main+0x60>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    %ebx,%esi
call   10a0 <bubble_sort@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
shr    $0x4,%rdx
cvtsi2ss %rdx,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdba(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xdb5(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
je     1298 <main+0x118>
mov    %ebx,%r15d
lea    0xd9d(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1280 <main+0x100>
xor    %eax,%eax
add    $0x338,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"trail.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%f\0A\00"
@.str.4 = [28 x i8] c"Lista en orden ascendente:\0A\00"
@.str.5 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [100 x i64]
%10 = alloca i64
%11 = alloca float
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %6
store i32 0, i32* %7
store i64 0, i64* %10
store float 0.000000e+00, float* %11
%15 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %14
%16 = load i32*, i32** %14
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
br label %18
18: ; preds = %23, %0
%19 = load i32*, i32** %14
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i64], [100 x i64]* %9, i64 0, i64 %27
store i64 %25, i64* %28
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
%31 = load i32*, i32** %14
%32 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
br label %18
33: ; preds = %18
%34 = load i32*, i32** %14
%35 = call i32 @fclose(i32* %34)
%36 = call i64 (...) @clock()
store i64 %36, i64* %12
%37 = getelementptr inbounds [100 x i64], [100 x i64]* %9, i64 0, i64 0
%38 = load i32, i32* %7
%39 = call i32 @bubble_sort(i64* %37, i32 %38)
%40 = call i64 (...) @clock()
store i64 %40, i64* %13
%41 = load i64, i64* %13
%42 = load i64, i64* %12
%43 = sub i64 %41, %42
store i64 %43, i64* %10
%44 = load i64, i64* %10
%45 = udiv i64 %44, 1000
%46 = uitofp i64 %45 to float
store float %46, float* %11
%47 = load float, float* %11
%48 = fpext float %47 to double
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i64 0, i64* %3
br label %51
51: ; preds = %61, %33
%52 = load i64, i64* %3
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = icmp slt i64 %52, %54
br i1 %55, label %56, label %64
56: ; preds = %51
%57 = load i64, i64* %3
%58 = getelementptr inbounds [100 x i64], [100 x i64]* %9, i64 0, i64 %57
%59 = load i64, i64* %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 %59)
br label %61
61: ; preds = %56
%62 = load i64, i64* %3
%63 = add nsw i64 %62, 1
store i64 %63, i64* %3
br label %51
64: ; preds = %51
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"trail.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%f\0A\00"
@.str.5 = [5 x i8] c"%ld\0A\00"
@str = [27 x i8] c"Lista en orden ascendente:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i64]
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast [100 x i64]* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = call i32 @feof(i32* %5)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %0, %9
%10 = phi i64 [ %14, %9 ], [ 0, %0 ]
%11 = load i32, i32* %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [100 x i64], [100 x i64]* %2, i64 0, i64 %10
store i64 %12, i64* %13
%14 = add nuw i64 %10, 1
%15 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%16 = call i32 @feof(i32* %5)
%17 = icmp eq i32 %16, 0
br i1 %17, label %9, label %18
18: ; preds = %9
%19 = trunc i64 %14 to i32
br label %20
20: ; preds = %18, %0
%21 = phi i32 [ 0, %0 ], [ %19, %18 ]
%22 = call i32 @fclose(i32* %5)
%23 = call i64 (...) @clock()
%24 = getelementptr inbounds [100 x i64], [100 x i64]* %2, i64 0, i64 0
%25 = call i32 @bubble_sort(i64* %24, i32 %21)
%26 = call i64 (...) @clock()
%27 = sub i64 %26, %23
%28 = udiv i64 %27, 1000
%29 = uitofp i64 %28 to float
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %30)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%33 = zext i32 %21 to i64
%34 = icmp eq i32 %21, 0
br i1 %34, label %42, label %35
35: ; preds = %20, %35
%36 = phi i64 [ %40, %35 ], [ 0, %20 ]
%37 = getelementptr inbounds [100 x i64], [100 x i64]* %2, i64 0, i64 %36
%38 = load i64, i64* %37
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 %38)
%40 = add nuw nsw i64 %36, 1
%41 = icmp eq i64 %40, %33
br i1 %41, label %42, label %35
42: ; preds = %35, %20
ret i32 0
}