#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*/ printf(char *, ...);
int main(void) {
  int arr[10] = {26, 34543, 17, 31, 13, 543, 456, 1, 0, 2};
  int idx, target, tmp, swapped;
  printf("Bubble Sort\n");
  printf("Before Sorting: \n");
  for (idx = 0; idx < 10; idx++) {
    printf("%d\t", arr[idx]);
  }
  printf("\n");
  for (idx = 0; idx < 10 - 1; idx++) {
    swapped = 0;
    for (target = 0; target < (10 - 1) - idx; target++) {
      if (arr[target] > arr[target + 1]) {
        tmp = arr[target];
        arr[target] = arr[target + 1];
        arr[target + 1] = tmp;
        swapped = 1;
      }
    }
    if (!swapped)
      break;
  }
  printf("After Sorting: \n");
  for (idx = 0; idx < 10; idx++) {
    printf("%d\t", arr[idx]);
  }
  printf("\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    1195 <main+0x75>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1167 <main+0x47>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x9,-0x34(%rbp)
jge    125a <main+0x13a>
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    $0x9,%ecx
sub    -0x34(%rbp),%ecx
cmp    %ecx,%eax
jge    1238 <main+0x118>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jle    1225 <main+0x105>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x30(%rbp,%rax,4),%ecx
movslq -0x38(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x30(%rbp,%rax,4)
movl   $0x1,-0x40(%rbp)
jmp    122a <main+0x10a>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11c2 <main+0xa2>
cmpl   $0x0,-0x40(%rbp)
jne    1247 <main+0x127>
jmp    125a <main+0x13a>
jmp    124c <main+0x12c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11aa <main+0x8a>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    129d <main+0x17d>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    126f <main+0x14f>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xee2(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
lea    0xeaf(%rip),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
mov    $0x1a,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x86ef,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x11,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x1f,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0xd,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x21f,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x1c8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x9,%eax
mov    $0x8,%ecx
jmp    1240 <main+0x110>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rcx
cmp    $0x9,%ebx
je     1290 <main+0x160>
mov    (%rsp),%esi
xor    %edx,%edx
xor    %r8d,%r8d
mov    0x4(%rsp,%rdx,4),%edi
cmp    %edi,%esi
jle    1280 <main+0x150>
mov    %edi,(%rsp,%rdx,4)
mov    %esi,0x4(%rsp,%rdx,4)
cmp    %rdx,%rcx
je     1230 <main+0x100>
mov    0x8(%rsp,%rdx,4),%edi
add    $0x1,%rdx
cmp    %edi,%esi
jg     1250 <main+0x120>
add    $0x1,%rdx
mov    $0x1,%r8d
jmp    1284 <main+0x154>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rdx
mov    %edi,%esi
cmp    %rax,%rdx
jne    1248 <main+0x118>
test   %r8d,%r8d
jne    1230 <main+0x100>
lea    0xdb2(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%esi
lea    0xd82(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

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