#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*/ frame();
int /*<<< orphan*/ swap(int *, int, int);
void sort_bubble(int array[360]) {
  int c = 0;
  while (1) {
    c = 0;
    for (int i = 1; i < 360; i++) {
      if (array[i - 1] > array[i]) {
        swap(array, i - 1, i);
        c = 1;
      }
    }
    frame();
    if (!c)
      break;
  }
}


x86 assembly (clang, -O0):
<sort_bubble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x168,-0x10(%rbp)
jge    119b <sort_bubble+0x7b>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1188 <sort_bubble+0x68>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <swap@plt>
movl   $0x1,-0xc(%rbp)
jmp    118d <sort_bubble+0x6d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1141 <sort_bubble+0x21>
mov    $0x0,%al
call   1030 <frame@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11b1 <sort_bubble+0x91>
jmp    11b6 <sort_bubble+0x96>
jmp    1133 <sort_bubble+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_bubble>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebp,%ebp
mov    $0x1,%ebx
jmp    113d <sort_bubble+0x1d>
add    $0x1,%rbx
cmp    $0x168,%rbx
je     1160 <sort_bubble+0x40>
mov    -0x4(%r14,%rbx,4),%eax
cmp    (%r14,%rbx,4),%eax
jle    1130 <sort_bubble+0x10>
lea    -0x1(%rbx),%esi
mov    %r14,%rdi
mov    %ebx,%edx
call   1040 <swap@plt>
mov    $0x1,%ebp
jmp    1130 <sort_bubble+0x10>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <frame@plt>
mov    $0x1,%ebx
test   %ebp,%ebp
mov    $0x0,%ebp
jne    113d <sort_bubble+0x1d>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @sort_bubble(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
br label %5
5: ; preds = %1, %37
store i32 0, i32* %3
store i32 1, i32* %4
br label %6
6: ; preds = %29, %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 360
br i1 %8, label %9, label %32
9: ; preds = %6
%10 = load i32*, i32** %2
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %10, i64 %13
%15 = load i32, i32* %14
%16 = load i32*, i32** %2
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = icmp sgt i32 %15, %20
br i1 %21, label %22, label %28
22: ; preds = %9
%23 = load i32*, i32** %2
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = load i32, i32* %4
%27 = call i32 @swap(i32* %23, i32 %25, i32 %26)
store i32 1, i32* %3
br label %28
28: ; preds = %22, %9
br label %29
29: ; preds = %28
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %6
32: ; preds = %6
%33 = call i32 (...) @frame()
%34 = load i32, i32* %3
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %32
br label %38
37: ; preds = %32
br label %5
38: ; preds = %36
ret void
}

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