#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*/ check_array_and_print(int *, int, int);
int /*<<< orphan*/ destroy_array(int **, int);
int *generate_array(int, int);
int /*<<< orphan*/ sort_bubble(int *, int);
int /*<<< orphan*/ sort_counting(int *, int);
int /*<<< orphan*/ sort_insertion(int *, int);
int /*<<< orphan*/ sort_merge(int *, int);
int /*<<< orphan*/ sort_quick(int *, int);
int /*<<< orphan*/ sort_selection(int *, int);
void test(int size, int max, int code) {
  int *array;
  array = generate_array(size, max);
  check_array_and_print(array, size, 0);
  switch (code) {
  case 1:
    sort_selection(array, size);
    break;
  case 2:
    sort_bubble(array, size);
    break;
  case 3:
    sort_insertion(array, size);
    break;
  case 4:
    sort_merge(array, size);
    break;
  case 5:
    sort_quick(array, size);
    break;
  case 6:
    sort_counting(array, size);
    break;
  default:
    break;
  }
  check_array_and_print(array, size, code);
  destroy_array(&array, size);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10b0 <generate_array@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
xor    %edx,%edx
call   1040 <check_array_and_print@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     124d <test+0xbd>
mov    -0x20(%rbp),%rax
lea    0xe22(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1090 <sort_selection@plt>
jmp    1252 <test+0xc2>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1030 <sort_bubble@plt>
jmp    1252 <test+0xc2>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   10a0 <sort_insertion@plt>
jmp    1252 <test+0xc2>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1070 <sort_merge@plt>
jmp    1252 <test+0xc2>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1050 <sort_quick@plt>
jmp    1252 <test+0xc2>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <sort_counting@plt>
jmp    1252 <test+0xc2>
jmp    1252 <test+0xc2>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <check_array_and_print@plt>
mov    -0x4(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1080 <destroy_array@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %edi,%ebx
call   10b0 <generate_array@plt>
mov    %rax,%r15
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1040 <check_array_and_print@plt>
lea    -0x1(%r14),%eax
cmp    $0x5,%eax
ja     1216 <test+0x86>
lea    0xe39(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %r15,%rdi
mov    %ebx,%esi
call   1090 <sort_selection@plt>
jmp    1216 <test+0x86>
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <sort_bubble@plt>
jmp    1216 <test+0x86>
mov    %r15,%rdi
mov    %ebx,%esi
call   10a0 <sort_insertion@plt>
jmp    1216 <test+0x86>
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <sort_merge@plt>
jmp    1216 <test+0x86>
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <sort_quick@plt>
jmp    1216 <test+0x86>
mov    %r15,%rdi
mov    %ebx,%esi
call   1060 <sort_counting@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1040 <check_array_and_print@plt>
lea    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1080 <destroy_array@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @test(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = call i32* @generate_array(i32 %8, i32 %9)
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = load i32, i32* %4
%13 = call i32 @check_array_and_print(i32* %11, i32 %12, i32 0)
%14 = load i32, i32* %6
switch i32 %14, label %39 [
i32 1, label %15
i32 2, label %19
i32 3, label %23
i32 4, label %27
i32 5, label %31
i32 6, label %35
]
15: ; preds = %3
%16 = load i32*, i32** %7
%17 = load i32, i32* %4
%18 = call i32 @sort_selection(i32* %16, i32 %17)
br label %40
19: ; preds = %3
%20 = load i32*, i32** %7
%21 = load i32, i32* %4
%22 = call i32 @sort_bubble(i32* %20, i32 %21)
br label %40
23: ; preds = %3
%24 = load i32*, i32** %7
%25 = load i32, i32* %4
%26 = call i32 @sort_insertion(i32* %24, i32 %25)
br label %40
27: ; preds = %3
%28 = load i32*, i32** %7
%29 = load i32, i32* %4
%30 = call i32 @sort_merge(i32* %28, i32 %29)
br label %40
31: ; preds = %3
%32 = load i32*, i32** %7
%33 = load i32, i32* %4
%34 = call i32 @sort_quick(i32* %32, i32 %33)
br label %40
35: ; preds = %3
%36 = load i32*, i32** %7
%37 = load i32, i32* %4
%38 = call i32 @sort_counting(i32* %36, i32 %37)
br label %40
39: ; preds = %3
br label %40
40: ; preds = %39, %35, %31, %27, %23, %19, %15
%41 = load i32*, i32** %7
%42 = load i32, i32* %4
%43 = load i32, i32* %6
%44 = call i32 @check_array_and_print(i32* %41, i32 %42, i32 %43)
%45 = load i32, i32* %4
%46 = call i32 @destroy_array(i32** %7, i32 %45)
ret void
}

LLVM IR (-O2):
define void @test(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = bitcast i32** %4 to i8*
%6 = tail call i32* @generate_array(i32 %0, i32 %1)
store i32* %6, i32** %4
%7 = tail call i32 @check_array_and_print(i32* %6, i32 %0, i32 0)
switch i32 %2, label %20 [
i32 1, label %8
i32 2, label %10
i32 3, label %12
i32 4, label %14
i32 5, label %16
i32 6, label %18
]
8: ; preds = %3
%9 = tail call i32 @sort_selection(i32* %6, i32 %0)
br label %20
10: ; preds = %3
%11 = tail call i32 @sort_bubble(i32* %6, i32 %0)
br label %20
12: ; preds = %3
%13 = tail call i32 @sort_insertion(i32* %6, i32 %0)
br label %20
14: ; preds = %3
%15 = tail call i32 @sort_merge(i32* %6, i32 %0)
br label %20
16: ; preds = %3
%17 = tail call i32 @sort_quick(i32* %6, i32 %0)
br label %20
18: ; preds = %3
%19 = tail call i32 @sort_counting(i32* %6, i32 %0)
br label %20
20: ; preds = %3, %18, %16, %14, %12, %10, %8
%21 = tail call i32 @check_array_and_print(i32* %6, i32 %0, i32 %2)
%22 = call i32 @destroy_array(i32** %4, i32 %0)
ret void
}