#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 rand();
int /*<<< orphan*/ srand(int);
int main(int argc, char *argv[]) {
  int i, n, seed;
  int *a;
  clock_t start, end;
  float time;
  if (argc < 3) {
    printf("*** エラー: "
           "コマンドライン引数に乱数の種と配列の長さを指定して下さい\n");
    return 1;
  }
  seed = atoi(argv[1]);
  printf("乱数の種 = %d\n", seed);
  srand(seed);
  n = atoi(argv[2]);
  printf("配列の長さ = %d\n", n);
  a = calloc(n, sizeof(int));
  if (a == NULL) {
    printf("配列のメモリ確保に失敗しました\n");
    return 1;
  }
  for (i = 0; i < n; i++) {
    a[i] = rand();
  }
  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   $0x3,-0x8(%rbp)
jge    11ba <main+0x3a>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x155>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    123a <main+0xba>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x155>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    126f <main+0xef>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1241 <main+0xc1>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   10a0 <bubble_sort@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2d43(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdff(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x28(%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   %r12
push   %rbx
cmp    $0x2,%edi
jg     11a9 <main+0x19>
lea    0xee8(%rip),%rdi
jmp    1278 <main+0xe8>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
lea    0xe42(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1070 <srand@plt>
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
lea    0xe32(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
test   %rax,%rax
je     1271 <main+0xe1>
mov    %rax,%r12
test   %r14d,%r14d
jle    1224 <main+0x94>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1210 <main+0x80>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %r14d,%esi
call   10b0 <bubble_sort@plt>
xor    %eax,%eax
call   1050 <clock@plt>
sub    %r15,%rax
cvtsi2ss %rax,%xmm0
mov    0x2d97(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc9(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1282 <main+0xf2>
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [101 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\E4\B9\B1\E6\95\B0\E3\81\AE\E7\A8\AE\E3\81\A8\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 = [19 x i8] c"\E4\B9\B1\E6\95\B0\E3\81\AE\E7\A8\AE = %d\0A\00"
@.str.2 = [22 x i8] c"\E9\85\8D\E5\88\97\E3\81\AE\E9\95\B7\E3\81\95 = %d\0A\00"
@.str.3 = [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.4 = [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 i32*
%10 = alloca i64
%11 = alloca i64
%12 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %69
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %8
%25 = call i32 @srand(i32 %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %7
%33 = call i32* @calloc(i32 %32, i32 4)
store i32* %33, i32** %9
%34 = load i32*, i32** %9
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %17
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %69
38: ; preds = %17
store i32 0, i32* %6
br label %39
39: ; preds = %49, %38
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = call i32 (...) @rand()
%45 = load i32*, i32** %9
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %44, i32* %48
br label %49
49: ; preds = %43
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %39
52: ; preds = %39
%53 = call i64 (...) @clock()
store i64 %53, i64* %10
%54 = load i32*, i32** %9
%55 = load i32, i32* %7
%56 = call i32 @bubble_sort(i32* %54, i32 %55)
%57 = call i64 (...) @clock()
store i64 %57, i64* %11
%58 = load i64, i64* %11
%59 = load i64, i64* %10
%60 = sub nsw i64 %58, %59
%61 = sitofp i64 %60 to float
%62 = load float, float* @CLOCKS_PER_SEC
%63 = fdiv float %61, %62
store float %63, float* %12
%64 = load float, float* %12
%65 = fpext float %64 to double
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), double %65)
%67 = load i32*, i32** %9
%68 = call i32 @free(i32* %67)
store i32 0, i32* %3
br label %69
69: ; preds = %52, %36, %15
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str.1 = [19 x i8] c"\E4\B9\B1\E6\95\B0\E3\81\AE\E7\A8\AE = %d\0A\00"
@.str.2 = [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.4 = [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.5 = [100 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\E4\B9\B1\E6\95\B0\E3\81\AE\E7\A8\AE\E3\81\A8\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, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([100 x i8], [100 x i8]* @str.5, i64 0, i64 0))
br label %41
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 ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i32 @srand(i32 %9)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = tail call i32* @calloc(i32 %14, i32 4)
%17 = icmp eq i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %6
%19 = icmp sgt i32 %14, 0
br i1 %19, label %20, label %30
20: ; preds = %18
%21 = zext i32 %14 to i64
br label %24
22: ; preds = %6
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %41
24: ; preds = %20, %24
%25 = phi i64 [ 0, %20 ], [ %28, %24 ]
%26 = tail call i32 (...) @rand()
%27 = getelementptr inbounds i32, i32* %16, i64 %25
store i32 %26, i32* %27
%28 = add nuw nsw i64 %25, 1
%29 = icmp eq i64 %28, %21
br i1 %29, label %30, label %24
30: ; preds = %24, %18
%31 = tail call i64 (...) @clock()
%32 = tail call i32 @bubble_sort(i32* %16, i32 %14)
%33 = tail call i64 (...) @clock()
%34 = sub nsw i64 %33, %31
%35 = sitofp i64 %34 to float
%36 = load float, float* @CLOCKS_PER_SEC
%37 = fdiv float %35, %36
%38 = fpext float %37 to double
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), double %38)
%40 = tail call i32 @free(i32* %16)
br label %41
41: ; preds = %30, %22, %4
%42 = phi i32 [ 1, %4 ], [ 1, %22 ], [ 0, %30 ]
ret i32 %42
}