#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 *);
int insertion_sort(int *a, int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (a[i] < a[j]) {
        swap(&a[i], &a[j]);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<insertion_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11aa <insertion_sort+0x9a>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1197 <insertion_sort+0x87>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1184 <insertion_sort+0x74>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
jmp    1189 <insertion_sort+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <insertion_sort+0x29>
jmp    119c <insertion_sort+0x8c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <insertion_sort+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertion_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    116f <insertion_sort+0x5f>
mov    %rdi,%r15
mov    %esi,%r12d
xor    %r13d,%r13d
jmp    1139 <insertion_sort+0x29>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r12,%r13
je     116f <insertion_sort+0x5f>
test   %r13,%r13
je     1130 <insertion_sort+0x20>
lea    (%r15,%r13,4),%r14
mov    %r13,%rbp
mov    %r15,%rbx
jmp    115a <insertion_sort+0x4a>
nopw   0x0(%rax,%rax,1)
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
je     1130 <insertion_sort+0x20>
mov    (%r15,%r13,4),%eax
cmp    (%rbx),%eax
jge    1150 <insertion_sort+0x40>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <swap@plt>
jmp    1150 <insertion_sort+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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