#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 last_largest_idx(int *, int);
int next_largest_idx(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sort(int *, int);
int /*<<< orphan*/ swap(int *, int, int);
float timeit();
int main(int argc, char *argv[]) {
  float start = timeit();
  int one_to_ten[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int first_idx, second_idx, count;
  int i;
  for (count = 0; count < 1000000 - 1; count++) {
    first_idx = next_largest_idx(one_to_ten);
    second_idx = last_largest_idx(one_to_ten, first_idx);
    swap(one_to_ten, first_idx, second_idx);
    sort(one_to_ten, first_idx);
  }
  float stop = timeit();
  printf("Answer: ");
  for (i = 0; i < 10; i++)
    printf("%d", one_to_ten[i]);
  printf("\nTime: %f\n", stop - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <timeit@plt>
movss  %xmm0,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x4c(%rbp)
cmpl   $0xf423f,-0x4c(%rbp)
jge    11ff <main+0x8f>
lea    -0x40(%rbp),%rdi
call   1090 <next_largest_idx@plt>
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1060 <last_largest_idx@plt>
mov    %eax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    -0x48(%rbp),%edx
call   1080 <swap@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1040 <sort@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11ae <main+0x3e>
mov    $0x0,%al
call   1070 <timeit@plt>
movss  %xmm0,-0x54(%rbp)
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x50(%rbp)
cmpl   $0xa,-0x50(%rbp)
jge    124e <main+0xde>
movslq -0x50(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1220 <main+0xb0>
movss  -0x54(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd1(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
xor    %eax,%eax
call   1060 <timeit@plt>
movss  %xmm0,0xc(%rsp)
mov    0xea4(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xe88(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe6c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0xf423f,%ebx
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1080 <next_largest_idx@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <last_largest_idx@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1070 <swap@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <sort@plt>
add    $0xffffffff,%ebx
jne    11b0 <main+0x50>
xor    %eax,%eax
call   1060 <timeit@plt>
movss  %xmm0,0x8(%rsp)
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xe2c(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x28(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x30(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x34(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd90(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.one_to_ten = [10 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [9 x i8] c"Answer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"\0ATime: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca [10 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call float (...) @timeit()
store float %13, float* %6
%14 = bitcast [10 x i32]* %7 to i8*
store i32 0, i32* %10
br label %15
15: ; preds = %31, %2
%16 = load i32, i32* %10
%17 = icmp slt i32 %16, 999999
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%20 = call i32 @next_largest_idx(i32* %19)
store i32 %20, i32* %8
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%22 = load i32, i32* %8
%23 = call i32 @last_largest_idx(i32* %21, i32 %22)
store i32 %23, i32* %9
%24 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%25 = load i32, i32* %8
%26 = load i32, i32* %9
%27 = call i32 @swap(i32* %24, i32 %25, i32 %26)
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%29 = load i32, i32* %8
%30 = call i32 @sort(i32* %28, i32 %29)
br label %31
31: ; preds = %18
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %15
34: ; preds = %15
%35 = call float (...) @timeit()
store float %35, float* %12
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %11
br label %37
37: ; preds = %46, %34
%38 = load i32, i32* %11
%39 = icmp slt i32 %38, 10
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %40
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
store i32 %48, i32* %11
br label %37
49: ; preds = %37
%50 = load float, float* %12
%51 = load float, float* %6
%52 = fsub float %50, %51
%53 = fpext float %52 to double
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %53)
ret i32 0
}

LLVM IR (-O2):
@__const.main.one_to_ten = [10 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [9 x i8] c"Answer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"\0ATime: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i32]
%4 = tail call float (...) @timeit()
%5 = bitcast [10 x i32]* %3 to i8*
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %13, %7 ]
%9 = call i32 @next_largest_idx(i32* %6)
%10 = call i32 @last_largest_idx(i32* %6, i32 %9)
%11 = call i32 @swap(i32* %6, i32 %9, i32 %10)
%12 = call i32 @sort(i32* %6, i32 %9)
%13 = add nuw nsw i32 %8, 1
%14 = icmp eq i32 %13, 999999
br i1 %14, label %15, label %7
15: ; preds = %7
%16 = call float (...) @timeit()
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %6
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 2
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 3
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 4
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 5
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 6
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 7
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 8
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 9
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = fsub float %16, %4
%48 = fpext float %47 to double
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %48)
ret i32 0
}