#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;
unsigned long atoi(char *);
int /*<<< orphan*/ comb_sort(int *, unsigned long);
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 main(int argc, char *argv[]) {
  struct timeval timevalA;
  struct timeval timevalB;
  int *vetor = NULL;
  unsigned long tam, i = 0;
  if (argc != 2) {
    printf("%s elementos\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  tam = atoi(argv[1]);
  if (!(vetor = (int *)malloc(sizeof(int) * tam))) {
    printf("Erro ao alocar memória\n");
    exit(EXIT_FAILURE);
  }
  srand(time(NULL));
  int j;
  double sum = 0;
  for (j = 0; j < 10; ++j) {
    for (i = 0; i < tam; i++) {
      *(vetor + i) = random() % 10000;
    }
    gettimeofday(&timevalA, NULL);
    comb_sort(vetor, tam);
    gettimeofday(&timevalB, NULL);
    double t = timevalB.tv_sec - timevalA.tv_sec +
               (timevalB.tv_usec - timevalA.tv_usec) / (double)1000000;
    sum += t;
  }
  printf("comb %lf\n", sum / 10.0);
  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   $0x2,-0x8(%rbp)
je     11f3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    123d <main+0x9d>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0xa,-0x4c(%rbp)
jge    1314 <main+0x174>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    12a7 <main+0x107>
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    126e <main+0xce>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10c0 <comb_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  0xd1e(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    125c <main+0xbc>
movsd  -0x58(%rbp),%xmm0
movsd  0xcdf(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd0b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c95(%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
cmp    $0x2,%edi
jne    12dd <main+0x12d>
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %rax,%rbx
lea    0x0(,%rax,4),%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     12f0 <main+0x140>
mov    %rax,%r14
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xorpd  %xmm0,%xmm0
lea    0x20(%rsp),%r15
lea    0x10(%rsp),%r12
xor    %r13d,%r13d
jmp    1263 <main+0xb3>
nopl   0x0(%rax)
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10d0 <comb_sort@plt>
mov    %r12,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
movapd 0x10(%rsp),%xmm0
subpd  0x20(%rsp),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
divsd  0xdb5(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x1,%r13d
cmp    $0xa,%r13d
je     12a7 <main+0xf7>
movsd  %xmm0,0x8(%rsp)
test   %rbx,%rbx
je     1210 <main+0x60>
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,(%r14,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1270 <main+0xc0>
jmp    1210 <main+0x60>
divsd  0xd59(%rip),%xmm0
lea    0xd68(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsi),%rsi
lea    0xd29(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12fc <main+0x14c>
lea    0xd31(%rip),%rdi
call   1040 <puts@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

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

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [14 x i8] c"%s elementos\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [10 x i8] c"comb %lf\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, 2
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 ([14 x i8], [14 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 i64 @atoi(i8* %17)
%19 = trunc i64 %18 to i32
%20 = shl i32 %19, 2
%21 = tail call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
%23 = icmp eq i64 %21, 0
br i1 %23, label %24, label %28
24: ; preds = %15
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %15
%29 = tail call i32 @time(i32* null)
%30 = tail call i32 @srand(i32 %29)
%31 = icmp eq i64 %18, 0
br label %32
32: ; preds = %28, %42
%33 = phi double [ 0.000000e+00, %28 ], [ %53, %42 ]
%34 = phi i32 [ 0, %28 ], [ %54, %42 ]
br i1 %31, label %42, label %35
35: ; preds = %32, %35
%36 = phi i64 [ %40, %35 ], [ 0, %32 ]
%37 = tail call i32 (...) @random()
%38 = srem i32 %37, 10000
%39 = getelementptr inbounds i32, i32* %22, i64 %36
store i32 %38, i32* %39
%40 = add nuw i64 %36, 1
%41 = icmp eq i64 %40, %18
br i1 %41, label %42, label %35
42: ; preds = %35, %32
%43 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%44 = tail call i32 @comb_sort(i32* %22, i64 %18)
%45 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%46 = load <2 x double>, <2 x double>* %5
%47 = load <2 x double>, <2 x double>* %3
%48 = fsub <2 x double> %46, %47
%49 = extractelement <2 x double> %48, i64 1
%50 = fdiv double %49, 1.000000e+06
%51 = extractelement <2 x double> %48, i64 0
%52 = fadd double %51, %50
%53 = fadd double %33, %52
%54 = add nuw nsw i32 %34, 1
%55 = icmp eq i32 %54, 10
br i1 %55, label %56, label %32
56: ; preds = %42
%57 = fdiv double %53, 1.000000e+01
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %57)
%59 = tail call i32 @free(i32* %22)
%60 = load i32, i32* @EXIT_SUCCESS
ret i32 %60
}