#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*/ RNDGETENTCNT;
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  int random_fd;
  int ent_count;
  random_fd = open("/dev/random", O_RDONLY);
  if (random_fd < 0)
    return 1;
  if (ioctl(random_fd, RNDGETENTCNT, &ent_count) != 0)
    return 1;
  printf("%d\n", ent_count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1174 <main+0x44>
movl   $0x1,-0x4(%rbp)
jmp    11b5 <main+0x85>
mov    -0x14(%rbp),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     119f <main+0x6f>
movl   $0x1,-0x4(%rbp)
jmp    11b5 <main+0x85>
mov    -0x18(%rbp),%esi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
lea    0xebb(%rip),%rdi
call   1050 <open@plt>
mov    $0x1,%ebx
test   %eax,%eax
js     117f <main+0x4f>
mov    0x2e86(%rip),%rcx
mov    (%rcx),%esi
lea    0xc(%rsp),%rdx
mov    %eax,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
jne    117f <main+0x4f>
mov    0xc(%rsp),%esi
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@RNDGETENTCNT = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %22
13: ; preds = %2
%14 = load i32, i32* %6
%15 = load i32, i32* @RNDGETENTCNT
%16 = call i64 @ioctl(i32 %14, i32 %15, i32* %7)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 1, i32* %3
br label %22
19: ; preds = %13
%20 = load i32, i32* %7
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 0, i32* %3
br label %22
22: ; preds = %19, %18, %12
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@RNDGETENTCNT = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = load i32, i32* @RNDGETENTCNT
%10 = call i64 @ioctl(i32 %6, i32 %9, i32* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %8, %2, %12
%16 = phi i32 [ 0, %12 ], [ 1, %2 ], [ 1, %8 ]
ret i32 %16
}