#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int value_from_fd(int);
int check_entropy_status(int quiet) {
  int cur_fd, max_fd;
  int cur_val, max_val;
  if ((cur_fd = open("/proc/sys/kernel/random/entropy_avail", O_RDONLY)) < 0) {
    printf("[-] Cannot open CUR_ENTROPY_FILE\n");
    exit(1);
  }
  if ((max_fd = open("/proc/sys/kernel/random/poolsize", O_RDONLY)) < 0) {
    printf("[-] Cannot open MAX_ENTROPY_FILE\n");
    close(cur_fd);
    exit(1);
  }
  cur_val = value_from_fd(cur_fd);
  max_val = value_from_fd(max_fd);
  close(cur_fd);
  close(max_fd);
  if (cur_val == max_val) {
    if (!quiet)
      printf(" (status: %d/%d)\n", cur_val, max_val);
    printf("[+] Available entropy is set to the maximum (%d)\n", max_val);
    return 0;
  }
  if (!quiet)
    printf(" (status: %d/%d)\n", cur_val, max_val);
  return 1;
}


x86 assembly (clang, -O0):
<check_entropy_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1194 <check_entropy_status+0x44>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11d5 <check_entropy_status+0x85>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%edi
call   1050 <value_from_fd@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <value_from_fd@plt>
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1242 <check_entropy_status+0xf2>
cmpl   $0x0,-0x8(%rbp)
jne    1225 <check_entropy_status+0xd5>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1267 <check_entropy_status+0x117>
cmpl   $0x0,-0x8(%rbp)
jne    1260 <check_entropy_status+0x110>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_entropy_status>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    0x2e76(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xe84(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1222 <check_entropy_status+0xc2>
mov    %eax,%ebx
mov    0x0(%rbp),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1238 <check_entropy_status+0xd8>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <value_from_fd@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1060 <value_from_fd@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
cmp    %r12d,%r15d
jne    11f9 <check_entropy_status+0x99>
test   %r14d,%r14d
jne    11e4 <check_entropy_status+0x84>
lea    0xe70(%rip),%rdi
mov    %r15d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6e(%rip),%rdi
xor    %ebx,%ebx
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1217 <check_entropy_status+0xb7>
mov    $0x1,%ebx
test   %r14d,%r14d
jne    1217 <check_entropy_status+0xb7>
lea    0xe3d(%rip),%rdi
mov    %r15d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"/proc/sys/kernel/random/entropy_avail\00"
@O_RDONLY = global i32 0
@.str.1 = [34 x i8] c"[-] Cannot open CUR_ENTROPY_FILE\0A\00"
@.str.2 = [33 x i8] c"/proc/sys/kernel/random/poolsize\00"
@.str.3 = [34 x i8] c"[-] Cannot open MAX_ENTROPY_FILE\0A\00"
@.str.4 = [18 x i8] c" (status: %d/%d)\0A\00"
@.str.5 = [50 x i8] c"[+] Available entropy is set to the maximum (%d)\0A\00"
define i32 @check_entropy_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %15)
store i32 %16, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = load i32, i32* %4
%25 = call i32 @value_from_fd(i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %5
%27 = call i32 @value_from_fd(i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %4
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %5
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %45
35: ; preds = %23
%36 = load i32, i32* %3
%37 = icmp ne i32 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %39, i32 %40)
br label %42
42: ; preds = %38, %35
%43 = load i32, i32* %7
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i32 %43)
store i32 0, i32* %2
br label %53
45: ; preds = %23
%46 = load i32, i32* %3
%47 = icmp ne i32 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %45
%49 = load i32, i32* %6
%50 = load i32, i32* %7
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %49, i32 %50)
br label %52
52: ; preds = %48, %45
store i32 1, i32* %2
br label %53
53: ; preds = %52, %42
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
@.str = [38 x i8] c"/proc/sys/kernel/random/entropy_avail\00"
@O_RDONLY = global i32 0
@.str.2 = [33 x i8] c"/proc/sys/kernel/random/poolsize\00"
@.str.4 = [18 x i8] c" (status: %d/%d)\0A\00"
@.str.5 = [50 x i8] c"[+] Available entropy is set to the maximum (%d)\0A\00"
@str = [33 x i8] c"[-] Cannot open MAX_ENTROPY_FILE\00"
@str.6 = [33 x i8] c"[-] Cannot open CUR_ENTROPY_FILE\00"
define i32 @check_entropy_status(i32 %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.6, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @close(i32 %3)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = tail call i32 @value_from_fd(i32 %3)
%18 = tail call i32 @value_from_fd(i32 %10)
%19 = tail call i32 @close(i32 %3)
%20 = tail call i32 @close(i32 %10)
%21 = icmp eq i32 %17, %18
%22 = icmp eq i32 %0, 0
br i1 %21, label %23, label %28
23: ; preds = %16
br i1 %22, label %24, label %26
24: ; preds = %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %17, i32 %17)
br label %26
26: ; preds = %24, %23
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i32 %17)
br label %31
28: ; preds = %16
br i1 %22, label %29, label %31
29: ; preds = %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %17, i32 %18)
br label %31
31: ; preds = %28, %29, %26
%32 = phi i32 [ 0, %26 ], [ 1, %29 ], [ 1, %28 ]
ret i32 %32
}