#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 int /*<<< orphan*/ clock_t;

/* Variables and functions */
int /*<<< orphan*/ bubble_sort(int *, int const);
int /*<<< orphan*/ clock();
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ get_time(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ heap_sort(int *, int const);
int /*<<< orphan*/ insertion_sort(int *, int const);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ merge_sort(int *, int /*<<< orphan*/, int const);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quick_sort(int *, int /*<<< orphan*/, int const);
int /*<<< orphan*/ rand_array(int *, int const);
int /*<<< orphan*/ selection_sort(int *, int const);
int /*<<< orphan*/ shell_sort(int *, int const);
int test_sort(const int count) {
  clock_t start, end;
  double timeUsed;
  int *p, *sort_data;
  p = (int *)malloc(sizeof(int) * count);
  if (p == NULL) {
    printf("memory alloc error.\n");
    return -1;
  }
  sort_data = (int *)malloc(sizeof(int) * count);
  if (sort_data == NULL) {
    printf("memory alloc error.\n");
    return -1;
  }
  memset(p, 0, sizeof(int) * count);
  rand_array(p, count);
  memset(sort_data, 0, sizeof(int) * count);
  memcpy(sort_data, p, sizeof(int) * count);
  start = clock();
  insertion_sort(sort_data, count);
  end = clock();
  printf("insert sort:");
  get_time(start, end);
  memset(sort_data, 0, sizeof(int) * count);
  memcpy(sort_data, p, sizeof(int) * count);
  start = clock();
  merge_sort(sort_data, 0, count - 1);
  end = clock();
  printf("merge  sort:");
  get_time(start, end);
  memset(sort_data, 0, sizeof(int) * count);
  memcpy(sort_data, p, sizeof(int) * count);
  start = clock();
  bubble_sort(sort_data, count);
  end = clock();
  printf("bubble sort:");
  get_time(start, end);
  memset(sort_data, 0, sizeof(int) * count);
  memcpy(sort_data, p, sizeof(int) * count);
  start = clock();
  selection_sort(sort_data, count);
  end = clock();
  printf("select sort:");
  get_time(start, end);
  memset(sort_data, 0, sizeof(int) * count);
  memcpy(sort_data, p, sizeof(int) * count);
  start = clock();
  shell_sort(sort_data, count);
  end = clock();
  printf("shell  sort:");
  get_time(start, end);
  memset(sort_data, 0, sizeof(int) * count);
  memcpy(sort_data, p, sizeof(int) * count);
  start = clock();
  quick_sort(sort_data, 0, count - 1);
  end = clock();
  printf("quick  sort:");
  get_time(start, end);
  memset(sort_data, 0, sizeof(int) * count);
  memcpy(sort_data, p, sizeof(int) * count);
  start = clock();
  heap_sort(sort_data, count);
  end = clock();
  printf("heap   sort:");
  get_time(start, end);
  if (p != NULL) {
    free(p);
    p = NULL;
  }
  if (sort_data != NULL) {
    free(sort_data);
    sort_data = NULL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1231 <test_sort+0x41>
lea    0xde0(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1586 <test_sort+0x396>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1267 <test_sort+0x77>
lea    0xdaa(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1586 <test_sort+0x396>
mov    -0x20(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10d0 <rand_array@plt>
mov    -0x28(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1100 <insertion_sort@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x10(%rbp)
lea    0xd3a(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <get_time@plt>
mov    -0x28(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   10c0 <merge_sort@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x10(%rbp)
lea    0xcdf(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <get_time@plt>
mov    -0x28(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1110 <bubble_sort@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x10(%rbp)
lea    0xc89(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <get_time@plt>
mov    -0x28(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <selection_sort@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x10(%rbp)
lea    0xc33(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <get_time@plt>
mov    -0x28(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10f0 <shell_sort@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x10(%rbp)
lea    0xbdd(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <get_time@plt>
mov    -0x28(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   10e0 <quick_sort@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x10(%rbp)
lea    0xb82(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <get_time@plt>
mov    -0x28(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <heap_sort@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x10(%rbp)
lea    0xb2c(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <get_time@plt>
cmpq   $0x0,-0x20(%rbp)
je     1563 <test_sort+0x373>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     157f <test_sort+0x38f>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0x0(,%r15,4),%ebx
mov    %ebx,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     1498 <test_sort+0x298>
mov    %rax,%r12
mov    %ebx,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     1498 <test_sort+0x298>
mov    %rax,%rbp
mov    %r12,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1090 <memset@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   10e0 <rand_array@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1090 <memset@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
mov    %r15d,%esi
call   1110 <insertion_sort@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r14d
lea    0xd6e(%rip),%rdi
call   1080 <printf@plt>
mov    %r13d,%edi
mov    %r14d,%esi
call   10a0 <get_time@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1090 <memset@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r14d
lea    -0x1(%r15),%edx
mov    %edx,0x4(%rsp)
mov    %rbp,%rdi
xor    %esi,%esi
call   10d0 <merge_sort@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r13d
lea    0xd25(%rip),%rdi
call   1080 <printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
call   10a0 <get_time@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1090 <memset@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
mov    %r15d,%esi
call   1120 <bubble_sort@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r13d
lea    0xce3(%rip),%rdi
call   1080 <printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
call   10a0 <get_time@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1090 <memset@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
mov    %r15d,%esi
call   1030 <selection_sort@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r13d
lea    0xca1(%rip),%rdi
call   1080 <printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
call   10a0 <get_time@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1090 <memset@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
mov    %r15d,%esi
call   1100 <shell_sort@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r13d
lea    0xc5f(%rip),%rdi
call   1080 <printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
call   10a0 <get_time@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1090 <memset@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
mov    0x4(%rsp),%edx
call   10f0 <quick_sort@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r13d
lea    0xc1a(%rip),%rdi
call   1080 <printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
call   10a0 <get_time@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1090 <memset@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
mov    %r15d,%esi
call   1050 <heap_sort@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%ebx
lea    0xbd9(%rip),%rdi
call   1080 <printf@plt>
mov    %r14d,%edi
mov    %ebx,%esi
call   10a0 <get_time@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    14a9 <test_sort+0x2a9>
lea    0xbbc(%rip),%rdi
call   1060 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"memory alloc error.\0A\00"
@.str.1 = [13 x i8] c"insert sort:\00"
@.str.2 = [13 x i8] c"merge sort:\00"
@.str.3 = [13 x i8] c"bubble sort:\00"
@.str.4 = [13 x i8] c"select sort:\00"
@.str.5 = [13 x i8] c"shell sort:\00"
@.str.6 = [13 x i8] c"quick sort:\00"
@.str.7 = [13 x i8] c"heap sort:\00"
define i32 @test_sort(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca i32*
%8 = alloca i32*
store i32 %0, i32* %3
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %208
19: ; preds = %1
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = mul i64 4, %21
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %8
%26 = load i32*, i32** %8
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %208
30: ; preds = %19
%31 = load i32*, i32** %7
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = mul i64 4, %33
%35 = trunc i64 %34 to i32
%36 = call i32 @memset(i32* %31, i32 0, i32 %35)
%37 = load i32*, i32** %7
%38 = load i32, i32* %3
%39 = call i32 @rand_array(i32* %37, i32 %38)
%40 = load i32*, i32** %8
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = mul i64 4, %42
%44 = trunc i64 %43 to i32
%45 = call i32 @memset(i32* %40, i32 0, i32 %44)
%46 = load i32*, i32** %8
%47 = load i32*, i32** %7
%48 = load i32, i32* %3
%49 = sext i32 %48 to i64
%50 = mul i64 4, %49
%51 = trunc i64 %50 to i32
%52 = call i32 @memcpy(i32* %46, i32* %47, i32 %51)
%53 = call i32 (...) @clock()
store i32 %53, i32* %4
%54 = load i32*, i32** %8
%55 = load i32, i32* %3
%56 = call i32 @insertion_sort(i32* %54, i32 %55)
%57 = call i32 (...) @clock()
store i32 %57, i32* %5
%58 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%59 = load i32, i32* %4
%60 = load i32, i32* %5
%61 = call i32 @get_time(i32 %59, i32 %60)
%62 = load i32*, i32** %8
%63 = load i32, i32* %3
%64 = sext i32 %63 to i64
%65 = mul i64 4, %64
%66 = trunc i64 %65 to i32
%67 = call i32 @memset(i32* %62, i32 0, i32 %66)
%68 = load i32*, i32** %8
%69 = load i32*, i32** %7
%70 = load i32, i32* %3
%71 = sext i32 %70 to i64
%72 = mul i64 4, %71
%73 = trunc i64 %72 to i32
%74 = call i32 @memcpy(i32* %68, i32* %69, i32 %73)
%75 = call i32 (...) @clock()
store i32 %75, i32* %4
%76 = load i32*, i32** %8
%77 = load i32, i32* %3
%78 = sub nsw i32 %77, 1
%79 = call i32 @merge_sort(i32* %76, i32 0, i32 %78)
%80 = call i32 (...) @clock()
store i32 %80, i32* %5
%81 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%82 = load i32, i32* %4
%83 = load i32, i32* %5
%84 = call i32 @get_time(i32 %82, i32 %83)
%85 = load i32*, i32** %8
%86 = load i32, i32* %3
%87 = sext i32 %86 to i64
%88 = mul i64 4, %87
%89 = trunc i64 %88 to i32
%90 = call i32 @memset(i32* %85, i32 0, i32 %89)
%91 = load i32*, i32** %8
%92 = load i32*, i32** %7
%93 = load i32, i32* %3
%94 = sext i32 %93 to i64
%95 = mul i64 4, %94
%96 = trunc i64 %95 to i32
%97 = call i32 @memcpy(i32* %91, i32* %92, i32 %96)
%98 = call i32 (...) @clock()
store i32 %98, i32* %4
%99 = load i32*, i32** %8
%100 = load i32, i32* %3
%101 = call i32 @bubble_sort(i32* %99, i32 %100)
%102 = call i32 (...) @clock()
store i32 %102, i32* %5
%103 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%104 = load i32, i32* %4
%105 = load i32, i32* %5
%106 = call i32 @get_time(i32 %104, i32 %105)
%107 = load i32*, i32** %8
%108 = load i32, i32* %3
%109 = sext i32 %108 to i64
%110 = mul i64 4, %109
%111 = trunc i64 %110 to i32
%112 = call i32 @memset(i32* %107, i32 0, i32 %111)
%113 = load i32*, i32** %8
%114 = load i32*, i32** %7
%115 = load i32, i32* %3
%116 = sext i32 %115 to i64
%117 = mul i64 4, %116
%118 = trunc i64 %117 to i32
%119 = call i32 @memcpy(i32* %113, i32* %114, i32 %118)
%120 = call i32 (...) @clock()
store i32 %120, i32* %4
%121 = load i32*, i32** %8
%122 = load i32, i32* %3
%123 = call i32 @selection_sort(i32* %121, i32 %122)
%124 = call i32 (...) @clock()
store i32 %124, i32* %5
%125 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%126 = load i32, i32* %4
%127 = load i32, i32* %5
%128 = call i32 @get_time(i32 %126, i32 %127)
%129 = load i32*, i32** %8
%130 = load i32, i32* %3
%131 = sext i32 %130 to i64
%132 = mul i64 4, %131
%133 = trunc i64 %132 to i32
%134 = call i32 @memset(i32* %129, i32 0, i32 %133)
%135 = load i32*, i32** %8
%136 = load i32*, i32** %7
%137 = load i32, i32* %3
%138 = sext i32 %137 to i64
%139 = mul i64 4, %138
%140 = trunc i64 %139 to i32
%141 = call i32 @memcpy(i32* %135, i32* %136, i32 %140)
%142 = call i32 (...) @clock()
store i32 %142, i32* %4
%143 = load i32*, i32** %8
%144 = load i32, i32* %3
%145 = call i32 @shell_sort(i32* %143, i32 %144)
%146 = call i32 (...) @clock()
store i32 %146, i32* %5
%147 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%148 = load i32, i32* %4
%149 = load i32, i32* %5
%150 = call i32 @get_time(i32 %148, i32 %149)
%151 = load i32*, i32** %8
%152 = load i32, i32* %3
%153 = sext i32 %152 to i64
%154 = mul i64 4, %153
%155 = trunc i64 %154 to i32
%156 = call i32 @memset(i32* %151, i32 0, i32 %155)
%157 = load i32*, i32** %8
%158 = load i32*, i32** %7
%159 = load i32, i32* %3
%160 = sext i32 %159 to i64
%161 = mul i64 4, %160
%162 = trunc i64 %161 to i32
%163 = call i32 @memcpy(i32* %157, i32* %158, i32 %162)
%164 = call i32 (...) @clock()
store i32 %164, i32* %4
%165 = load i32*, i32** %8
%166 = load i32, i32* %3
%167 = sub nsw i32 %166, 1
%168 = call i32 @quick_sort(i32* %165, i32 0, i32 %167)
%169 = call i32 (...) @clock()
store i32 %169, i32* %5
%170 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%171 = load i32, i32* %4
%172 = load i32, i32* %5
%173 = call i32 @get_time(i32 %171, i32 %172)
%174 = load i32*, i32** %8
%175 = load i32, i32* %3
%176 = sext i32 %175 to i64
%177 = mul i64 4, %176
%178 = trunc i64 %177 to i32
%179 = call i32 @memset(i32* %174, i32 0, i32 %178)
%180 = load i32*, i32** %8
%181 = load i32*, i32** %7
%182 = load i32, i32* %3
%183 = sext i32 %182 to i64
%184 = mul i64 4, %183
%185 = trunc i64 %184 to i32
%186 = call i32 @memcpy(i32* %180, i32* %181, i32 %185)
%187 = call i32 (...) @clock()
store i32 %187, i32* %4
%188 = load i32*, i32** %8
%189 = load i32, i32* %3
%190 = call i32 @heap_sort(i32* %188, i32 %189)
%191 = call i32 (...) @clock()
store i32 %191, i32* %5
%192 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%193 = load i32, i32* %4
%194 = load i32, i32* %5
%195 = call i32 @get_time(i32 %193, i32 %194)
%196 = load i32*, i32** %7
%197 = icmp ne i32* %196, null
br i1 %197, label %198, label %201
198: ; preds = %30
%199 = load i32*, i32** %7
%200 = call i32 @free(i32* %199)
store i32* null, i32** %7
br label %201
201: ; preds = %198, %30
%202 = load i32*, i32** %8
%203 = icmp ne i32* %202, null
br i1 %203, label %204, label %207
204: ; preds = %201
%205 = load i32*, i32** %8
%206 = call i32 @free(i32* %205)
store i32* null, i32** %8
br label %207
207: ; preds = %204, %201
store i32 0, i32* %2
br label %208
208: ; preds = %207, %28, %17
%209 = load i32, i32* %2
ret i32 %209
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"insert sort:\00"
@.str.2 = [13 x i8] c"merge sort:\00"
@.str.3 = [13 x i8] c"bubble sort:\00"
@.str.4 = [13 x i8] c"select sort:\00"
@.str.5 = [13 x i8] c"shell sort:\00"
@.str.6 = [13 x i8] c"quick sort:\00"
@.str.7 = [13 x i8] c"heap sort:\00"
@str.8 = [20 x i8] c"memory alloc error.\00"
define i32 @test_sort(i32 %0) {
%2 = shl i32 %0, 2
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
br label %69
8: ; preds = %1
%9 = tail call i64 @malloc(i32 %2)
%10 = inttoptr i64 %9 to i32*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
br label %69
14: ; preds = %8
%15 = tail call i32 @memset(i32* %4, i32 0, i32 %2)
%16 = tail call i32 @rand_array(i32* %4, i32 %0)
%17 = tail call i32 @memset(i32* %10, i32 0, i32 %2)
%18 = tail call i32 @memcpy(i32* %10, i32* %4, i32 %2)
%19 = tail call i32 (...) @clock()
%20 = tail call i32 @insertion_sort(i32* %10, i32 %0)
%21 = tail call i32 (...) @clock()
%22 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @get_time(i32 %19, i32 %21)
%24 = tail call i32 @memset(i32* %10, i32 0, i32 %2)
%25 = tail call i32 @memcpy(i32* %10, i32* %4, i32 %2)
%26 = tail call i32 (...) @clock()
%27 = add nsw i32 %0, -1
%28 = tail call i32 @merge_sort(i32* %10, i32 0, i32 %27)
%29 = tail call i32 (...) @clock()
%30 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @get_time(i32 %26, i32 %29)
%32 = tail call i32 @memset(i32* %10, i32 0, i32 %2)
%33 = tail call i32 @memcpy(i32* %10, i32* %4, i32 %2)
%34 = tail call i32 (...) @clock()
%35 = tail call i32 @bubble_sort(i32* %10, i32 %0)
%36 = tail call i32 (...) @clock()
%37 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%38 = tail call i32 @get_time(i32 %34, i32 %36)
%39 = tail call i32 @memset(i32* %10, i32 0, i32 %2)
%40 = tail call i32 @memcpy(i32* %10, i32* %4, i32 %2)
%41 = tail call i32 (...) @clock()
%42 = tail call i32 @selection_sort(i32* %10, i32 %0)
%43 = tail call i32 (...) @clock()
%44 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%45 = tail call i32 @get_time(i32 %41, i32 %43)
%46 = tail call i32 @memset(i32* %10, i32 0, i32 %2)
%47 = tail call i32 @memcpy(i32* %10, i32* %4, i32 %2)
%48 = tail call i32 (...) @clock()
%49 = tail call i32 @shell_sort(i32* %10, i32 %0)
%50 = tail call i32 (...) @clock()
%51 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%52 = tail call i32 @get_time(i32 %48, i32 %50)
%53 = tail call i32 @memset(i32* %10, i32 0, i32 %2)
%54 = tail call i32 @memcpy(i32* %10, i32* %4, i32 %2)
%55 = tail call i32 (...) @clock()
%56 = tail call i32 @quick_sort(i32* %10, i32 0, i32 %27)
%57 = tail call i32 (...) @clock()
%58 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%59 = tail call i32 @get_time(i32 %55, i32 %57)
%60 = tail call i32 @memset(i32* %10, i32 0, i32 %2)
%61 = tail call i32 @memcpy(i32* %10, i32* %4, i32 %2)
%62 = tail call i32 (...) @clock()
%63 = tail call i32 @heap_sort(i32* %10, i32 %0)
%64 = tail call i32 (...) @clock()
%65 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%66 = tail call i32 @get_time(i32 %62, i32 %64)
%67 = tail call i32 @free(i32* %4)
%68 = tail call i32 @free(i32* %10)
br label %69
69: ; preds = %14, %12, %6
%70 = phi i32 [ -1, %6 ], [ -1, %12 ], [ 0, %14 ]
ret i32 %70
}