#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 */
double *malloc(int);
int /*<<< orphan*/ print(double *);
int /*<<< orphan*/ printf(char *);
double random();
int /*<<< orphan*/ selection_sort(double *, int const);
void test_sort(void) {
  const int size = 10;
  double *list = malloc(sizeof(double));
  int i = 0;
  for (; i < size; i++)
    list[i] = random();
  print(list);
  printf("\n");
  selection_sort(list, size);
  print(list);
}


x86 assembly (clang, -O0):
<test_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xa,-0x4(%rbp)
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11a0 <test_sort+0x50>
mov    $0x0,%al
call   1060 <random@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1174 <test_sort+0x24>
mov    -0x10(%rbp),%rdi
call   1050 <print@plt>
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <selection_sort@plt>
mov    -0x10(%rbp),%rdi
call   1050 <print@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sort>:
push   %rbx
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,0x8(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,0x10(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,0x18(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,0x20(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,0x28(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,0x30(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,0x38(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,0x40(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
movsd  %xmm0,0x48(%rbx)
mov    %rbx,%rdi
call   1050 <print@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <selection_sort@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <print@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @test_sort() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca i32
store i32 10, i32* %1
%4 = call double* @malloc(i32 8)
store double* %4, double** %2
store i32 0, i32* %3
br label %5
5: ; preds = %14, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = call double (...) @random()
%10 = load double*, double** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds double, double* %10, i64 %12
store double %9, double* %13
br label %14
14: ; preds = %8
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %5
17: ; preds = %5
%18 = load double*, double** %2
%19 = call i32 @print(double* %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load double*, double** %2
%22 = call i32 @selection_sort(double* %21, i32 10)
%23 = load double*, double** %2
%24 = call i32 @print(double* %23)
ret void
}

LLVM IR (-O2):
define void @test_sort() {
%1 = tail call double* @malloc(i32 8)
%2 = tail call double (...) @random()
store double %2, double* %1
%3 = tail call double (...) @random()
%4 = getelementptr inbounds double, double* %1, i64 1
store double %3, double* %4
%5 = tail call double (...) @random()
%6 = getelementptr inbounds double, double* %1, i64 2
store double %5, double* %6
%7 = tail call double (...) @random()
%8 = getelementptr inbounds double, double* %1, i64 3
store double %7, double* %8
%9 = tail call double (...) @random()
%10 = getelementptr inbounds double, double* %1, i64 4
store double %9, double* %10
%11 = tail call double (...) @random()
%12 = getelementptr inbounds double, double* %1, i64 5
store double %11, double* %12
%13 = tail call double (...) @random()
%14 = getelementptr inbounds double, double* %1, i64 6
store double %13, double* %14
%15 = tail call double (...) @random()
%16 = getelementptr inbounds double, double* %1, i64 7
store double %15, double* %16
%17 = tail call double (...) @random()
%18 = getelementptr inbounds double, double* %1, i64 8
store double %17, double* %18
%19 = tail call double (...) @random()
%20 = getelementptr inbounds double, double* %1, i64 9
store double %19, double* %20
%21 = tail call i32 @print(double* %1)
%22 = tail call i32 @putchar(i32 10)
%23 = tail call i32 @selection_sort(double* %1, i32 10)
%24 = tail call i32 @print(double* %1)
ret void
}