#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 /*<<< orphan*/ printf(char *, double);
int insertionSort(int *vetor, int tam) {
  int i, j, valorAtual;
  double comparacoes = 0, trocas = 0;
  for (j = 1; j < tam; j++) {
    valorAtual = vetor[j];
    i = j - 1;
    comparacoes++;
    while (i >= 0 && vetor[i] > valorAtual) {
      trocas++;
      vetor[i + 1] = vetor[i];
      i--;
    }
    vetor[i + 1] = valorAtual;
  }
  printf("Tamanho: %d\n", tam);
  printf("Quant. de Comparacoes: %.0f\n", comparacoes);
  printf("Quant. de Trocas: %.0f\n", trocas);
}


x86 assembly (clang, -O0):
<insertionSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fa <insertionSort+0xea>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
movsd  0xe9f(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x31(%rbp)
jl     118e <insertionSort+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x20(%rbp),%eax
setg   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    119e <insertionSort+0x8e>
jmp    11d9 <insertionSort+0xc9>
movsd  0xe5a(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    116b <insertionSort+0x5b>
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1136 <insertionSort+0x26>
cvtsi2sdl -0x14(%rbp),%xmm0
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xdfe(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
lea    0xe0a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertionSort>:
sub    $0x18,%rsp
xorpd  %xmm2,%xmm2
xorpd  %xmm1,%xmm1
cmp    $0x2,%esi
jl     1186 <insertionSort+0x76>
mov    %esi,%r8d
xorpd  %xmm1,%xmm1
mov    $0x1,%r9d
movsd  0xeca(%rip),%xmm0
xorpd  %xmm2,%xmm2
jmp    114f <insertionSort+0x3f>
nopl   0x0(%rax)
cltq
mov    %r10d,(%rdi,%rax,4)
add    $0x1,%r9
cmp    %r8,%r9
je     1186 <insertionSort+0x76>
mov    (%rdi,%r9,4),%r10d
addsd  %xmm0,%xmm2
mov    %r9,%rax
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rax),%rcx
mov    %ecx,%edx
mov    (%rdi,%rdx,4),%edx
cmp    %r10d,%edx
jle    1140 <insertionSort+0x30>
addsd  %xmm0,%xmm1
mov    %edx,(%rdi,%rax,4)
lea    0x1(%rcx),%rdx
mov    %rcx,%rax
cmp    $0x1,%rdx
jg     1160 <insertionSort+0x50>
xor    %eax,%eax
jmp    1140 <insertionSort+0x30>
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
lea    0xe69(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1030 <printf@plt>
lea    0xe74(%rip),%rdi
movsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Tamanho: %d\0A\00"
@.str.1 = [29 x i8] c"Quant. de Comparacoes: %.0f\0A\00"
@.str.2 = [24 x i8] c"Quant. de Trocas: %.0f\0A\00"
define i32 @insertionSort(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i32* %0, i32** %4
store i32 %1, i32* %5
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store i32 1, i32* %7
br label %11
11: ; preds = %60, %2
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %63
15: ; preds = %11
%16 = load i32*, i32** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
store i32 %20, i32* %8
%21 = load i32, i32* %7
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %6
%23 = load double, double* %9
%24 = fadd double %23, 1.000000e+00
store double %24, double* %9
br label %25
25: ; preds = %38, %15
%26 = load i32, i32* %6
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i32*, i32** %4
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %8
%35 = icmp sgt i32 %33, %34
br label %36
36: ; preds = %28, %25
%37 = phi i1 [ false, %25 ], [ %35, %28 ]
br i1 %37, label %38, label %53
38: ; preds = %36
%39 = load double, double* %10
%40 = fadd double %39, 1.000000e+00
store double %40, double* %10
%41 = load i32*, i32** %4
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = load i32*, i32** %4
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %46, i64 %49
store i32 %45, i32* %50
%51 = load i32, i32* %6
%52 = add nsw i32 %51, -1
store i32 %52, i32* %6
br label %25
53: ; preds = %36
%54 = load i32, i32* %8
%55 = load i32*, i32** %4
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %55, i64 %58
store i32 %54, i32* %59
br label %60
60: ; preds = %53
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %11
63: ; preds = %11
%64 = load i32, i32* %5
%65 = sitofp i32 %64 to double
%66 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %65)
%67 = load double, double* %9
%68 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), double %67)
%69 = load double, double* %10
%70 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), double %69)
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [13 x i8] c"Tamanho: %d\0A\00"
@.str.1 = [29 x i8] c"Quant. de Comparacoes: %.0f\0A\00"
@.str.2 = [24 x i8] c"Quant. de Trocas: %.0f\0A\00"
define i32 @insertionSort(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %33
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %25
%7 = phi i64 [ 1, %4 ], [ %31, %25 ]
%8 = phi double [ 0.000000e+00, %4 ], [ %27, %25 ]
%9 = phi double [ 0.000000e+00, %4 ], [ %12, %25 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %7
%11 = load i32, i32* %10
%12 = fadd double %9, 1.000000e+00
br label %13
13: ; preds = %6, %21
%14 = phi i64 [ %7, %6 ], [ %16, %21 ]
%15 = phi double [ %8, %6 ], [ %22, %21 ]
%16 = add nsw i64 %14, -1
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = icmp sgt i32 %19, %11
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = fadd double %15, 1.000000e+00
%23 = getelementptr inbounds i32, i32* %0, i64 %14
store i32 %19, i32* %23
%24 = icmp sgt i64 %14, 1
br i1 %24, label %13, label %25
25: ; preds = %21, %13
%26 = phi i64 [ 0, %21 ], [ %14, %13 ]
%27 = phi double [ %22, %21 ], [ %15, %13 ]
%28 = shl i64 %26, 32
%29 = ashr exact i64 %28, 32
%30 = getelementptr inbounds i32, i32* %0, i64 %29
store i32 %11, i32* %30
%31 = add nuw nsw i64 %7, 1
%32 = icmp eq i64 %31, %5
br i1 %32, label %33, label %6
33: ; preds = %25, %2
%34 = phi double [ 0.000000e+00, %2 ], [ %12, %25 ]
%35 = phi double [ 0.000000e+00, %2 ], [ %27, %25 ]
%36 = sitofp i32 %1 to double
%37 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %36)
%38 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), double %34)
%39 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), double %35)
ret i32 undef
}