#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*/ a;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ swap(int *, int *);
int main() {
  int i = 1, j = 2, lg, tmp;
  swap(&i, &j);
  printf("swap i=%d, j=%d\n\n", i, j);
  int a[] = {3, 7, 8, 5, 12, 14, 21, 15, 18, 14};
  lg = sizeof(a) / sizeof(a[0]);
  for (i = 0; i < lg; i++) {
    for (j = i + 1; j < lg; j++) {
      if (a[j] < a[i]) {
        swap(&a[j], &a[i]);
      }
    }
    int x = 0;
    for (x = 0; x < lg; x++) {
      printf("%d ", a[x]);
    }
    printf("\n");
  }
  printf("\n\n#####\n");
  for (i = 0; i < lg; i++) {
    printf("%d ", a[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <swap@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    0xea7(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movl   $0xa,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1258 <main+0x128>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11fe <main+0xce>
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
movslq -0x8(%rbp),%rcx
cmp    -0x40(%rbp,%rcx,4),%eax
jge    11eb <main+0xbb>
movslq -0xc(%rbp),%rax
lea    -0x40(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
movslq -0x8(%rbp),%rax
lea    -0x40(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
jmp    11f0 <main+0xc0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a6 <main+0x76>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    123c <main+0x10c>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    120c <main+0xdc>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1191 <main+0x61>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    129d <main+0x16d>
movslq -0x8(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    126d <main+0x13d>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
movl   $0x1,0x8(%rsp)
movl   $0x2,0xc(%rsp)
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1060 <swap@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xebf(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xea3(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe87(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe65(%rip),%rbx
xor    %ecx,%ecx
jmp    1266 <main+0x126>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
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    0x28(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x30(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x34(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
cmp    $0x9,%eax
jge    12c1 <main+0x181>
lea    0x1(%rcx),%eax
mov    %eax,0xc(%rsp)
cmp    $0x8,%ecx
jg     11c0 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
movslq %eax,%rdx
mov    0x10(%rsp,%rdx,4),%esi
movslq %ecx,%rcx
cmp    0x10(%rsp,%rcx,4),%esi
jge    12a9 <main+0x169>
lea    (%rsp,%rdx,4),%rdi
add    $0x10,%rdi
lea    (%rsp,%rcx,4),%rsi
add    $0x10,%rsi
call   1060 <swap@plt>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
lea    0x1(%rcx),%eax
mov    %eax,0xc(%rsp)
cmp    $0x8,%ecx
jg     11c0 <main+0x80>
mov    0x8(%rsp),%ecx
jmp    1280 <main+0x140>
lea    0xd4e(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,0x8(%rsp)
lea    0xd36(%rip),%rbx
xor    %eax,%eax
xchg   %ax,%ax
cltq
mov    0x10(%rsp,%rax,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%ecx
lea    0x1(%rcx),%eax
mov    %eax,0x8(%rsp)
cmp    $0x9,%ecx
jl     12e0 <main+0x1a0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

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

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