#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(void *);
void *malloc(unsigned int);
int /*<<< orphan*/ sort_swp(void *, void *, unsigned int, void *);
void sort_insert(void *array, unsigned int length, unsigned int el_size,
                 int (*comp)(const void *, const void *)) {
  void *compPtr = NULL;
  void *compPtrSmall = NULL;
  void *hold = malloc(el_size);
  for (int i = 0; i < length; i++) {
    int curr = i;
    compPtr = array;
    compPtrSmall = ((char *)array) - el_size;
    while (curr > 0) {
      if (comp(compPtrSmall, compPtr) > 0) {
        sort_swp(compPtrSmall, compPtr, el_size, hold);
        compPtr = ((char *)compPtr) - el_size;
        compPtrSmall = ((char *)compPtrSmall) - el_size;
        curr--;
        continue;
      }
      break;
    }
    array = ((char *)array) + el_size;
  }
  free(hold);
}


x86 assembly (clang, -O0):
<sort_insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1226 <sort_insert+0xf6>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    120a <sort_insert+0xda>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jle    1205 <sort_insert+0xd5>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1040 <sort_swp@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    1198 <sort_insert+0x68>
jmp    120a <sort_insert+0xda>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1169 <sort_insert+0x39>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_insert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x20(%rsp)
mov    %esi,%ebx
mov    %rdi,0x10(%rsp)
mov    %edx,%r13d
mov    %edx,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %ebx,0x8(%rsp)
test   %ebx,%ebx
je     11e2 <sort_insert+0xb2>
mov    %r13d,%r15d
mov    %r15,0x18(%rsp)
neg    %r15
xor    %eax,%eax
movl   $0x1,0x4(%rsp)
jmp    119c <sort_insert+0x6c>
nopw   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rax
add    %rax,0x10(%rsp)
mov    0xc(%rsp),%eax
add    $0x1,%eax
addl   $0x1,0x4(%rsp)
cmp    0x8(%rsp),%eax
je     11e2 <sort_insert+0xb2>
mov    %eax,0xc(%rsp)
test   %eax,%eax
je     1180 <sort_insert+0x50>
mov    0x4(%rsp),%r12d
mov    0x10(%rsp),%rbx
xchg   %ax,%ax
lea    (%rbx,%r15,1),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   *0x20(%rsp)
test   %eax,%eax
jle    1180 <sort_insert+0x50>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
mov    %rbp,%rcx
call   1040 <sort_swp@plt>
add    $0xffffffff,%r12d
mov    %r14,%rbx
cmp    $0x1,%r12d
jg     11b0 <sort_insert+0x80>
jmp    1180 <sort_insert+0x50>
mov    %rbp,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @sort_insert(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32 (i8*, i8*)*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %8
store i8* null, i8** %9
store i8* null, i8** %10
%14 = load i32, i32* %7
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %11
store i32 0, i32* %12
br label %16
16: ; preds = %61, %4
%17 = load i32, i32* %12
%18 = load i32, i32* %6
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %64
20: ; preds = %16
%21 = load i32, i32* %12
store i32 %21, i32* %13
%22 = load i8*, i8** %5
store i8* %22, i8** %9
%23 = load i8*, i8** %5
%24 = load i32, i32* %7
%25 = zext i32 %24 to i64
%26 = sub i64 0, %25
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8* %27, i8** %10
br label %28
28: ; preds = %37, %20
%29 = load i32, i32* %13
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %56
31: ; preds = %28
%32 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%33 = load i8*, i8** %10
%34 = load i8*, i8** %9
%35 = call i32 %32(i8* %33, i8* %34)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %55
37: ; preds = %31
%38 = load i8*, i8** %10
%39 = load i8*, i8** %9
%40 = load i32, i32* %7
%41 = load i8*, i8** %11
%42 = call i32 @sort_swp(i8* %38, i8* %39, i32 %40, i8* %41)
%43 = load i8*, i8** %9
%44 = load i32, i32* %7
%45 = zext i32 %44 to i64
%46 = sub i64 0, %45
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8* %47, i8** %9
%48 = load i8*, i8** %10
%49 = load i32, i32* %7
%50 = zext i32 %49 to i64
%51 = sub i64 0, %50
%52 = getelementptr inbounds i8, i8* %48, i64 %51
store i8* %52, i8** %10
%53 = load i32, i32* %13
%54 = add nsw i32 %53, -1
store i32 %54, i32* %13
br label %28
55: ; preds = %31
br label %56
56: ; preds = %55, %28
%57 = load i8*, i8** %5
%58 = load i32, i32* %7
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8* %60, i8** %5
br label %61
61: ; preds = %56
%62 = load i32, i32* %12
%63 = add nsw i32 %62, 1
store i32 %63, i32* %12
br label %16
64: ; preds = %16
%65 = load i8*, i8** %11
%66 = call i32 @free(i8* %65)
ret void
}

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