#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ RNDGETENTCNT;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int get_entropy_cnt(int fd, int argc, char *argv[]) {
  int val;
  int r;
  if (argc != 1) {
    fprintf(stderr, "Incorrect amount of arguments\n");
    usage();
    return EXIT_FAILURE;
  }
  r = ioctl(fd, RNDGETENTCNT, &val);
  if (r != 0) {
    perror("RNDGETENTCNT failed");
    return EXIT_FAILURE;
  }
  printf("entropy count: %u\n", val);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<get_entropy_cnt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     1199 <get_entropy_cnt+0x49>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1060 <usage@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <get_entropy_cnt+0xa3>
mov    -0x8(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11d8 <get_entropy_cnt+0x88>
lea    0xe5d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <get_entropy_cnt+0xa3>
mov    -0x1c(%rbp),%esi
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_entropy_cnt>:
push   %rax
cmp    $0x1,%esi
jne    1186 <get_entropy_cnt+0x36>
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1040 <ioctl@plt>
test   %eax,%eax
jne    11ad <get_entropy_cnt+0x5d>
mov    0x4(%rsp),%esi
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e44(%rip),%rax
jmp    11a9 <get_entropy_cnt+0x59>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe6b(%rip),%rdi
call   1070 <perror@plt>
jmp    11a2 <get_entropy_cnt+0x52>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Incorrect amount of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@RNDGETENTCNT = global i32 0
@.str.1 = [20 x i8] c"RNDGETENTCNT failed\00"
@.str.2 = [19 x i8] c"entropy count: %u\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @get_entropy_cnt(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (...) @usage()
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %4
br label %30
17: ; preds = %3
%18 = load i32, i32* %5
%19 = load i32, i32* @RNDGETENTCNT
%20 = call i32 @ioctl(i32 %18, i32 %19, i32* %8)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
store i32 %25, i32* %4
br label %30
26: ; preds = %17
%27 = load i32, i32* %8
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @EXIT_SUCCESS
store i32 %29, i32* %4
br label %30
30: ; preds = %26, %23, %12
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Incorrect amount of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@RNDGETENTCNT = global i32 0
@.str.1 = [20 x i8] c"RNDGETENTCNT failed\00"
@.str.2 = [19 x i8] c"entropy count: %u\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @get_entropy_cnt(i32 %0, i32 %1, i8** nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i32 %1, 1
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 (...) @usage()
br label %20
11: ; preds = %3
%12 = load i32, i32* @RNDGETENTCNT
%13 = call i32 @ioctl(i32 %0, i32 %12, i32* %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %20
17: ; preds = %11
%18 = load i32, i32* %4
%19 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %15, %7
%21 = phi i32* [ @EXIT_FAILURE, %7 ], [ @EXIT_FAILURE, %15 ], [ @EXIT_SUCCESS, %17 ]
%22 = load i32, i32* %21
ret i32 %22
}