#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*/ B;
typedef int /*<<< orphan*/ A;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ select_sort(int *, int);
void select_sort_test() {
  int A[] = {5, 4, 1, 8, 2, 6, 0, 9, 7, 3};
  int s1 = sizeof(A) / sizeof(int);
  select_sort(A, s1);
  for (int i = 0; i < s1; ++i) {
    assert(A[i] == i);
  }
  int B[] = {1, 4, 5, 8, 7, 6, 3, 2, 0};
  int s2 = sizeof(B) / sizeof(int);
  select_sort(B, s2);
  for (int i = 0; i < s2; ++i) {
    assert(B[i] == i);
  }
}


x86 assembly (clang, -O0):
<select_sort_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x30(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movl   $0xa,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <select_sort@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1199 <select_sort_test+0x69>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
cmp    -0x38(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1167 <select_sort_test+0x37>
lea    -0x60(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x24,%edx
call   1040 <memcpy@plt>
movl   $0x9,-0x64(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1050 <select_sort@plt>
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    11fa <select_sort_test+0xca>
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
cmp    -0x68(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11c8 <select_sort_test+0x98>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_sort_test>:
sub    $0x58,%rsp
mov    0xef5(%rip),%rax
mov    %rax,0x50(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x30(%rsp),%rdi
mov    $0xa,%esi
call   1040 <select_sort@plt>
xor    %edi,%edi
cmpl   $0x0,0x30(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x1,0x34(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x2,0x38(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x3,0x3c(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x4,0x40(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x5,0x44(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x6,0x48(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x7,0x4c(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x8,0x50(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x9,0x54(%rsp)
sete   %dil
call   1030 <assert@plt>
mov    0xe53(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xe38(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe1c(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x9,%esi
call   1040 <select_sort@plt>
xor    %edi,%edi
cmpl   $0x0,(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x1,0x4(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x2,0x8(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x3,0xc(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x4,0x10(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x5,0x14(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x6,0x18(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x7,0x1c(%rsp)
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x8,0x20(%rsp)
sete   %dil
call   1030 <assert@plt>
add    $0x58,%rsp
ret

LLVM IR (-O0):
@__const.select_sort_test.A = [10 x i32] [i32 5, i32 4, i32 1, i32 8, i32 2, i32 6, i32 0, i32 9, i32 7, i32 3]
@__const.select_sort_test.B = [9 x i32] [i32 1, i32 4, i32 5, i32 8, i32 7, i32 6, i32 3, i32 2, i32 0]
define void @select_sort_test() {
%1 = alloca [10 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca [9 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [10 x i32]* %1 to i8*
store i32 10, i32* %2
%8 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @select_sort(i32* %8, i32 %9)
store i32 0, i32* %3
br label %11
11: ; preds = %24, %0
%12 = load i32, i32* %3
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %3
%21 = icmp eq i32 %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
br label %24
24: ; preds = %15
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %11
27: ; preds = %11
%28 = bitcast [9 x i32]* %4 to i8*
store i32 9, i32* %5
%29 = getelementptr inbounds [9 x i32], [9 x i32]* %4, i64 0, i64 0
%30 = load i32, i32* %5
%31 = call i32 @select_sort(i32* %29, i32 %30)
store i32 0, i32* %6
br label %32
32: ; preds = %45, %27
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [9 x i32], [9 x i32]* %4, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %6
%42 = icmp eq i32 %40, %41
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
br label %45
45: ; preds = %36
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %32
48: ; preds = %32
ret void
}

LLVM IR (-O2):
@__const.select_sort_test.A = [10 x i32] [i32 5, i32 4, i32 1, i32 8, i32 2, i32 6, i32 0, i32 9, i32 7, i32 3]
@__const.select_sort_test.B = [9 x i32] [i32 1, i32 4, i32 5, i32 8, i32 7, i32 6, i32 3, i32 2, i32 0]
define void @select_sort_test() {
%1 = alloca [10 x i32]
%2 = alloca [9 x i32]
%3 = bitcast [10 x i32]* %1 to i8*
%4 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%5 = call i32 @select_sort(i32* %4, i32 10)
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 1
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 2
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 3
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 4
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 5
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 6
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 7
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 8
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, 9
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = bitcast [9 x i32]* %2 to i8*
%56 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%57 = call i32 @select_sort(i32* %56, i32 9)
%58 = load i32, i32* %56
%59 = icmp eq i32 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 1
%63 = load i32, i32* %62
%64 = icmp eq i32 %63, 1
%65 = zext i1 %64 to i32
%66 = call i32 @assert(i32 %65)
%67 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 2
%68 = load i32, i32* %67
%69 = icmp eq i32 %68, 2
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 3
%73 = load i32, i32* %72
%74 = icmp eq i32 %73, 3
%75 = zext i1 %74 to i32
%76 = call i32 @assert(i32 %75)
%77 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 4
%78 = load i32, i32* %77
%79 = icmp eq i32 %78, 4
%80 = zext i1 %79 to i32
%81 = call i32 @assert(i32 %80)
%82 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 5
%83 = load i32, i32* %82
%84 = icmp eq i32 %83, 5
%85 = zext i1 %84 to i32
%86 = call i32 @assert(i32 %85)
%87 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 6
%88 = load i32, i32* %87
%89 = icmp eq i32 %88, 6
%90 = zext i1 %89 to i32
%91 = call i32 @assert(i32 %90)
%92 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 7
%93 = load i32, i32* %92
%94 = icmp eq i32 %93, 7
%95 = zext i1 %94 to i32
%96 = call i32 @assert(i32 %95)
%97 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 8
%98 = load i32, i32* %97
%99 = icmp eq i32 %98, 8
%100 = zext i1 %99 to i32
%101 = call i32 @assert(i32 %100)
ret void
}