#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*/ SWAP(int, int);
void insertion_sort(int objs[], unsigned int n, bool (*cmp)(int *x, int *y)) {
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = i; j > 0; j--)
      if (cmp(&objs[j], &objs[j - 1]))
        SWAP(objs[j], objs[j - 1]);
      else
        break;
  }
}


x86 assembly (clang, -O0):
<insertion_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11c8 <insertion_sort+0xb8>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11b5 <insertion_sort+0xa5>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rsi
call   *%rax
cmp    $0x0,%eax
je     119d <insertion_sort+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <SWAP@plt>
jmp    11a2 <insertion_sort+0x92>
jmp    11b5 <insertion_sort+0xa5>
jmp    11a7 <insertion_sort+0x97>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    113c <insertion_sort+0x2c>
jmp    11ba <insertion_sort+0xaa>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <insertion_sort+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertion_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
je     11b2 <insertion_sort+0xa2>
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%eax
mov    %rax,0x10(%rsp)
mov    $0x1,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %r12d,%r12d
jmp    1166 <insertion_sort+0x56>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
addq   $0x1,0x8(%rsp)
addq   $0x4,(%rsp)
cmp    0x10(%rsp),%r12
je     11b2 <insertion_sort+0xa2>
test   %r12d,%r12d
je     1150 <insertion_sort+0x40>
mov    (%rsp),%rbp
mov    0x8(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r15,%rbp,1),%rdi
lea    -0x2(%r13),%eax
lea    (%r15,%rax,4),%rbx
mov    %rbx,%rsi
call   *%r14
test   %eax,%eax
je     1150 <insertion_sort+0x40>
mov    -0x4(%r15,%r13,4),%edi
mov    (%rbx),%esi
call   1030 <SWAP@plt>
add    $0xffffffffffffffff,%r13
add    $0xfffffffffffffffc,%rbp
cmp    $0x1,%r13
jg     1180 <insertion_sort+0x70>
jmp    1150 <insertion_sort+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @insertion_sort(i32* %0, i32 %1, i32 (i32*, i32*)* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32 (i32*, i32*)*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 (i32*, i32*)* %2, i32 (i32*, i32*)** %6
store i32 0, i32* %7
br label %9
9: ; preds = %50, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %53
13: ; preds = %9
%14 = load i32, i32* %7
store i32 %14, i32* %8
br label %15
15: ; preds = %46, %13
%16 = load i32, i32* %8
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %49
18: ; preds = %15
%19 = load i32 (i32*, i32*)*, i32 (i32*, i32*)** %6
%20 = load i32*, i32** %4
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32*, i32** %4
%25 = load i32, i32* %8
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %24, i64 %27
%29 = call i32 %19(i32* %23, i32* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %44
31: ; preds = %18
%32 = load i32*, i32** %4
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = load i32*, i32** %4
%38 = load i32, i32* %8
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %37, i64 %40
%42 = load i32, i32* %41
%43 = call i32 @SWAP(i32 %36, i32 %42)
br label %45
44: ; preds = %18
br label %49
45: ; preds = %31
br label %46
46: ; preds = %45
%47 = load i32, i32* %8
%48 = add nsw i32 %47, -1
store i32 %48, i32* %8
br label %15
49: ; preds = %44, %15
br label %50
50: ; preds = %49
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %9
53: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @insertion_sort(i32* %0, i32 %1, i32 (i32*, i32*)* nocapture %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %27, label %5
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %24
%8 = phi i64 [ 0, %5 ], [ %25, %24 ]
%9 = trunc i64 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %7, %19
%12 = phi i64 [ %14, %19 ], [ %8, %7 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = add nsw i64 %12, -1
%15 = and i64 %14, 4294967295
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = tail call i32 %2(i32* %13, i32* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %11
%20 = load i32, i32* %13
%21 = load i32, i32* %16
%22 = tail call i32 @SWAP(i32 %20, i32 %21)
%23 = icmp sgt i64 %12, 1
br i1 %23, label %11, label %24
24: ; preds = %11, %19, %7
%25 = add nuw nsw i64 %8, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %27, label %7
27: ; preds = %24, %3
ret void
}