#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 *, char *, double, char *);
double shannon_entropy(unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int i;
  char *p;
  double e;
  for (i = 1; i < argc; i++) {
    p = argv[i];
    e = shannon_entropy((unsigned char *)p, strlen(p));
    printf("Shannon entropy of \"%s\" is %f (%s)\n", p, e,
           e < 3.5 ? "bad" : "good");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d0 <main+0xa0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1050 <shannon_entropy@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  0xe60(%rip),%xmm1
lea    0xe89(%rip),%rdx
lea    0xe7e(%rip),%rax
ucomisd %xmm2,%xmm1
cmova  %rax,%rdx
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11a4 <main+0x74>
mov    %rsi,%r15
mov    %edi,%r12d
mov    $0x1,%ebx
lea    0xede(%rip),%rbp
lea    0xeaf(%rip),%r14
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1050 <shannon_entropy@plt>
movsd  0xe82(%rip),%xmm1
ucomisd %xmm0,%xmm1
mov    %rbp,%rdx
lea    0xea0(%rip),%rax
cmova  %rax,%rdx
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Shannon entropy of \22%s\22 is %f (%s)\0A\00"
@.str.1 = [4 x i8] c"bad\00"
@.str.2 = [5 x i8] c"good\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %9
9: ; preds = %30, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %33
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = load i8*, i8** %7
%21 = call i32 @strlen(i8* %20)
%22 = call double @shannon_entropy(i8* %19, i32 %21)
store double %22, double* %8
%23 = load i8*, i8** %7
%24 = load double, double* %8
%25 = load double, double* %8
%26 = fcmp olt double %25, 3.500000e+00
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%29 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %23, double %24, i8* %28)
br label %30
30: ; preds = %13
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %9
33: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Shannon entropy of \22%s\22 is %f (%s)\0A\00"
@.str.1 = [4 x i8] c"bad\00"
@.str.2 = [5 x i8] c"good\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 1, %4 ], [ %15, %6 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = tail call double @shannon_entropy(i8* %9, i32 %10)
%12 = fcmp olt double %11, 3.500000e+00
%13 = select i1 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %9, double %11, i8* %13)
%15 = add nuw nsw i64 %7, 1
%16 = icmp eq i64 %15, %5
br i1 %16, label %17, label %6
17: ; preds = %6, %2
ret i32 0
}