#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 InsertionSort2(int a[], int n) {
  int i, j;
  for (i = 1; i < n; i++)
    for (j = i - 1; j >= 0 && a[j] > a[j + 1]; j--)
      Swap(a + j, a + j + 1);
}


x86 assembly (clang, -O0):
<InsertionSort2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c3 <InsertionSort2+0xb3>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jl     116b <InsertionSort2+0x5b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    117b <InsertionSort2+0x6b>
jmp    11b0 <InsertionSort2+0xa0>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
add    $0x4,%rsi
call   1030 <Swap@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <InsertionSort2+0x2b>
jmp    11b5 <InsertionSort2+0xa5>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <InsertionSort2+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InsertionSort2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%esi
jl     1174 <InsertionSort2+0x64>
mov    %esi,%r14d
mov    %rdi,%rbx
mov    $0x1,%r15d
mov    $0x2,%r12d
jmp    114d <InsertionSort2+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15d
add    $0x1,%r12d
cmp    %r14d,%r15d
je     1174 <InsertionSort2+0x64>
mov    %r12d,%ebp
mov    %ebp,%eax
lea    -0x1(%rax),%ebp
add    $0xfffffffe,%eax
mov    (%rbx,%rax,4),%ecx
cmp    (%rbx,%rbp,4),%ecx
jle    1140 <InsertionSort2+0x30>
lea    (%rbx,%rax,4),%rdi
lea    0x4(%rdi),%rsi
call   1030 <Swap@plt>
cmp    $0x1,%ebp
jg     1150 <InsertionSort2+0x40>
jmp    1140 <InsertionSort2+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @InsertionSort2(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
store i32 1, i32* %5
br label %7
7: ; preds = %47, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %50
11: ; preds = %7
%12 = load i32, i32* %5
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %6
br label %14
14: ; preds = %43, %11
%15 = load i32, i32* %6
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i32*, i32** %3
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = load i32*, i32** %3
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %23, i64 %26
%28 = load i32, i32* %27
%29 = icmp sgt i32 %22, %28
br label %30
30: ; preds = %17, %14
%31 = phi i1 [ false, %14 ], [ %29, %17 ]
br i1 %31, label %32, label %46
32: ; preds = %30
%33 = load i32*, i32** %3
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32*, i32** %3
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = getelementptr inbounds i32, i32* %40, i64 1
%42 = call i32 @Swap(i32* %36, i32* %41)
br label %43
43: ; preds = %32
%44 = load i32, i32* %6
%45 = add nsw i32 %44, -1
store i32 %45, i32* %6
br label %14
46: ; preds = %30
br label %47
47: ; preds = %46
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %7
50: ; preds = %7
ret void
}

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