#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
void *atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int random();
int /*<<< orphan*/ selection_sort(int *, unsigned long, unsigned int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ verify(int *, unsigned long);
int main(int argc, char *argv[]) {
  struct timeval timevalA;
  struct timeval timevalB;
  int *vetor = NULL;
  unsigned long tam, i = 0;
  unsigned int numThread;
  int count;
  if (argc != 3) {
    printf("%s elementos e numero de threads\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  tam = atoi(argv[1]);
  numThread = atoi(argv[2]);
  if (!(vetor = (int *)malloc(sizeof(int) * tam))) {
    printf("Erro ao alocar memória\n");
    exit(EXIT_FAILURE);
  }
  double sum = 0.0;
  srand(time(NULL));
  for (count = 0; count < 10; count++) {
    for (i = 0; i < tam; i++) {
      *(vetor + i) = random() % 10000;
    }
    gettimeofday(&timevalA, NULL);
    selection_sort(vetor, tam, numThread);
    gettimeofday(&timevalB, NULL);
    verify(vetor, tam);
    double t = timevalB.tv_sec - timevalA.tv_sec +
               (timevalB.tv_usec - timevalA.tv_usec) / (double)1000000;
    sum += t;
    printf("%lf\n", t);
  }
  printf("#\t%lf\t%u\t%lu\n", sum / 10.0, numThread, tam);
  free(vetor);
  return EXIT_SUCCESS;
}


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)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x48(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1203 <main+0x53>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    125d <main+0xad>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
movl   $0x0,-0x50(%rbp)
cmpl   $0xa,-0x50(%rbp)
jge    1357 <main+0x1a7>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    12c7 <main+0x117>
mov    $0x0,%al
call   1090 <random@plt>
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    128e <main+0xde>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1030 <selection_sort@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10b0 <verify@plt>
movsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xcee(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x60(%rbp),%xmm0
lea    0xd09(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    127c <main+0xcc>
movsd  -0x58(%rbp),%xmm0
movsd  0xc9c(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x4c(%rbp),%esi
mov    -0x40(%rbp),%rdx
lea    0xcda(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    0x2c4b(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1338 <main+0x178>
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %rax,%r14
lea    0x0(,%r15,4),%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     134b <main+0x18b>
mov    %rax,%rbx
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
cmp    $0x2,%r15
mov    $0x1,%r12d
cmovae %r15,%r12
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %r13d,%r13d
jmp    12b9 <main+0xf9>
nopl   0x0(%rax)
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <selection_sort@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <verify@plt>
movapd 0x10(%rsp),%xmm1
subpd  0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0xd73(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xd8a(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
add    $0x1,%r13d
cmp    $0xa,%r13d
je     12f6 <main+0x136>
test   %r15,%r15
je     1240 <main+0x80>
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <random@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    12c0 <main+0x100>
jmp    1240 <main+0x80>
movsd  0x8(%rsp),%xmm0
divsd  0xd04(%rip),%xmm0
lea    0xd2c(%rip),%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    $0x1,%al
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xcce(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1357 <main+0x197>
lea    0xcf3(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [34 x i8] c"%s elementos e numero de threads\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"Erro ao alocar mem\C3\B3ria\0A\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
@.str.3 = [14 x i8] c"#\09%lf\09%u\09%lu\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %8
store i64 0, i64* %10
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i8* @atoi(i8* %27)
%29 = ptrtoint i8* %28 to i64
store i64 %29, i64* %9
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i8* @atoi(i8* %32)
%34 = ptrtoint i8* %33 to i32
store i32 %34, i32* %11
%35 = load i64, i64* %9
%36 = mul i64 4, %35
%37 = trunc i64 %36 to i32
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i32*
store i32* %39, i32** %8
%40 = icmp ne i32* %39, null
br i1 %40, label %45, label %41
41: ; preds = %24
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %24
store double 0.000000e+00, double* %13
%46 = call i32 @time(i32* null)
%47 = call i32 @srand(i32 %46)
store i32 0, i32* %12
br label %48
48: ; preds = %92, %45
%49 = load i32, i32* %12
%50 = icmp slt i32 %49, 10
br i1 %50, label %51, label %95
51: ; preds = %48
store i64 0, i64* %10
br label %52
52: ; preds = %62, %51
%53 = load i64, i64* %10
%54 = load i64, i64* %9
%55 = icmp ult i64 %53, %54
br i1 %55, label %56, label %65
56: ; preds = %52
%57 = call i32 (...) @random()
%58 = srem i32 %57, 10000
%59 = load i32*, i32** %8
%60 = load i64, i64* %10
%61 = getelementptr inbounds i32, i32* %59, i64 %60
store i32 %58, i32* %61
br label %62
62: ; preds = %56
%63 = load i64, i64* %10
%64 = add i64 %63, 1
store i64 %64, i64* %10
br label %52
65: ; preds = %52
%66 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%67 = load i32*, i32** %8
%68 = load i64, i64* %9
%69 = load i32, i32* %11
%70 = call i32 @selection_sort(i32* %67, i64 %68, i32 %69)
%71 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%72 = load i32*, i32** %8
%73 = load i64, i64* %9
%74 = call i32 @verify(i32* %72, i64 %73)
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%76 = load double, double* %75
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%78 = load double, double* %77
%79 = fsub double %76, %78
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%81 = load double, double* %80
%82 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%83 = load double, double* %82
%84 = fsub double %81, %83
%85 = fdiv double %84, 1.000000e+06
%86 = fadd double %79, %85
store double %86, double* %14
%87 = load double, double* %14
%88 = load double, double* %13
%89 = fadd double %88, %87
store double %89, double* %13
%90 = load double, double* %14
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %90)
br label %92
92: ; preds = %65
%93 = load i32, i32* %12
%94 = add nsw i32 %93, 1
store i32 %94, i32* %12
br label %48
95: ; preds = %48
%96 = load double, double* %13
%97 = fdiv double %96, 1.000000e+01
%98 = load i32, i32* %11
%99 = load i64, i64* %9
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %97, i32 %98, i64 %99)
%101 = load i32*, i32** %8
%102 = call i32 @free(i32* %101)
%103 = load i32, i32* @EXIT_SUCCESS
ret i32 %103
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [34 x i8] c"%s elementos e numero de threads\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"%lf\0A\00"
@.str.3 = [14 x i8] c"#\09%lf\09%u\09%lu\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [24 x i8] c"Erro ao alocar mem\C3\B3ria\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca <2 x double>
%4 = bitcast <2 x double>* %3 to %struct.timeval*
%5 = alloca <2 x double>
%6 = bitcast <2 x double>* %5 to %struct.timeval*
%7 = bitcast <2 x double>* %3 to i8*
%8 = bitcast <2 x double>* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i8* @atoi(i8* %17)
%19 = ptrtoint i8* %18 to i64
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i8* @atoi(i8* %21)
%23 = ptrtoint i8* %22 to i64
%24 = trunc i64 %23 to i32
%25 = trunc i64 %19 to i32
%26 = shl i32 %25, 2
%27 = tail call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i32*
%29 = icmp eq i64 %27, 0
br i1 %29, label %30, label %34
30: ; preds = %15
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %15
%35 = tail call i32 @time(i32* null)
%36 = tail call i32 @srand(i32 %35)
%37 = icmp eq i8* %18, null
%38 = call i64 @llvm.umax.i64(i64 %19, i64 1)
br label %39
39: ; preds = %34, %49
%40 = phi double [ 0.000000e+00, %34 ], [ %61, %49 ]
%41 = phi i32 [ 0, %34 ], [ %63, %49 ]
br i1 %37, label %49, label %42
42: ; preds = %39, %42
%43 = phi i64 [ %47, %42 ], [ 0, %39 ]
%44 = tail call i32 (...) @random()
%45 = srem i32 %44, 10000
%46 = getelementptr inbounds i32, i32* %28, i64 %43
store i32 %45, i32* %46
%47 = add nuw i64 %43, 1
%48 = icmp eq i64 %47, %38
br i1 %48, label %49, label %42
49: ; preds = %42, %39
%50 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%51 = tail call i32 @selection_sort(i32* %28, i64 %19, i32 %24)
%52 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%53 = tail call i32 @verify(i32* %28, i64 %19)
%54 = load <2 x double>, <2 x double>* %5
%55 = load <2 x double>, <2 x double>* %3
%56 = fsub <2 x double> %54, %55
%57 = extractelement <2 x double> %56, i64 1
%58 = fdiv double %57, 1.000000e+06
%59 = extractelement <2 x double> %56, i64 0
%60 = fadd double %59, %58
%61 = fadd double %40, %60
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %60)
%63 = add nuw nsw i32 %41, 1
%64 = icmp eq i32 %63, 10
br i1 %64, label %65, label %39
65: ; preds = %49
%66 = fdiv double %61, 1.000000e+01
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %66, i32 %24, i64 %19)
%68 = tail call i32 @free(i32* %28)
%69 = load i32, i32* @EXIT_SUCCESS
ret i32 %69
}