#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 */
struct timeval {
  double tv_sec;
  double tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ xepBatKi(int *, int);
int main() {
  int i, N;
  int ngaunhien[10000];
  printf("Nhap so phan tu cua mang:");
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    ngaunhien[i] = (rand() % 1000);
  }
  struct timeval t1, t2;
  double elapsedTime;
  gettimeofday(&t1, NULL);
  xepBatKi(ngaunhien, N);
  gettimeofday(&t2, NULL);
  elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
  elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;
  for (i = 0; i < N; i++) {
    printf("%d\n", ngaunhien[i]);
  }
  printf("Thoi gian chay %f", elapsedTime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeab(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bb <main+0x6b>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq -0x8(%rbp),%rax
mov    %edx,-0x9c50(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1187 <main+0x37>
lea    -0x9c60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x9c50(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <xepBatKi@plt>
lea    -0x9c70(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  -0x9c70(%rbp),%xmm0
ff
subsd  -0x9c60(%rbp),%xmm0
ff
movsd  0xdfe(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x9c78(%rbp)
ff
movsd  -0x9c68(%rbp),%xmm0
ff
subsd  -0x9c58(%rbp),%xmm0
ff
movsd  0xdda(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x9c78(%rbp),%xmm0
ff
movsd  %xmm0,-0x9c78(%rbp)
ff
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1274 <main+0x124>
movslq -0x8(%rbp),%rax
mov    -0x9c50(%rbp,%rax,4),%esi
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1241 <main+0xf1>
movsd  -0x9c78(%rbp),%xmm0
ff
lea    0xda6(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x9c98,%rsp
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11c7 <main+0x77>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x50(%rsp,%rbx,4)
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1190 <main+0x40>
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0xc(%rsp),%esi
lea    0x50(%rsp),%rdi
call   1050 <xepBatKi@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x38(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x40(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x48(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    124c <main+0xfc>
lea    0xdfa(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    0x50(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1230 <main+0xe0>
movsd  0x20(%rsp),%xmm2
subsd  0x10(%rsp),%xmm2
movsd  0xda0(%rip),%xmm1
mulsd  %xmm1,%xmm2
movsd  0x28(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
divsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
lea    0xdaa(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c98,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [26 x i8] c"Nhap so phan tu cua mang:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [18 x i8] c"Thoi gian chay %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10000 x i32]
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca double
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store i32 0, i32* %2
br label %10
10: ; preds = %20, %0
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 1000
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10000 x i32], [10000 x i32]* %4, i64 0, i64 %18
store i32 %16, i32* %19
br label %20
20: ; preds = %14
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %10
23: ; preds = %10
%24 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%25 = getelementptr inbounds [10000 x i32], [10000 x i32]* %4, i64 0, i64 0
%26 = load i32, i32* %3
%27 = call i32 @xepBatKi(i32* %25, i32 %26)
%28 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%30 = load double, double* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%32 = load double, double* %31
%33 = fsub double %30, %32
%34 = fmul double %33, 1.000000e+03
store double %34, double* %7
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%36 = load double, double* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%38 = load double, double* %37
%39 = fsub double %36, %38
%40 = fdiv double %39, 1.000000e+03
%41 = load double, double* %7
%42 = fadd double %41, %40
store double %42, double* %7
store i32 0, i32* %2
br label %43
43: ; preds = %53, %23
%44 = load i32, i32* %2
%45 = load i32, i32* %3
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %56
47: ; preds = %43
%48 = load i32, i32* %2
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [10000 x i32], [10000 x i32]* %4, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %47
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %43
56: ; preds = %43
%57 = load double, double* %7
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %57)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [26 x i8] c"Nhap so phan tu cua mang:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [18 x i8] c"Thoi gian chay %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i32]
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast i32* %1 to i8*
%6 = bitcast [10000 x i32]* %2 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %0, %11
%12 = phi i64 [ %16, %11 ], [ 0, %0 ]
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 1000
%15 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %12
store i32 %14, i32* %15
%16 = add nuw nsw i64 %12, 1
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %11, label %20
20: ; preds = %11, %0
%21 = bitcast %struct.timeval* %3 to i8*
%22 = bitcast %struct.timeval* %4 to i8*
%23 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%24 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %1
%26 = call i32 @xepBatKi(i32* %24, i32 %25)
%27 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%29 = load double, double* %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%31 = load double, double* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%33 = load double, double* %32
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%35 = load double, double* %34
%36 = load i32, i32* %1
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %47
38: ; preds = %20, %38
%39 = phi i64 [ %43, %38 ], [ 0, %20 ]
%40 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i64 %39, 1
%44 = load i32, i32* %1
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %43, %45
br i1 %46, label %38, label %47
47: ; preds = %38, %20
%48 = fsub double %29, %31
%49 = fmul double %48, 1.000000e+03
%50 = fsub double %33, %35
%51 = fdiv double %50, 1.000000e+03
%52 = fadd double %49, %51
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %52)
ret i32 0
}