#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 EXIT_SUCCESS;
scalar_t__ entropy(int /*<<< orphan*/ *, double *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  if (argc < 2) {
    double e;
    if (entropy(stdin, &e) == 0) {
      printf("<stdin>: %f\n", e);
    }
    return EXIT_SUCCESS;
  }
  for (int i = 1; i < argc; i++) {
    double e;
    const char *path = argv[i];
    FILE *fp = fopen(path, "rb");
    if (!fp) {
      printf("fopen failed: %s\n", path);
      continue;
    }
    if (entropy(fp, &e) == 0) {
      printf("%s: %f\n", path, e);
    }
    fclose(fp);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a1 <main+0x61>
mov    0x2e81(%rip),%rax
mov    (%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <entropy@plt>
cmp    $0x0,%rax
jne    1190 <main+0x50>
movsd  -0x18(%rbp),%xmm0
lea    0xe77(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124b <main+0x10b>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    123f <main+0xff>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11fa <main+0xba>
mov    -0x30(%rbp),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1231 <main+0xf1>
mov    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <entropy@plt>
cmp    $0x0,%rax
jne    1228 <main+0xe8>
mov    -0x30(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
lea    0xe01(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a8 <main+0x68>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%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
jge    1192 <main+0x52>
mov    0x2e91(%rip),%rax
mov    (%rax),%rdi
mov    %rsp,%rsi
call   1050 <entropy@plt>
test   %rax,%rax
jne    117a <main+0x3a>
movsd  (%rsp),%xmm0
lea    0xe8d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%rbx
mov    %edi,%r15d
mov    $0x1,%r12d
lea    0xe68(%rip),%r14
jmp    11c1 <main+0x81>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1030 <fclose@plt>
add    $0x1,%r12
cmp    %r12,%r15
je     117a <main+0x3a>
mov    (%rbx,%r12,8),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1200 <main+0xc0>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rsp,%rsi
call   1050 <entropy@plt>
test   %rax,%rax
jne    11b0 <main+0x70>
movsd  (%rsp),%xmm0
lea    0xe2e(%rip),%rdi
mov    %rbp,%rsi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    11b0 <main+0x70>
lea    0xe09(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b8 <main+0x78>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [13 x i8] c"<stdin>: %f\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"fopen failed: %s\0A\00"
@.str.3 = [8 x i8] c"%s: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca i8*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i32*, i32** @stdin
%15 = call i64 @entropy(i32* %14, double* %6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load double, double* %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %18)
br label %20
20: ; preds = %17, %13
%21 = load i32, i32* @EXIT_SUCCESS
store i32 %21, i32* %3
br label %56
22: ; preds = %2
store i32 1, i32* %7
br label %23
23: ; preds = %51, %22
%24 = load i32, i32* %7
%25 = load i32, i32* %4
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %54
27: ; preds = %23
%28 = load i8**, i8*** %5
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
store i8* %32, i8** %9
%33 = load i8*, i8** %9
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %34, i32** %10
%35 = load i32*, i32** %10
%36 = icmp ne i32* %35, null
br i1 %36, label %40, label %37
37: ; preds = %27
%38 = load i8*, i8** %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %51
40: ; preds = %27
%41 = load i32*, i32** %10
%42 = call i64 @entropy(i32* %41, double* %8)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i8*, i8** %9
%46 = load double, double* %8
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %45, double %46)
br label %48
48: ; preds = %44, %40
%49 = load i32*, i32** %10
%50 = call i32 @fclose(i32* %49)
br label %51
51: ; preds = %48, %37
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %23
54: ; preds = %23
%55 = load i32, i32* @EXIT_SUCCESS
store i32 %55, i32* %3
br label %56
56: ; preds = %54, %20
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [13 x i8] c"<stdin>: %f\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"fopen failed: %s\0A\00"
@.str.3 = [8 x i8] c"%s: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = alloca double
%5 = icmp slt i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = bitcast double* %4 to i8*
%8 = zext i32 %0 to i64
br label %21
9: ; preds = %2
%10 = bitcast double* %3 to i8*
%11 = load i32*, i32** @stdin
%12 = call i64 @entropy(i32* %11, double* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load double, double* %3
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %15)
br label %17
17: ; preds = %14, %9
%18 = load i32, i32* @EXIT_SUCCESS
br label %40
19: ; preds = %37
%20 = load i32, i32* @EXIT_SUCCESS
br label %40
21: ; preds = %6, %37
%22 = phi i64 [ 1, %6 ], [ %38, %37 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %37
29: ; preds = %21
%30 = call i64 @entropy(i32* %25, double* %4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load double, double* %4
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %24, double %33)
br label %35
35: ; preds = %32, %29
%36 = call i32 @fclose(i32* %25)
br label %37
37: ; preds = %35, %27
%38 = add nuw nsw i64 %22, 1
%39 = icmp eq i64 %38, %8
br i1 %39, label %19, label %21
40: ; preds = %19, %17
%41 = phi i32 [ %18, %17 ], [ %20, %19 ]
ret i32 %41
}