#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 */
typedef int /*<<< orphan*/ list;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ swap(int *, int *);
void main() {
  int list[] = {36, 24, 10, 6, 12};
  int int_size = sizeof(int);
  int length = sizeof(list) / int_size;
  int i = 0;
  int j = 0;
  printf("unsorted = {");
  for (i = 0; i < length; i++) {
    printf("%3d ", list[i]);
  }
  printf("}\n");
  for (i = 0; i < length - 1; i++)
    for (j = length - 1; j > i; j--)
      if (list[j] < list[j - 1])
        swap(&list[j], &list[j - 1]);
  printf("sorted   = {");
  for (i = 0; i < length; i++) {
    printf("%3d ", list[i]);
  }
  printf("}\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecc(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x4,-0x24(%rbp)
movslq -0x24(%rbp),%rcx
mov    $0x14,%eax
xor    %edx,%edx
div    %rcx
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11b2 <main+0x92>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1182 <main+0x62>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1255 <main+0x135>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jle    1242 <main+0x122>
movslq -0x30(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    -0x20(%rbp,%rcx,4),%eax
jge    122f <main+0x10f>
movslq -0x30(%rbp),%rax
lea    -0x20(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
cltq
lea    -0x20(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <swap@plt>
jmp    1234 <main+0x114>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    11e1 <main+0xc1>
jmp    1247 <main+0x127>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c7 <main+0xa7>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    129a <main+0x17a>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    126a <main+0x14a>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    0xecd(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rbx
mov    %rbx,%rdi
mov    $0x24,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%r15
mov    %rbx,%rdi
mov    $0x18,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%r14
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%r13
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <swap@plt>
mov    0x4(%rsp),%eax
cmp    %eax,0x8(%rsp)
jge    11f1 <main+0xc1>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <swap@plt>
mov    0x4(%rsp),%eax
cmp    (%rsp),%eax
jge    1201 <main+0xd1>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1050 <swap@plt>
lea    0x10(%rsp),%r12
mov    0xc(%rsp),%eax
cmp    %eax,0x10(%rsp)
jge    121f <main+0xef>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <swap@plt>
mov    0xc(%rsp),%eax
mov    0x8(%rsp),%ecx
cmp    %ecx,%eax
jge    1236 <main+0x106>
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <swap@plt>
mov    0x8(%rsp),%ecx
cmp    0x4(%rsp),%ecx
jge    1247 <main+0x117>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <swap@plt>
mov    0xc(%rsp),%eax
cmp    %eax,0x10(%rsp)
jge    1260 <main+0x130>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <swap@plt>
mov    0xc(%rsp),%eax
cmp    0x8(%rsp),%eax
jge    1271 <main+0x141>
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <swap@plt>
mov    0x10(%rsp),%eax
cmp    0xc(%rsp),%eax
jge    1286 <main+0x156>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <swap@plt>
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%esi
lea    0xd83(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd4c(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.list = [5 x i32] [i32 36, i32 24, i32 10, i32 6, i32 12]
@.str = [13 x i8] c"unsorted = {\00"
@.str.1 = [5 x i8] c"%3d \00"
@.str.2 = [3 x i8] c"}\0A\00"
@.str.3 = [13 x i8] c"sorted = {\00"
define void @main() {
%1 = alloca [5 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [5 x i32]* %1 to i8*
store i32 4, i32* %2
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = udiv i64 20, %8
%10 = trunc i64 %9 to i32
store i32 %10, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %12
12: ; preds = %22, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %16
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %12
25: ; preds = %12
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %27
27: ; preds = %64, %25
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = sub nsw i32 %29, 1
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %67
32: ; preds = %27
%33 = load i32, i32* %3
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %5
br label %35
35: ; preds = %60, %32
%36 = load i32, i32* %5
%37 = load i32, i32* %4
%38 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %63
39: ; preds = %35
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* %5
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = icmp slt i32 %43, %48
br i1 %49, label %50, label %59
50: ; preds = %39
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %52
%54 = load i32, i32* %5
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %56
%58 = call i32 @swap(i32* %53, i32* %57)
br label %59
59: ; preds = %50, %39
br label %60
60: ; preds = %59
%61 = load i32, i32* %5
%62 = add nsw i32 %61, -1
store i32 %62, i32* %5
br label %35
63: ; preds = %35
br label %64
64: ; preds = %63
%65 = load i32, i32* %4
%66 = add nsw i32 %65, 1
store i32 %66, i32* %4
br label %27
67: ; preds = %27
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %69
69: ; preds = %79, %67
%70 = load i32, i32* %4
%71 = load i32, i32* %3
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %82
73: ; preds = %69
%74 = load i32, i32* %4
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %75
%77 = load i32, i32* %76
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %77)
br label %79
79: ; preds = %73
%80 = load i32, i32* %4
%81 = add nsw i32 %80, 1
store i32 %81, i32* %4
br label %69
82: ; preds = %69
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.main.list = [5 x i32] [i32 36, i32 24, i32 10, i32 6, i32 12]
@.str = [13 x i8] c"unsorted = {\00"
@.str.1 = [5 x i8] c"%3d \00"
@.str.3 = [13 x i8] c"sorted = {\00"
@str.4 = [2 x i8] c"}\00"
define void @main() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 36)
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 24)
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 10)
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 6)
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 4
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 12)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
%15 = call i32 @swap(i32* %10, i32* %8)
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = call i32 @swap(i32* %8, i32* %6)
%21 = load i32, i32* %6
br label %22
22: ; preds = %19, %0
%23 = phi i32 [ %21, %19 ], [ %17, %0 ]
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @swap(i32* %6, i32* %4)
br label %28
28: ; preds = %26, %22
%29 = load i32, i32* %12
%30 = load i32, i32* %10
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 @swap(i32* %12, i32* %10)
%34 = load i32, i32* %10
br label %35
35: ; preds = %32, %28
%36 = phi i32 [ %34, %32 ], [ %30, %28 ]
%37 = load i32, i32* %8
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = call i32 @swap(i32* %10, i32* %8)
%41 = load i32, i32* %8
br label %42
42: ; preds = %39, %35
%43 = phi i32 [ %41, %39 ], [ %37, %35 ]
%44 = load i32, i32* %6
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @swap(i32* %8, i32* %6)
br label %48
48: ; preds = %46, %42
%49 = load i32, i32* %12
%50 = load i32, i32* %10
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = call i32 @swap(i32* %12, i32* %10)
%54 = load i32, i32* %10
br label %55
55: ; preds = %52, %48
%56 = phi i32 [ %54, %52 ], [ %50, %48 ]
%57 = load i32, i32* %8
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @swap(i32* %10, i32* %8)
br label %61
61: ; preds = %59, %55
%62 = load i32, i32* %12
%63 = load i32, i32* %10
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 @swap(i32* %12, i32* %10)
br label %67
67: ; preds = %61, %65
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%69 = load i32, i32* %4
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = load i32, i32* %6
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %8
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %73)
%75 = load i32, i32* %10
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %12
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %77)
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
ret void
}