#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__ compare_elements_helper(void *, size_t, int, int,
                                   int (*)(void const *, void const *));
int /*<<< orphan*/ exchange_elements_helper(void *, size_t, int, int);
__attribute__((__weak__)) void
my_qsort(void *base, size_t num_elements, size_t element_size,
         int (*comparer)(const void *, const void *)) {
  size_t i;
  for (i = 0; i < num_elements; i++) {
    int j;
    for (j = i - 1; j >= 0; j--) {
      if ((compare_elements_helper(base, element_size, (j), (j + 1), comparer) <
           0))
        break;
      (exchange_elements_helper(base, element_size, (j), (j + 1)));
    }
  }
}


x86 assembly (clang, -O0):
<my_qsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11c6 <my_qsort+0xa6>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11b0 <my_qsort+0x90>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%r8
call   1030 <compare_elements_helper@plt>
cmp    $0x0,%rax
jge    118c <my_qsort+0x6c>
jmp    11b0 <my_qsort+0x90>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
call   1040 <exchange_elements_helper@plt>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    1159 <my_qsort+0x39>
jmp    11b5 <my_qsort+0x95>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1140 <my_qsort+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_qsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1181 <my_qsort+0x61>
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r13
xor    %ebp,%ebp
jmp    1149 <my_qsort+0x29>
add    $0x1,%rbp
cmp    %r15,%rbp
je     1181 <my_qsort+0x61>
mov    %ebp,%edx
add    $0xffffffff,%edx
js     1140 <my_qsort+0x20>
lea    0x1(%rdx),%ebx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%ecx
mov    %r14,%r8
call   1030 <compare_elements_helper@plt>
test   %rax,%rax
js     1140 <my_qsort+0x20>
lea    -0x1(%rbx),%edx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%ecx
call   1040 <exchange_elements_helper@plt>
add    $0xfffffffe,%ebx
mov    %ebx,%edx
jns    1150 <my_qsort+0x30>
jmp    1140 <my_qsort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define weak void @my_qsort(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32 (i8*, i8*)*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %8
store i64 0, i64* %9
br label %11
11: ; preds = %43, %4
%12 = load i64, i64* %9
%13 = load i64, i64* %6
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %46
15: ; preds = %11
%16 = load i64, i64* %9
%17 = sub i64 %16, 1
%18 = trunc i64 %17 to i32
store i32 %18, i32* %10
br label %19
19: ; preds = %39, %15
%20 = load i32, i32* %10
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %42
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = load i64, i64* %7
%25 = load i32, i32* %10
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
%28 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%29 = call i64 @compare_elements_helper(i8* %23, i64 %24, i32 %25, i32 %27, i32 (i8*, i8*)* %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %22
br label %42
32: ; preds = %22
%33 = load i8*, i8** %5
%34 = load i64, i64* %7
%35 = load i32, i32* %10
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
%38 = call i32 @exchange_elements_helper(i8* %33, i64 %34, i32 %35, i32 %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %10
%41 = add nsw i32 %40, -1
store i32 %41, i32* %10
br label %19
42: ; preds = %31, %19
br label %43
43: ; preds = %42
%44 = load i64, i64* %9
%45 = add i64 %44, 1
store i64 %45, i64* %9
br label %11
46: ; preds = %11
ret void
}

LLVM IR (-O2):
define weak void @my_qsort(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = icmp eq i64 %1, 0
br i1 %5, label %23, label %6
6: ; preds = %4, %20
%7 = phi i64 [ %21, %20 ], [ 0, %4 ]
%8 = trunc i64 %7 to i32
%9 = add i32 %8, -1
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %20
11: ; preds = %6, %16
%12 = phi i32 [ %18, %16 ], [ %9, %6 ]
%13 = phi i32 [ %12, %16 ], [ %8, %6 ]
%14 = tail call i64 @compare_elements_helper(i8* %0, i64 %2, i32 %12, i32 %13, i32 (i8*, i8*)* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = tail call i32 @exchange_elements_helper(i8* %0, i64 %2, i32 %12, i32 %13)
%18 = add i32 %12, -1
%19 = icmp sgt i32 %18, -1
br i1 %19, label %11, label %20
20: ; preds = %16, %11, %6
%21 = add nuw i64 %7, 1
%22 = icmp eq i64 %21, %1
br i1 %22, label %23, label %6
23: ; preds = %20, %4
ret void
}