#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ do_entropy(char *, int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  extern int optind, getopt();
  int ch, use_bayes, error;
  error = 0;
  use_bayes = 1;
  while ((ch = getopt(argc, argv, "bB")) != EOF) {
    switch (ch) {
    case 'b':
      use_bayes = 2;
      break;
    case 'B':
      use_bayes = 4;
      break;
    default:
      error = 1;
      break;
    }
  }
  if (error) {
    fprintf(stderr, "usage: entropy [-b] [-B] {files}\n");
    fprintf(stderr, " no option means use k/N as probability estimate\n");
    fprintf(stderr, " -b means use (k+1)/(N+m) as probability estimate\n");
    fprintf(stderr, " -B means use Bayesian unbiased estimator for H\n");
    exit(1);
  }
  if (optind >= argc) {
    do_entropy("-", stdin, use_bayes, 0);
  } else {
    int i;
    FILE *f;
    for (i = optind; i < argc; i++) {
      f = fopen(argv[i], "r");
      if (!f) {
        fprintf(stderr, "entropy: cannot open file %s\n", argv[i]);
        exit(1);
      }
      do_entropy(argv[i], f, use_bayes, 1);
    }
  }
  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   $0x0,-0x1c(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdx
mov    $0x0,%al
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%eax
je     11e4 <main+0x94>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x42,%eax
je     11cc <main+0x7c>
jmp    11af <main+0x5f>
mov    -0x2c(%rbp),%eax
sub    $0x62,%eax
jne    11d8 <main+0x88>
jmp    11c0 <main+0x70>
movl   $0x2,-0x18(%rbp)
jmp    11df <main+0x8f>
movl   $0x4,-0x18(%rbp)
jmp    11df <main+0x8f>
movl   $0x1,-0x1c(%rbp)
jmp    1174 <main+0x24>
cmpl   $0x0,-0x1c(%rbp)
je     1254 <main+0x104>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     1286 <main+0x136>
mov    0x2d7b(%rip),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%edx
lea    0xe41(%rip),%rdi
xor    %ecx,%ecx
call   1030 <do_entropy@plt>
jmp    1322 <main+0x1d2>
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    131d <main+0x1cd>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe0c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12f2 <main+0x1a2>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%ecx
call   1030 <do_entropy@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1292 <main+0x142>
jmp    1322 <main+0x1d2>
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
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xe98(%rip),%rdx
xor    %eax,%eax
call   1060 <getopt@plt>
mov    0x2e6a(%rip),%r12
mov    $0x1,%r13d
cmp    (%r12),%eax
je     11e0 <main+0x90>
mov    $0x1,%r13d
lea    0xe71(%rip),%r15
xor    %ebp,%ebp
jmp    11bb <main+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <getopt@plt>
cmp    (%r12),%eax
je     11d8 <main+0x88>
cmp    $0x62,%eax
je     11d0 <main+0x80>
cmp    $0x42,%eax
jne    11a0 <main+0x50>
mov    $0x4,%r13d
jmp    11a5 <main+0x55>
nopl   (%rax)
mov    $0x2,%r13d
jmp    11a5 <main+0x55>
test   %ebp,%ebp
jne    1281 <main+0x131>
mov    0x2de1(%rip),%rax
movslq (%rax),%rbp
cmp    %r14d,%ebp
jge    1230 <main+0xe0>
movslq %r14d,%r15
lea    0xec4(%rip),%r14
nopl   0x0(%rax)
mov    (%rbx,%rbp,8),%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     125c <main+0x10c>
mov    (%rbx,%rbp,8),%rdi
mov    %rax,%rsi
mov    %r13d,%edx
mov    $0x1,%ecx
call   1030 <do_entropy@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1200 <main+0xb0>
jmp    124b <main+0xfb>
mov    0x2db1(%rip),%rax
mov    (%rax),%rsi
lea    0xe7a(%rip),%rdi
mov    %r13d,%edx
xor    %ecx,%ecx
call   1030 <do_entropy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%rbp,8),%rdx
lea    0xe4f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2d48(%rip),%rbx
mov    (%rbx),%edi
lea    0xd72(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd84(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xda6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"bB\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"usage: entropy [-b] [-B] {files}\0A\00"
@.str.2 = [50 x i8] c" no option means use k/N as probability estimate\0A\00"
@.str.3 = [51 x i8] c" -b means use (k+1)/(N+m) as probability estimate\0A\00"
@.str.4 = [49 x i8] c" -B means use Bayesian unbiased estimator for H\0A\00"
@optind = external global i32
@.str.5 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [30 x i8] c"entropy: cannot open file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 1, i32* %7
br label %11
11: ; preds = %22, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 (i32, i8**, i8*, ...) bitcast (i32 (...)* @getopt to i32 (i32, i8**, i8*, ...)*)(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i32, i32* %6
switch i32 %18, label %21 [
i32 98, label %19
i32 66, label %20
]
19: ; preds = %17
store i32 2, i32* %7
br label %22
20: ; preds = %17
store i32 4, i32* %7
br label %22
21: ; preds = %17
store i32 1, i32* %8
br label %22
22: ; preds = %21, %20, %19
br label %11
23: ; preds = %11
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %23
%37 = load i32, i32* @optind
%38 = load i32, i32* %4
%39 = icmp sge i32 %37, %38
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i32*, i32** @stdin
%42 = load i32, i32* %7
%43 = call i32 @do_entropy(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* %41, i32 %42, i32 0)
br label %81
44: ; preds = %36
%45 = load i32, i32* @optind
store i32 %45, i32* %9
br label %46
46: ; preds = %77, %44
%47 = load i32, i32* %9
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %80
50: ; preds = %46
%51 = load i8**, i8*** %5
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %56, i32** %10
%57 = load i32*, i32** %10
%58 = icmp ne i32* %57, null
br i1 %58, label %68, label %59
59: ; preds = %50
%60 = load i32, i32* @stderr
%61 = load i8**, i8*** %5
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %65)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %50
%69 = load i8**, i8*** %5
%70 = load i32, i32* %9
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8*, i8** %69, i64 %71
%73 = load i8*, i8** %72
%74 = load i32*, i32** %10
%75 = load i32, i32* %7
%76 = call i32 @do_entropy(i8* %73, i32* %74, i32 %75, i32 1)
br label %77
77: ; preds = %68
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
store i32 %79, i32* %9
br label %46
80: ; preds = %46
br label %81
81: ; preds = %80, %40
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"bB\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"usage: entropy [-b] [-B] {files}\0A\00"
@.str.2 = [50 x i8] c" no option means use k/N as probability estimate\0A\00"
@.str.3 = [51 x i8] c" -b means use (k+1)/(N+m) as probability estimate\0A\00"
@.str.4 = [49 x i8] c" -B means use Bayesian unbiased estimator for H\0A\00"
@optind = external global i32
@.str.5 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [30 x i8] c"entropy: cannot open file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (i32, i8**, i8*, ...) bitcast (i32 (...)* @getopt to i32 (i32, i8**, i8*, ...)*)(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %30, label %6
6: ; preds = %2, %12
%7 = phi i32 [ %15, %12 ], [ %3, %2 ]
%8 = phi i32 [ %14, %12 ], [ 1, %2 ]
%9 = phi i32 [ %13, %12 ], [ 0, %2 ]
switch i32 %7, label %11 [
i32 98, label %12
i32 66, label %10
]
10: ; preds = %6
br label %12
11: ; preds = %6
br label %12
12: ; preds = %6, %11, %10
%13 = phi i32 [ 1, %11 ], [ %9, %10 ], [ %9, %6 ]
%14 = phi i32 [ %8, %11 ], [ 4, %10 ], [ 2, %6 ]
%15 = tail call i32 (i32, i8**, i8*, ...) bitcast (i32 (...)* @getopt to i32 (i32, i8**, i8*, ...)*)(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %6
18: ; preds = %12
%19 = icmp eq i32 %13, 0
br i1 %19, label %30, label %20
20: ; preds = %18
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %2, %18
%31 = phi i32 [ %14, %18 ], [ 1, %2 ]
%32 = load i32, i32* @optind
%33 = icmp slt i32 %32, %0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = sext i32 %32 to i64
%36 = sext i32 %0 to i64
br label %40
37: ; preds = %30
%38 = load i32*, i32** @stdin
%39 = tail call i32 @do_entropy(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* %38, i32 %31, i32 0)
br label %56
40: ; preds = %34, %51
%41 = phi i64 [ %35, %34 ], [ %54, %51 ]
%42 = getelementptr inbounds i8*, i8** %1, i64 %41
%43 = load i8*, i8** %42
%44 = tail call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %42
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %48)
%50 = tail call i32 @exit(i32 1)
unreachable
51: ; preds = %40
%52 = load i8*, i8** %42
%53 = tail call i32 @do_entropy(i8* %52, i32* %44, i32 %31, i32 1)
%54 = add nsw i64 %41, 1
%55 = icmp eq i64 %54, %36
br i1 %55, label %56, label %40
56: ; preds = %51, %37
ret i32 0
}