#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 findSmallestElement(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ isSort(int *, int /*<<< orphan*/, int);
int nIsSort(int *, int);
int /*<<< orphan*/ swapOfInsertionSortMethod(int *, int, int);
void insertionSort(int *s, int n) {
  int lh, rh;
  while (!isSort(s, 0, n)) {
    rh = nIsSort(s, n);
    lh = findSmallestElement(s, 0, rh - 1);
    swapOfInsertionSortMethod(s, lh, rh);
  }
}


x86 assembly (clang, -O0):
<insertionSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1050 <isSort@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1172 <insertionSort+0x32>
jmp    11a9 <insertionSort+0x69>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <nIsSort@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <findSmallestElement@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1060 <swapOfInsertionSortMethod@plt>
jmp    114f <insertionSort+0xf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertionSort>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <isSort@plt>
test   %eax,%eax
jne    1189 <insertionSort+0x49>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <nIsSort@plt>
mov    %eax,%ebp
lea    -0x1(%rbp),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <findSmallestElement@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1060 <swapOfInsertionSortMethod@plt>
mov    %rbx,%rdi
jmp    1150 <insertionSort+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @insertionSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
br label %7
7: ; preds = %13, %2
%8 = load i32*, i32** %3
%9 = load i32, i32* %4
%10 = call i32 @isSort(i32* %8, i32 0, i32 %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %25
13: ; preds = %7
%14 = load i32*, i32** %3
%15 = load i32, i32* %4
%16 = call i32 @nIsSort(i32* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32*, i32** %3
%18 = load i32, i32* %6
%19 = sub nsw i32 %18, 1
%20 = call i32 @findSmallestElement(i32* %17, i32 0, i32 %19)
store i32 %20, i32* %5
%21 = load i32*, i32** %3
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = call i32 @swapOfInsertionSortMethod(i32* %21, i32 %22, i32 %23)
br label %7
25: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @insertionSort(i32* %0, i32 %1) {
%3 = tail call i32 @isSort(i32* %0, i32 0, i32 %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %2, %5
%6 = tail call i32 @nIsSort(i32* %0, i32 %1)
%7 = add nsw i32 %6, -1
%8 = tail call i32 @findSmallestElement(i32* %0, i32 0, i32 %7)
%9 = tail call i32 @swapOfInsertionSortMethod(i32* %0, i32 %8, i32 %6)
%10 = tail call i32 @isSort(i32* %0, i32 0, i32 %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %5, label %12
12: ; preds = %5, %2
ret void
}