#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 */
scalar_t__ is_sorted(int *, int);
int /*<<< orphan*/ print(int *, int);
int /*<<< orphan*/ printf(char *, ...);
void check_array_and_print(int *array, int size, int code) {
  switch (code) {
  case 1:
    printf("selection sort:\n");
    break;
  case 2:
    printf("bubble sort:\n");
    break;
  case 3:
    printf("insertion sort:\n");
    break;
  case 4:
    printf("merge sort:\n");
    break;
  case 5:
    printf("quick sort:\n");
    break;
  case 6:
    printf("counting sort:\n");
    break;
  default:
    printf("unsorted array:\n");
    break;
  }
  print(array, size);
  printf("The array is %s\n\n", is_sorted(array, size) ? "sorted" : "unsorted");
}


x86 assembly (clang, -O0):
<check_array_and_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     11dd <check_array_and_print+0xad>
mov    -0x18(%rbp),%rax
lea    0xe9e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11eb <check_array_and_print+0xbb>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11eb <check_array_and_print+0xbb>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11eb <check_array_and_print+0xbb>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11eb <check_array_and_print+0xbb>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11eb <check_array_and_print+0xbb>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11eb <check_array_and_print+0xbb>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <print@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <is_sorted@plt>
mov    %rax,%rcx
lea    0xe88(%rip),%rsi
lea    0xe83(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_array_and_print>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0xffffffff,%edx
cmp    $0x5,%edx
ja     1163 <check_array_and_print+0x23>
movslq %edx,%rax
lea    0xf26(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    116a <check_array_and_print+0x2a>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <print@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <is_sorted@plt>
test   %rax,%rax
lea    0xe85(%rip),%rax
lea    0xe80(%rip),%rsi
cmove  %rax,%rsi
lea    0xe61(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"selection sort:\0A\00"
@.str.1 = [14 x i8] c"bubble sort:\0A\00"
@.str.2 = [17 x i8] c"insertion sort:\0A\00"
@.str.3 = [13 x i8] c"merge sort:\0A\00"
@.str.4 = [13 x i8] c"quick sort:\0A\00"
@.str.5 = [16 x i8] c"counting sort:\0A\00"
@.str.6 = [17 x i8] c"unsorted array:\0A\00"
@.str.7 = [18 x i8] c"The array is %s\0A\0A\00"
@.str.8 = [7 x i8] c"sorted\00"
@.str.9 = [9 x i8] c"unsorted\00"
define void @check_array_and_print(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
switch i32 %7, 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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %22
10: ; preds = %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %22
12: ; preds = %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %22
14: ; preds = %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %22
16: ; preds = %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %22
18: ; preds = %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %22
20: ; preds = %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %22
22: ; preds = %20, %18, %16, %14, %12, %10, %8
%23 = load i32*, i32** %4
%24 = load i32, i32* %5
%25 = call i32 @print(i32* %23, i32 %24)
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = call i64 @is_sorted(i32* %26, i32 %27)
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %31)
ret void
}

LLVM IR (-O2):
@.str.7 = [18 x i8] c"The array is %s\0A\0A\00"
@.str.8 = [7 x i8] c"sorted\00"
@.str.9 = [9 x i8] c"unsorted\00"
@str = [15 x i8] c"counting sort:\00"
@str.10 = [12 x i8] c"quick sort:\00"
@str.11 = [12 x i8] c"merge sort:\00"
@str.12 = [16 x i8] c"insertion sort:\00"
@str.13 = [13 x i8] c"bubble sort:\00"
@str.14 = [16 x i8] c"selection sort:\00"
@str.15 = [16 x i8] c"unsorted array:\00"
@reltable.check_array_and_print = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @str.14 to i64), i64 ptrtoint ([6 x i32]* @reltable.check_array_and_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.13 to i64), i64 ptrtoint ([6 x i32]* @reltable.check_array_and_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.check_array_and_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @str.11 to i64), i64 ptrtoint ([6 x i32]* @reltable.check_array_and_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @str.10 to i64), i64 ptrtoint ([6 x i32]* @reltable.check_array_and_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @str to i64), i64 ptrtoint ([6 x i32]* @reltable.check_array_and_print to i64)) to i32)]
define void @check_array_and_print(i32* %0, i32 %1, i32 %2) {
%4 = add i32 %2, -1
%5 = icmp ult i32 %4, 6
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = sext i32 %4 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.check_array_and_print to i8*), i64 %8)
br label %10
10: ; preds = %3, %6
%11 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.15, i64 0, i64 0), %3 ]
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
%13 = tail call i32 @print(i32* %0, i32 %1)
%14 = tail call i64 @is_sorted(i32* %0, i32 %1)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %16)
ret void
}