#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*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sort_double(double *, int);
void test_algorithm() {
  double *data = (double *)malloc(5 * sizeof(double));
  if (!data) {
    printf("BAD. no memory left. :(\n");
    return;
  }
  data[0] = 3;
  data[1] = 8;
  data[2] = 4;
  data[3] = 6;
  data[4] = 7;
  int i = 0;
  printf("before sort:\n");
  for (i = 0; i < 5; i++)
    printf("%f ", data[i]);
  printf("\n");
  sort_double(data, 5);
  printf("after sort:\n");
  for (i = 0; i < 5; i++) {
    printf("%f ", data[i]);
  }
  printf("\n");
  free(data);
}


x86 assembly (clang, -O0):
<test_algorithm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1174 <test_algorithm+0x34>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1292 <test_algorithm+0x152>
mov    -0x8(%rbp),%rax
movsd  0xea0(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe88(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe6f(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe56(%rip),%xmm0
movsd  %xmm0,0x18(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe3d(%rip),%xmm0
movsd  %xmm0,0x20(%rax)
movl   $0x0,-0xc(%rbp)
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    1217 <test_algorithm+0xd7>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe4d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e4 <test_algorithm+0xa4>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x5,%esi
call   1050 <sort_double@plt>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    127b <test_algorithm+0x13b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xde9(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1248 <test_algorithm+0x108>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_algorithm>:
push   %r14
push   %rbx
push   %rax
mov    $0x28,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1280 <test_algorithm+0x120>
mov    %rax,%rbx
movaps 0xe7f(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe85(%rip),%xmm0
movups %xmm0,0x10(%rax)
movabs $0x401c000000000000,%rax
mov    %rax,0x20(%rbx)
lea    0xe98(%rip),%rdi
call   1050 <puts@plt>
movsd  (%rbx),%xmm0
lea    0xe6c(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x8(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x10(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x18(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x20(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1070 <sort_double@plt>
lea    0xe31(%rip),%rdi
call   1050 <puts@plt>
movsd  (%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x8(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x10(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x18(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x20(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
lea    0xd9d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <puts@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"BAD. no memory left. :(\0A\00"
@.str.1 = [14 x i8] c"before sort:\0A\00"
@.str.2 = [4 x i8] c"%f \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [13 x i8] c"after sort:\0A\00"
define void @test_algorithm() {
%1 = alloca double*
%2 = alloca i32
%3 = call i64 @malloc(i32 40)
%4 = inttoptr i64 %3 to double*
store double* %4, double** %1
%5 = load double*, double** %1
%6 = icmp ne double* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %56
9: ; preds = %0
%10 = load double*, double** %1
%11 = getelementptr inbounds double, double* %10, i64 0
store double 3.000000e+00, double* %11
%12 = load double*, double** %1
%13 = getelementptr inbounds double, double* %12, i64 1
store double 8.000000e+00, double* %13
%14 = load double*, double** %1
%15 = getelementptr inbounds double, double* %14, i64 2
store double 4.000000e+00, double* %15
%16 = load double*, double** %1
%17 = getelementptr inbounds double, double* %16, i64 3
store double 6.000000e+00, double* %17
%18 = load double*, double** %1
%19 = getelementptr inbounds double, double* %18, i64 4
store double 7.000000e+00, double* %19
store i32 0, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %21
21: ; preds = %31, %9
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 5
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load double*, double** %1
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %29)
br label %31
31: ; preds = %24
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %21
34: ; preds = %21
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = load double*, double** %1
%37 = call i32 @sort_double(double* %36, i32 5)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %39
39: ; preds = %49, %34
%40 = load i32, i32* %2
%41 = icmp slt i32 %40, 5
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = load double*, double** %1
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %39
52: ; preds = %39
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%54 = load double*, double** %1
%55 = call i32 @free(double* %54)
br label %56
56: ; preds = %52, %7
ret void
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c"%f \00"
@str = [24 x i8] c"BAD. no memory left. :(\00"
@str.5 = [13 x i8] c"before sort:\00"
@str.6 = [12 x i8] c"after sort:\00"
define void @test_algorithm() {
%1 = tail call i64 @malloc(i32 40)
%2 = inttoptr i64 %1 to double*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %39
6: ; preds = %0
%7 = getelementptr inbounds double, double* %2, i64 1
%8 = inttoptr i64 %1 to <2 x double>*
store <2 x double> <double 3.000000e+00, double 8.000000e+00>, <2 x double>* %8
%9 = getelementptr inbounds double, double* %2, i64 2
%10 = getelementptr inbounds double, double* %2, i64 3
%11 = bitcast double* %9 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 6.000000e+00>, <2 x double>* %11
%12 = getelementptr inbounds double, double* %2, i64 4
store double 7.000000e+00, double* %12
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
%14 = load double, double* %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %14)
%16 = load double, double* %7
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %16)
%18 = load double, double* %9
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %18)
%20 = load double, double* %10
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %20)
%22 = load double, double* %12
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %22)
%24 = tail call i32 @putchar(i32 10)
%25 = tail call i32 @sort_double(double* %2, i32 5)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
%27 = load double, double* %2
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %27)
%29 = load double, double* %7
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %29)
%31 = load double, double* %9
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %31)
%33 = load double, double* %10
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %33)
%35 = load double, double* %12
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %35)
%37 = tail call i32 @putchar(i32 10)
%38 = tail call i32 @free(double* %2)
br label %39
39: ; preds = %6, %4
ret void
}