#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*/ bubble_sort(int *, unsigned long, unsigned int);
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*/ 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;
  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 (int j = 0; j < 10; j++) {
    for (i = 0; i < tam; i++) {
      *(vetor + i) = random() % 10000;
    }
    gettimeofday(&timevalA, NULL);
    bubble_sort(vetor, tam, numThread);
    gettimeofday(&timevalB, NULL);
    double t = timevalB.tv_sec - timevalA.tv_sec +
               (timevalB.tv_usec - timevalA.tv_usec) / (double)1000000;
    sum += t;
    printf("%lf\n", t);
    verify(vetor, tam);
  }
  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    $0x70,%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   1040 <printf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    125d <main+0xad>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x5c(%rbp)
cmpl   $0xa,-0x5c(%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   1080 <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   1050 <gettimeofday@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   10d0 <bubble_sort@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xcfb(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x68(%rbp),%xmm0
lea    0xd16(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10a0 <verify@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%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   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c4b(%rip),%rax
mov    (%rax),%eax
add    $0x70,%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   10c0 <atoi@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %rax,%r14
lea    0x0(,%r15,4),%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     134b <main+0x18b>
mov    %rax,%rbx
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <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   1060 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   10e0 <bubble_sort@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
movapd 0x10(%rsp),%xmm1
subpd  0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0xd7e(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xd95(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <verify@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   1090 <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   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <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   1050 <printf@plt>
jmp    1357 <main+0x197>
lea    0xcf3(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
call   10d0 <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 double
%13 = alloca i32
%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* %12
%46 = call i32 @time(i32* null)
%47 = call i32 @srand(i32 %46)
store i32 0, i32* %13
br label %48
48: ; preds = %92, %45
%49 = load i32, i32* %13
%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 @bubble_sort(i32* %67, i64 %68, i32 %69)
%71 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%73 = load double, double* %72
%74 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%75 = load double, double* %74
%76 = fsub double %73, %75
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%78 = load double, double* %77
%79 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%80 = load double, double* %79
%81 = fsub double %78, %80
%82 = fdiv double %81, 1.000000e+06
%83 = fadd double %76, %82
store double %83, double* %14
%84 = load double, double* %14
%85 = load double, double* %12
%86 = fadd double %85, %84
store double %86, double* %12
%87 = load double, double* %14
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %87)
%89 = load i32*, i32** %8
%90 = load i64, i64* %9
%91 = call i32 @verify(i32* %89, i64 %90)
br label %92
92: ; preds = %65
%93 = load i32, i32* %13
%94 = add nsw i32 %93, 1
store i32 %94, i32* %13
br label %48
95: ; preds = %48
%96 = load double, double* %12
%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, %54
%40 = phi i32 [ 0, %34 ], [ %68, %54 ]
%41 = phi double [ 0.000000e+00, %34 ], [ %65, %54 ]
br i1 %37, label %54, label %47
42: ; preds = %54
%43 = fdiv double %65, 1.000000e+01
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %43, i32 %24, i64 %19)
%45 = tail call i32 @free(i32* %28)
%46 = load i32, i32* @EXIT_SUCCESS
ret i32 %46
47: ; preds = %39, %47
%48 = phi i64 [ %52, %47 ], [ 0, %39 ]
%49 = tail call i32 (...) @random()
%50 = srem i32 %49, 10000
%51 = getelementptr inbounds i32, i32* %28, i64 %48
store i32 %50, i32* %51
%52 = add nuw i64 %48, 1
%53 = icmp eq i64 %52, %38
br i1 %53, label %54, label %47
54: ; preds = %47, %39
%55 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%56 = tail call i32 @bubble_sort(i32* %28, i64 %19, i32 %24)
%57 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%58 = load <2 x double>, <2 x double>* %5
%59 = load <2 x double>, <2 x double>* %3
%60 = fsub <2 x double> %58, %59
%61 = extractelement <2 x double> %60, i64 1
%62 = fdiv double %61, 1.000000e+06
%63 = extractelement <2 x double> %60, i64 0
%64 = fadd double %63, %62
%65 = fadd double %41, %64
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %64)
%67 = tail call i32 @verify(i32* %28, i64 %19)
%68 = add nuw nsw i32 %40, 1
%69 = icmp eq i32 %68, 10
br i1 %69, label %42, label %39
}