#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 /*<<< orphan*/ bucket_sort(int *, int);
int hash(int, int);
int /*<<< orphan*/ print(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int arr[] = {3,  24, 78, 98, 6,  12, 45, 68, 11, 15, 10, 49, 79, 13,
               36, 9,  30, 25, 1,  9,  89, 75, 64, 23, 41, 82, 42, 83,
               13, 11, 64, 16, 81, 4,  17, 12, 67, 80, 21, 36};
  int length = 40;
  printf("比较均匀的分配各元素到不同的桶里：\n");
  for (int i = 0; i < length; i++) {
    printf("%d\t", hash(arr[i], length / 5));
  }
  printf("\n\n");
  bucket_sort(arr, length);
  print(arr, length);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xb0(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0xa0,%edx
call   1070 <memcpy@plt>
movl   $0x28,-0xb4(%rbp)
lea    0xf15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    11f5 <main+0xa5>
movslq -0xb8(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%edi
mov    -0xb4(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1030 <hash@plt>
mov    %eax,%esi
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    119c <main+0x4c>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
call   1060 <bucket_sort@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
call   1050 <print@plt>
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xa8,%rsp
lea    0xe8f(%rip),%rsi
mov    %rsp,%rdi
mov    $0xa0,%edx
call   1080 <memcpy@plt>
lea    0xf1f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
mov    $0x8,%esi
call   1040 <hash@plt>
lea    0xf00(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,4),%edi
mov    $0x8,%esi
call   1040 <hash@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0x28,%rbx
jne    11c0 <main+0x60>
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x28,%esi
call   1070 <bucket_sort@plt>
mov    %rbx,%rdi
mov    $0x28,%esi
call   1060 <print@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.arr = [40 x i32] [i32 3, i32 24, i32 78, i32 98, i32 6, i32 12, i32 45, i32 68, i32 11, i32 15, i32 10, i32 49, i32 79, i32 13, i32 36, i32 9, i32 30, i32 25, i32 1, i32 9, i32 89, i32 75, i32 64, i32 23, i32 41, i32 82, i32 42, i32 83, i32 13, i32 11, i32 64, i32 16, i32 81, i32 4, i32 17, i32 12, i32 67, i32 80, i32 21, i32 36]
@.str = [53 x i8] c"\E6\AF\94\E8\BE\83\E5\9D\87\E5\8C\80\E7\9A\84\E5\88\86\E9\85\8D\E5\90\84\E5\85\83\E7\B4\A0\E5\88\B0\E4\B8\8D\E5\90\8C\E7\9A\84\E6\A1\B6\E9\87\8C\EF\BC\9A\0A\00"
@.str.1 = [4 x i8] c"%d\09\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [40 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [40 x i32]* %2 to i8*
store i32 40, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %4
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 5
%18 = call i32 @hash(i32 %15, i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %11
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %7
23: ; preds = %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %3
%27 = call i32 @bucket_sort(i32* %25, i32 %26)
%28 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 0
%29 = load i32, i32* %3
%30 = call i32 @print(i32* %28, i32 %29)
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@__const.main.arr = [40 x i32] [i32 3, i32 24, i32 78, i32 98, i32 6, i32 12, i32 45, i32 68, i32 11, i32 15, i32 10, i32 49, i32 79, i32 13, i32 36, i32 9, i32 30, i32 25, i32 1, i32 9, i32 89, i32 75, i32 64, i32 23, i32 41, i32 82, i32 42, i32 83, i32 13, i32 11, i32 64, i32 16, i32 81, i32 4, i32 17, i32 12, i32 67, i32 80, i32 21, i32 36]
@.str.1 = [4 x i8] c"%d\09\00"
@str = [52 x i8] c"\E6\AF\94\E8\BE\83\E5\9D\87\E5\8C\80\E7\9A\84\E5\88\86\E9\85\8D\E5\90\84\E5\85\83\E7\B4\A0\E5\88\B0\E4\B8\8D\E5\90\8C\E7\9A\84\E6\A1\B6\E9\87\8C\EF\BC\9A\00"
@str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [40 x i32]
%2 = bitcast [40 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @hash(i32 3, i32 8)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %11
6: ; preds = %11
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.3, i64 0, i64 0))
%8 = getelementptr inbounds [40 x i32], [40 x i32]* %1, i64 0, i64 0
%9 = call i32 @bucket_sort(i32* %8, i32 40)
%10 = call i32 @print(i32* %8, i32 40)
ret i32 0
11: ; preds = %0, %11
%12 = phi i64 [ 1, %0 ], [ %17, %11 ]
%13 = getelementptr inbounds [40 x i32], [40 x i32]* %1, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = tail call i32 @hash(i32 %14, i32 8)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, 40
br i1 %18, label %6, label %11
}