#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*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ qsort(double *, size_t, size_t,
                         int (*)(void const *, void const *));
int rs_rainflow_sort_cycles(double *buffer, size_t count, size_t size,
                            int (*compare)(void const *, void const *)) {
  if (buffer == NULL || compare == NULL) {
    errno = EINVAL;
    return -1;
  }
  if (count > 1)
    qsort(buffer, count, size, compare);
  return 0;
}


x86 assembly (clang, -O0):
<rs_rainflow_sort_cycles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     113e <rs_rainflow_sort_cycles+0x2e>
cmpq   $0x0,-0x28(%rbp)
jne    115c <rs_rainflow_sort_cycles+0x4c>
mov    0x2e93(%rip),%rax
mov    (%rax),%ecx
mov    0x2e92(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <rs_rainflow_sort_cycles+0x73>
cmpq   $0x1,-0x18(%rbp)
jbe    117c <rs_rainflow_sort_cycles+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <qsort@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rs_rainflow_sort_cycles>:
push   %rbx
test   %rdi,%rdi
je     112a <rs_rainflow_sort_cycles+0x1a>
test   %rcx,%rcx
je     112a <rs_rainflow_sort_cycles+0x1a>
xor    %ebx,%ebx
cmp    $0x2,%rsi
jb     1141 <rs_rainflow_sort_cycles+0x31>
call   1030 <qsort@plt>
jmp    1141 <rs_rainflow_sort_cycles+0x31>
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    0x2ea6(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @rs_rainflow_sort_cycles(double* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32 (i8*, i8*)*
store double* %0, double** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %9
%10 = load double*, double** %6
%11 = icmp eq double* %10, null
br i1 %11, label %15, label %12
12: ; preds = %4
%13 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %9
%14 = icmp eq i32 (i8*, i8*)* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12, %4
%16 = load i32, i32* @EINVAL
store i32 %16, i32* @errno
store i32 -1, i32* %5
br label %27
17: ; preds = %12
%18 = load i64, i64* %7
%19 = icmp ugt i64 %18, 1
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load double*, double** %6
%22 = load i64, i64* %7
%23 = load i64, i64* %8
%24 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %9
%25 = call i32 @qsort(double* %21, i64 %22, i64 %23, i32 (i8*, i8*)* %24)
br label %26
26: ; preds = %20, %17
store i32 0, i32* %5
br label %27
27: ; preds = %26, %15
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @rs_rainflow_sort_cycles(double* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = icmp eq double* %0, null
%6 = icmp eq i32 (i8*, i8*)* %3, null
%7 = or i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
br label %14
10: ; preds = %4
%11 = icmp ugt i64 %1, 1
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @qsort(double* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3)
br label %14
14: ; preds = %10, %12, %8
%15 = phi i32 [ -1, %8 ], [ 0, %12 ], [ 0, %10 ]
ret i32 %15
}