#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 */
double calcEntropy(int);
int findSmallestChannel() {
  double chanEnt[15];
  for (int i = 0; i < 15; i++) {
    chanEnt[i] = calcEntropy(i);
  }
  int index = 0;
  double min = chanEnt[index];
  for (int i = 1; i < 15; i++) {
    if (chanEnt[i] < min) {
      min = chanEnt[i];
      index = i;
    }
  }
  return index;
}


x86 assembly (clang, -O0):
<findSmallestChannel>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x84(%rbp)
cmpl   $0xf,-0x84(%rbp)
jge    115e <findSmallestChannel+0x4e>
mov    -0x84(%rbp),%edi
call   1030 <calcEntropy@plt>
movslq -0x84(%rbp),%rax
movsd  %xmm0,-0x80(%rbp,%rax,8)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1125 <findSmallestChannel+0x15>
movl   $0x0,-0x88(%rbp)
movslq -0x88(%rbp),%rax
movsd  -0x80(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movl   $0x1,-0x94(%rbp)
cmpl   $0xf,-0x94(%rbp)
jge    11ed <findSmallestChannel+0xdd>
movslq -0x94(%rbp),%rax
movsd  -0x80(%rbp,%rax,8),%xmm1
movsd  -0x90(%rbp),%xmm0
ff
ucomisd %xmm1,%xmm0
jbe    11d4 <findSmallestChannel+0xc4>
movslq -0x94(%rbp),%rax
movsd  -0x80(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x94(%rbp),%eax
mov    %eax,-0x88(%rbp)
jmp    11d9 <findSmallestChannel+0xc9>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1187 <findSmallestChannel+0x77>
mov    -0x88(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findSmallestChannel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
xor    %edi,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x70(%rsp)
mov    $0x1,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x68(%rsp)
mov    $0x2,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x60(%rsp)
mov    $0x3,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x58(%rsp)
mov    $0x4,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x50(%rsp)
mov    $0x5,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x48(%rsp)
mov    $0x6,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x40(%rsp)
mov    $0x7,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x38(%rsp)
mov    $0x8,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x30(%rsp)
mov    $0x9,%r15d
mov    $0x9,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x28(%rsp)
mov    $0xa,%r12d
mov    $0xa,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x20(%rsp)
mov    $0xb,%r13d
mov    $0xb,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x18(%rsp)
mov    $0xc,%ebx
mov    $0xc,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x10(%rsp)
mov    $0xd,%ebp
mov    $0xd,%edi
call   1030 <calcEntropy@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xe,%r14d
mov    $0xe,%edi
call   1030 <calcEntropy@plt>
xor    %eax,%eax
movsd  0x70(%rsp),%xmm1
movsd  0x68(%rsp),%xmm2
ucomisd %xmm2,%xmm1
seta   %al
minsd  %xmm1,%xmm2
movsd  0x60(%rsp),%xmm1
ucomisd %xmm1,%xmm2
mov    $0x2,%ecx
cmova  %ecx,%eax
minsd  %xmm2,%xmm1
movsd  0x58(%rsp),%xmm2
ucomisd %xmm2,%xmm1
mov    $0x3,%ecx
cmova  %ecx,%eax
minsd  %xmm1,%xmm2
movsd  0x50(%rsp),%xmm1
ucomisd %xmm1,%xmm2
mov    $0x4,%ecx
cmova  %ecx,%eax
minsd  %xmm2,%xmm1
movsd  0x48(%rsp),%xmm2
ucomisd %xmm2,%xmm1
mov    $0x5,%ecx
cmova  %ecx,%eax
minsd  %xmm1,%xmm2
movsd  0x40(%rsp),%xmm1
ucomisd %xmm1,%xmm2
mov    $0x6,%ecx
cmova  %ecx,%eax
minsd  %xmm2,%xmm1
movsd  0x38(%rsp),%xmm2
ucomisd %xmm2,%xmm1
mov    $0x7,%ecx
cmova  %ecx,%eax
minsd  %xmm1,%xmm2
movsd  0x30(%rsp),%xmm1
ucomisd %xmm1,%xmm2
mov    $0x8,%ecx
cmova  %ecx,%eax
minsd  %xmm2,%xmm1
movsd  0x28(%rsp),%xmm2
ucomisd %xmm2,%xmm1
cmova  %r15d,%eax
minsd  %xmm1,%xmm2
movsd  0x20(%rsp),%xmm1
ucomisd %xmm1,%xmm2
cmova  %r12d,%eax
minsd  %xmm2,%xmm1
movsd  0x18(%rsp),%xmm2
ucomisd %xmm2,%xmm1
cmova  %r13d,%eax
minsd  %xmm1,%xmm2
movsd  0x10(%rsp),%xmm1
ucomisd %xmm1,%xmm2
cmova  %ebx,%eax
minsd  %xmm2,%xmm1
movsd  0x8(%rsp),%xmm2
ucomisd %xmm2,%xmm1
cmova  %ebp,%eax
minsd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
cmova  %r14d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @findSmallestChannel() {
%1 = alloca [15 x double]
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
store i32 0, i32* %2
br label %6
6: ; preds = %15, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 15
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load i32, i32* %2
%11 = call double @calcEntropy(i32 %10)
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [15 x double], [15 x double]* %1, i64 0, i64 %13
store double %11, double* %14
br label %15
15: ; preds = %9
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %6
18: ; preds = %6
store i32 0, i32* %3
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [15 x double], [15 x double]* %1, i64 0, i64 %20
%22 = load double, double* %21
store double %22, double* %4
store i32 1, i32* %5
br label %23
23: ; preds = %40, %18
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 15
br i1 %25, label %26, label %43
26: ; preds = %23
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [15 x double], [15 x double]* %1, i64 0, i64 %28
%30 = load double, double* %29
%31 = load double, double* %4
%32 = fcmp olt double %30, %31
br i1 %32, label %33, label %39
33: ; preds = %26
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [15 x double], [15 x double]* %1, i64 0, i64 %35
%37 = load double, double* %36
store double %37, double* %4
%38 = load i32, i32* %5
store i32 %38, i32* %3
br label %39
39: ; preds = %33, %26
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %23
43: ; preds = %23
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
define i32 @findSmallestChannel() {
%1 = tail call double @calcEntropy(i32 0)
%2 = tail call double @calcEntropy(i32 1)
%3 = tail call double @calcEntropy(i32 2)
%4 = tail call double @calcEntropy(i32 3)
%5 = tail call double @calcEntropy(i32 4)
%6 = tail call double @calcEntropy(i32 5)
%7 = tail call double @calcEntropy(i32 6)
%8 = tail call double @calcEntropy(i32 7)
%9 = tail call double @calcEntropy(i32 8)
%10 = tail call double @calcEntropy(i32 9)
%11 = tail call double @calcEntropy(i32 10)
%12 = tail call double @calcEntropy(i32 11)
%13 = tail call double @calcEntropy(i32 12)
%14 = tail call double @calcEntropy(i32 13)
%15 = tail call double @calcEntropy(i32 14)
%16 = fcmp olt double %2, %1
%17 = zext i1 %16 to i32
%18 = select i1 %16, double %2, double %1
%19 = fcmp olt double %3, %18
%20 = select i1 %19, i32 2, i32 %17
%21 = select i1 %19, double %3, double %18
%22 = fcmp olt double %4, %21
%23 = select i1 %22, i32 3, i32 %20
%24 = select i1 %22, double %4, double %21
%25 = fcmp olt double %5, %24
%26 = select i1 %25, i32 4, i32 %23
%27 = select i1 %25, double %5, double %24
%28 = fcmp olt double %6, %27
%29 = select i1 %28, i32 5, i32 %26
%30 = select i1 %28, double %6, double %27
%31 = fcmp olt double %7, %30
%32 = select i1 %31, i32 6, i32 %29
%33 = select i1 %31, double %7, double %30
%34 = fcmp olt double %8, %33
%35 = select i1 %34, i32 7, i32 %32
%36 = select i1 %34, double %8, double %33
%37 = fcmp olt double %9, %36
%38 = select i1 %37, i32 8, i32 %35
%39 = select i1 %37, double %9, double %36
%40 = fcmp olt double %10, %39
%41 = select i1 %40, i32 9, i32 %38
%42 = select i1 %40, double %10, double %39
%43 = fcmp olt double %11, %42
%44 = select i1 %43, i32 10, i32 %41
%45 = select i1 %43, double %11, double %42
%46 = fcmp olt double %12, %45
%47 = select i1 %46, i32 11, i32 %44
%48 = select i1 %46, double %12, double %45
%49 = fcmp olt double %13, %48
%50 = select i1 %49, i32 12, i32 %47
%51 = select i1 %49, double %13, double %48
%52 = fcmp olt double %14, %51
%53 = select i1 %52, i32 13, i32 %50
%54 = select i1 %52, double %14, double %51
%55 = fcmp olt double %15, %54
%56 = select i1 %55, i32 14, i32 %53
ret i32 %56
}