#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 */
float CLOCKS_PER_SEC;
int atoi(char *);
int /*<<< orphan*/ bubble_sort(int *, int);
int *calloc(int, int);
scalar_t__ clock();
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int i, n;
  int *a;
  clock_t start, end;
  float time;
  if (argc < 2) {
    printf("*** エラー: コマンドライン引数に配列の長さを指定して下さい\n");
    return 1;
  }
  n = atoi(argv[1]);
  printf("配列の長さ = %d\n", n);
  a = calloc(n, sizeof(int));
  if (a == NULL) {
    printf("配列のメモリ確保に失敗しました\n");
    return 1;
  }
  for (i = 0; i < n; i++) {
    a[i] = n - i;
  }
  start = clock();
  bubble_sort(a, n);
  end = clock();
  time = (float)(end - start) / CLOCKS_PER_SEC;
  printf("ソーティングにかかった時間 = %7.3f 秒\n", time);
  free(a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119a <main+0x3a>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1289 <main+0x129>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f1 <main+0x91>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1289 <main+0x129>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1223 <main+0xc3>
mov    -0x18(%rbp),%edx
sub    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f8 <main+0x98>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <bubble_sort@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2d8f(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe29(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1185 <main+0x15>
lea    0xf46(%rip),%rdi
jmp    11d6 <main+0x66>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
lea    0xeb8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     11cf <main+0x5f>
mov    %rax,%rbx
test   %r14d,%r14d
jle    12bf <main+0x14f>
mov    %r14d,%eax
cmp    $0x8,%r14d
jae    11e5 <main+0x75>
xor    %ecx,%ecx
jmp    12a6 <main+0x136>
lea    0xec5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
jmp    130d <main+0x19d>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
movd   %r14d,%xmm0
pshufd $0x0,%xmm0,%xmm0
lea    -0x8(%rcx),%rsi
mov    %rsi,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     131a <main+0x1aa>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
movdqa 0xde5(%rip),%xmm1
xor    %esi,%esi
movdqa 0xdeb(%rip),%xmm2
movdqa 0xdf3(%rip),%xmm3
movdqa 0xdfb(%rip),%xmm4
movdqa 0xe03(%rip),%xmm5
nopl   (%rax)
movdqa %xmm0,%xmm6
psubd  %xmm1,%xmm6
movdqa %xmm6,%xmm7
psubd  %xmm2,%xmm7
movdqu %xmm6,(%rbx,%rsi,4)
movdqu %xmm7,0x10(%rbx,%rsi,4)
movdqa %xmm6,%xmm7
psubd  %xmm3,%xmm7
psubd  %xmm4,%xmm6
movdqu %xmm7,0x20(%rbx,%rsi,4)
movdqu %xmm6,0x30(%rbx,%rsi,4)
add    $0x10,%rsi
paddd  %xmm5,%xmm1
add    $0xfffffffffffffffe,%rdi
jne    1240 <main+0xd0>
test   $0x1,%dl
je     12a1 <main+0x131>
psubd  %xmm1,%xmm0
movdqa %xmm0,%xmm1
psubd  0xd7a(%rip),%xmm1
movdqu %xmm0,(%rbx,%rsi,4)
movdqu %xmm1,0x10(%rbx,%rsi,4)
cmp    %rax,%rcx
je     12bf <main+0x14f>
mov    %r14d,%edx
sub    %ecx,%edx
nopl   0x0(%rax,%rax,1)
mov    %edx,(%rbx,%rcx,4)
add    $0x1,%rcx
add    $0xffffffff,%edx
cmp    %rcx,%rax
jne    12b0 <main+0x140>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14d,%esi
call   1090 <bubble_sort@plt>
xor    %eax,%eax
call   1050 <clock@plt>
sub    %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mov    0x2cf9(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd68(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movdqa 0xcde(%rip),%xmm1
xor    %esi,%esi
test   $0x1,%dl
jne    1286 <main+0x116>
jmp    12a1 <main+0x131>

LLVM IR (-O0):
@.str = [86 x i8] c"*** \E3\82\A8\E3\83\A9\E3\83\BC: \E3\82\B3\E3\83\9E\E3\83\B3\E3\83\89\E3\83\A9\E3\82\A4\E3\83\B3\E5\BC\95\E6\95\B0\E3\81\AB\E9\85\8D\E5\88\97\E3\81\AE\E9\95\B7\E3\81\95\E3\82\92\E6\8C\87\E5\AE\9A\E3\81\97\E3\81\A6\E4\B8\8B\E3\81\95\E3\81\84\0A\00"
@.str.1 = [22 x i8] c"\E9\85\8D\E5\88\97\E3\81\AE\E9\95\B7\E3\81\95 = %d\0A\00"
@.str.2 = [47 x i8] c"\E9\85\8D\E5\88\97\E3\81\AE\E3\83\A1\E3\83\A2\E3\83\AA\E7\A2\BA\E4\BF\9D\E3\81\AB\E5\A4\B1\E6\95\97\E3\81\97\E3\81\BE\E3\81\97\E3\81\9F\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.3 = [53 x i8] c"\E3\82\BD\E3\83\BC\E3\83\86\E3\82\A3\E3\83\B3\E3\82\B0\E3\81\AB\E3\81\8B\E3\81\8B\E3\81\A3\E3\81\9F\E6\99\82\E9\96\93 = %7.3f \E7\A7\92\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*
%9 = alloca i64
%10 = alloca i64
%11 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %62
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %7
%24 = call i32* @calloc(i32 %23, i32 4)
store i32* %24, i32** %8
%25 = load i32*, i32** %8
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %16
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %62
29: ; preds = %16
store i32 0, i32* %6
br label %30
30: ; preds = %42, %29
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load i32, i32* %7
%36 = load i32, i32* %6
%37 = sub nsw i32 %35, %36
%38 = load i32*, i32** %8
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
br label %42
42: ; preds = %34
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %30
45: ; preds = %30
%46 = call i64 (...) @clock()
store i64 %46, i64* %9
%47 = load i32*, i32** %8
%48 = load i32, i32* %7
%49 = call i32 @bubble_sort(i32* %47, i32 %48)
%50 = call i64 (...) @clock()
store i64 %50, i64* %10
%51 = load i64, i64* %10
%52 = load i64, i64* %9
%53 = sub nsw i64 %51, %52
%54 = sitofp i64 %53 to float
%55 = load float, float* @CLOCKS_PER_SEC
%56 = fdiv float %54, %55
store float %56, float* %11
%57 = load float, float* %11
%58 = fpext float %57 to double
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), double %58)
%60 = load i32*, i32** %8
%61 = call i32 @free(i32* %60)
store i32 0, i32* %3
br label %62
62: ; preds = %45, %27, %14
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"\E9\85\8D\E5\88\97\E3\81\AE\E9\95\B7\E3\81\95 = %d\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.3 = [53 x i8] c"\E3\82\BD\E3\83\BC\E3\83\86\E3\82\A3\E3\83\B3\E3\82\B0\E3\81\AB\E3\81\8B\E3\81\8B\E3\81\A3\E3\81\9F\E6\99\82\E9\96\93 = %7.3f \E7\A7\92\0A\00"
@str = [46 x i8] c"\E9\85\8D\E5\88\97\E3\81\AE\E3\83\A1\E3\83\A2\E3\83\AA\E7\A2\BA\E4\BF\9D\E3\81\AB\E5\A4\B1\E6\95\97\E3\81\97\E3\81\BE\E3\81\97\E3\81\9F\00"
@str.4 = [85 x i8] c"*** \E3\82\A8\E3\83\A9\E3\83\BC: \E3\82\B3\E3\83\9E\E3\83\B3\E3\83\89\E3\83\A9\E3\82\A4\E3\83\B3\E5\BC\95\E6\95\B0\E3\81\AB\E9\85\8D\E5\88\97\E3\81\AE\E9\95\B7\E3\81\95\E3\82\92\E6\8C\87\E5\AE\9A\E3\81\97\E3\81\A6\E4\B8\8B\E3\81\95\E3\81\84\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.4, i64 0, i64 0))
br label %91
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i32* @calloc(i32 %9, i32 4)
%12 = icmp eq i32* %11, null
br i1 %12, label %71, label %13
13: ; preds = %6
%14 = icmp sgt i32 %9, 0
br i1 %14, label %15, label %80
15: ; preds = %13
%16 = zext i32 %9 to i64
%17 = icmp ult i32 %9, 8
br i1 %17, label %69, label %18
18: ; preds = %15
%19 = and i64 %16, 4294967288
%20 = insertelement <4 x i32> poison, i32 %9, i64 0
%21 = shufflevector <4 x i32> %20, <4 x i32> poison, <4 x i32> zeroinitializer
%22 = insertelement <4 x i32> poison, i32 %9, i64 0
%23 = shufflevector <4 x i32> %22, <4 x i32> poison, <4 x i32> zeroinitializer
%24 = add nsw i64 %19, -8
%25 = lshr exact i64 %24, 3
%26 = add nuw nsw i64 %25, 1
%27 = and i64 %26, 1
%28 = icmp eq i64 %24, 0
br i1 %28, label %55, label %29
29: ; preds = %18
%30 = and i64 %26, 4611686018427387902
br label %31
31: ; preds = %31, %29
%32 = phi i64 [ 0, %29 ], [ %51, %31 ]
%33 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %29 ], [ %52, %31 ]
%34 = phi i64 [ 0, %29 ], [ %53, %31 ]
%35 = add <4 x i32> %33, <i32 4, i32 4, i32 4, i32 4>
%36 = sub nsw <4 x i32> %21, %33
%37 = sub nsw <4 x i32> %23, %35
%38 = getelementptr inbounds i32, i32* %11, i64 %32
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> %36, <4 x i32>* %39
%40 = getelementptr inbounds i32, i32* %38, i64 4
%41 = bitcast i32* %40 to <4 x i32>*
store <4 x i32> %37, <4 x i32>* %41
%42 = or i64 %32, 8
%43 = add <4 x i32> %33, <i32 8, i32 8, i32 8, i32 8>
%44 = add <4 x i32> %33, <i32 12, i32 12, i32 12, i32 12>
%45 = sub nsw <4 x i32> %21, %43
%46 = sub nsw <4 x i32> %23, %44
%47 = getelementptr inbounds i32, i32* %11, i64 %42
%48 = bitcast i32* %47 to <4 x i32>*
store <4 x i32> %45, <4 x i32>* %48
%49 = getelementptr inbounds i32, i32* %47, i64 4
%50 = bitcast i32* %49 to <4 x i32>*
store <4 x i32> %46, <4 x i32>* %50
%51 = add nuw i64 %32, 16
%52 = add <4 x i32> %33, <i32 16, i32 16, i32 16, i32 16>
%53 = add i64 %34, 2
%54 = icmp eq i64 %53, %30
br i1 %54, label %55, label %31
55: ; preds = %31, %18
%56 = phi i64 [ 0, %18 ], [ %51, %31 ]
%57 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %18 ], [ %52, %31 ]
%58 = icmp eq i64 %27, 0
br i1 %58, label %67, label %59
59: ; preds = %55
%60 = add <4 x i32> %57, <i32 4, i32 4, i32 4, i32 4>
%61 = sub nsw <4 x i32> %21, %57
%62 = sub nsw <4 x i32> %23, %60
%63 = getelementptr inbounds i32, i32* %11, i64 %56
%64 = bitcast i32* %63 to <4 x i32>*
store <4 x i32> %61, <4 x i32>* %64
%65 = getelementptr inbounds i32, i32* %63, i64 4
%66 = bitcast i32* %65 to <4 x i32>*
store <4 x i32> %62, <4 x i32>* %66
br label %67
67: ; preds = %55, %59
%68 = icmp eq i64 %19, %16
br i1 %68, label %80, label %69
69: ; preds = %15, %67
%70 = phi i64 [ 0, %15 ], [ %19, %67 ]
br label %73
71: ; preds = %6
%72 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %91
73: ; preds = %69, %73
%74 = phi i64 [ %78, %73 ], [ %70, %69 ]
%75 = trunc i64 %74 to i32
%76 = sub nsw i32 %9, %75
%77 = getelementptr inbounds i32, i32* %11, i64 %74
store i32 %76, i32* %77
%78 = add nuw nsw i64 %74, 1
%79 = icmp eq i64 %78, %16
br i1 %79, label %80, label %73
80: ; preds = %73, %67, %13
%81 = tail call i64 (...) @clock()
%82 = tail call i32 @bubble_sort(i32* %11, i32 %9)
%83 = tail call i64 (...) @clock()
%84 = sub nsw i64 %83, %81
%85 = sitofp i64 %84 to float
%86 = load float, float* @CLOCKS_PER_SEC
%87 = fdiv float %85, %86
%88 = fpext float %87 to double
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), double %88)
%90 = tail call i32 @free(i32* %11)
br label %91
91: ; preds = %80, %71, %4
%92 = phi i32 [ 1, %4 ], [ 1, %71 ], [ 0, %80 ]
ret i32 %92
}