#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, double);
int /*<<< orphan*/ swap(double *, double *);
int main(void) {
  double array[5] = {91.23, 45.9, 60.87, 98.5, 105.7};
  int i, j, k;
  for (i = 0; i < 5; i++) {
    printf("Before swap, array at index %d is %f\n", i, array[i]);
  }
  for (j = 0; j < 5; j++) {
    swap(&array[j], &array[j + 1]);
    printf("During swap, array at index %d is %f\n", j, array[j]);
  }
  for (k = 0; k < 5; k++) {
    printf("After swap, array at index %d is %f\n", k, array[k]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe9f(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe8a(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe75(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    11c8 <main+0x98>
mov    -0x34(%rbp),%esi
movslq -0x34(%rbp),%rax
movsd  -0x30(%rbp,%rax,8),%xmm0
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1197 <main+0x67>
movl   $0x0,-0x38(%rbp)
cmpl   $0x5,-0x38(%rbp)
jge    1227 <main+0xf7>
movslq -0x38(%rbp),%rax
lea    -0x30(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltq
lea    -0x30(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x38(%rbp),%esi
movslq -0x38(%rbp),%rax
movsd  -0x30(%rbp,%rax,8),%xmm0
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11cf <main+0x9f>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x5,-0x3c(%rbp)
jge    125f <main+0x12f>
mov    -0x3c(%rbp),%esi
movslq -0x3c(%rbp),%rax
movsd  -0x30(%rbp,%rax,8),%xmm0
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    122e <main+0xfe>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%r13
movaps 0xec7(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%r12
lea    0x18(%rsp),%r15
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x20(%rsp),%r14
movabs $0x405a6ccccccccccd,%rax
6c 5a 40
mov    %rax,0x20(%rsp)
lea    0xeda(%rip),%rbx
movsd  0xeaa(%rip),%xmm0
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
movsd  0xea0(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
movsd  0xe93(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
movsd  0xe86(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
movsd  0xe79(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    %r13,%rsi
call   1040 <swap@plt>
movsd  (%rsp),%xmm0
lea    0xe83(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <swap@plt>
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <swap@plt>
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <swap@plt>
movsd  0x18(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
lea    0x28(%rsp),%rsi
mov    %r14,%rdi
call   1040 <swap@plt>
movsd  0x20(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
lea    0xe19(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
movsd  0x18(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
movsd  0x20(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Before swap, array at index %d is %f\0A\00"
@.str.1 = [38 x i8] c"During swap, array at index %d is %f\0A\00"
@.str.2 = [37 x i8] c"After swap, array at index %d is %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x double]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [5 x double]* %2 to i8*
%7 = bitcast i8* %6 to [5 x double]*
%8 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 0
store double 9.123000e+01, double* %8
%9 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 1
store double 4.590000e+01, double* %9
%10 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 2
store double 0x404E6F5C28F5C28F, double* %10
%11 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 3
store double 9.850000e+01, double* %11
%12 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 4
store double 1.057000e+02, double* %12
store i32 0, i32* %3
br label %13
13: ; preds = %23, %0
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 5
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32, i32* %3
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 %19
%21 = load double, double* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %17, double %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %13
26: ; preds = %13
store i32 0, i32* %4
br label %27
27: ; preds = %45, %26
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 5
br i1 %29, label %30, label %48
30: ; preds = %27
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 %36
%38 = call i32 @swap(double* %33, double* %37)
%39 = load i32, i32* %4
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 %41
%43 = load double, double* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %39, double %43)
br label %45
45: ; preds = %30
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %27
48: ; preds = %27
store i32 0, i32* %5
br label %49
49: ; preds = %59, %48
%50 = load i32, i32* %5
%51 = icmp slt i32 %50, 5
br i1 %51, label %52, label %62
52: ; preds = %49
%53 = load i32, i32* %5
%54 = load i32, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 %55
%57 = load double, double* %56
%58 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %53, double %57)
br label %59
59: ; preds = %52
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
store i32 %61, i32* %5
br label %49
62: ; preds = %49
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"Before swap, array at index %d is %f\0A\00"
@.str.1 = [38 x i8] c"During swap, array at index %d is %f\0A\00"
@.str.2 = [37 x i8] c"After swap, array at index %d is %f\0A\00"
define i32 @main() {
%1 = alloca [5 x double]
%2 = bitcast [5 x double]* %1 to i8*
%3 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 0
%4 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 1
%5 = bitcast [5 x double]* %1 to <2 x double>*
store <2 x double> <double 9.123000e+01, double 4.590000e+01>, <2 x double>* %5
%6 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 2
%7 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 3
%8 = bitcast double* %6 to <2 x double>*
store <2 x double> <double 0x404E6F5C28F5C28F, double 9.850000e+01>, <2 x double>* %8
%9 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 4
store double 1.057000e+02, double* %9
%10 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 0, double 9.123000e+01)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 1, double 4.590000e+01)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 2, double 0x404E6F5C28F5C28F)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 3, double 9.850000e+01)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 4, double 1.057000e+02)
%15 = call i32 @swap(double* %3, double* %4)
%16 = load double, double* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, double %16)
%18 = call i32 @swap(double* %4, double* %6)
%19 = load double, double* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 1, double %19)
%21 = call i32 @swap(double* %6, double* %7)
%22 = load double, double* %6
%23 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 2, double %22)
%24 = call i32 @swap(double* %7, double* %9)
%25 = load double, double* %7
%26 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 3, double %25)
%27 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 5
%28 = call i32 @swap(double* %9, double* %27)
%29 = load double, double* %9
%30 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 4, double %29)
%31 = load double, double* %3
%32 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 0, double %31)
%33 = load double, double* %4
%34 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 1, double %33)
%35 = load double, double* %6
%36 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 2, double %35)
%37 = load double, double* %7
%38 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 3, double %37)
%39 = load double, double* %9
%40 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 4, double %39)
ret i32 0
}