#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 s[], int len) {
  int i, j;
  int n = len;
  for (i = 0; i < n; i++) {
    j = i;
    while ((j > 0) && (s[j] < s[j - 1])) {
      swap(s + j, s + (j - 1));
      j -= 1;
    }
  }
}


x86 assembly (clang, -O0):
<insertion_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c6 <insertion_sort+0xb6>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jle    116e <insertion_sort+0x5e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117e <insertion_sort+0x6e>
jmp    11b3 <insertion_sort+0xa3>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <insertion_sort+0x2e>
jmp    11b8 <insertion_sort+0xa8>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112c <insertion_sort+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertion_sort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1174 <insertion_sort+0x64>
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %r12d,%r12d
mov    $0x1,%r15d
jmp    113d <insertion_sort+0x2d>
nopl   (%rax)
add    $0x1,%r12d
add    $0x1,%r15d
cmp    %r14d,%r12d
je     1174 <insertion_sort+0x64>
test   %r12d,%r12d
je     1130 <insertion_sort+0x20>
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%eax
lea    -0x1(%rax),%ebp
mov    (%rbx,%rbp,4),%ecx
add    $0xfffffffe,%eax
cmp    (%rbx,%rax,4),%ecx
jge    1130 <insertion_sort+0x20>
lea    (%rbx,%rbp,4),%rdi
lea    (%rbx,%rax,4),%rsi
call   1030 <swap@plt>
cmp    $0x1,%ebp
jg     1150 <insertion_sort+0x40>
jmp    1130 <insertion_sort+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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