#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);
void ex2() {
  int array[5] = {7, 9, 5, 3, 1}, tmp;
  for (int x = 0; x < (4); x++) {
    for (int y = x + 1; y < 5; y++) {
      if (array[x] > array[y]) {
        tmp = array[y];
        array[y] = array[x];
        array[x] = tmp;
      }
    }
  }
  for (int x = 0; x < 5; x++) {
    printf("%d\n", array[x]);
  }
}


x86 assembly (clang, -O0):
<ex2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xee1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xede(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xedc(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    11bd <ex2+0xad>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x5,-0x2c(%rbp)
jge    11aa <ex2+0x9a>
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
movslq -0x2c(%rbp),%rcx
cmp    -0x20(%rbp,%rcx,4),%eax
jle    1197 <ex2+0x87>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
mov    %eax,-0x24(%rbp)
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%ecx
movslq -0x2c(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x24(%rbp),%ecx
movslq -0x28(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
jmp    119c <ex2+0x8c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1151 <ex2+0x41>
jmp    11af <ex2+0x9f>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    113e <ex2+0x2e>
movl   $0x0,-0x30(%rbp)
cmpl   $0x5,-0x30(%rbp)
jge    11f0 <ex2+0xe0>
movslq -0x30(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c4 <ex2+0xb4>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex2>:
push   %rbx
lea    0xee8(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@__const.ex2.array = [5 x i32] [i32 7, i32 9, i32 5, i32 3, i32 1]
@.str = [4 x i8] c"%d\0A\00"
define void @ex2() {
%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 0, i32* %3
br label %7
7: ; preds = %47, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %50
10: ; preds = %7
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %4
br label %13
13: ; preds = %43, %10
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 5
br i1 %15, label %16, label %46
16: ; preds = %13
%17 = load i32, i32* %3
%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 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = icmp sgt i32 %20, %24
br i1 %25, label %26, label %42
26: ; preds = %16
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %28
%30 = load i32, i32* %29
store i32 %30, i32* %2
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %36
store i32 %34, i32* %37
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %40
store i32 %38, i32* %41
br label %42
42: ; preds = %26, %16
br label %43
43: ; preds = %42
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %13
46: ; preds = %13
br label %47
47: ; preds = %46
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
br label %7
50: ; preds = %7
store i32 0, i32* %5
br label %51
51: ; preds = %60, %50
%52 = load i32, i32* %5
%53 = icmp slt i32 %52, 5
br i1 %53, label %54, label %63
54: ; preds = %51
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %54
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %51
63: ; preds = %51
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define void @ex2() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 5)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 7)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 9)
ret void
}