#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_RDWR;
int /*<<< orphan*/ RNDADDTOENTCNT;
int /*<<< orphan*/ errno;
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd = open("/dev/random", O_RDWR);
  int count = 1024;
  if (ioctl(fd, RNDADDTOENTCNT, &count) != 0) {
    printf("RNDADDENTROPY failed: %s\n", strerror(errno));
    return 1;
  }
  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    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x400,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     11bd <main+0x7d>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c4 <main+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1050 <open@plt>
movl   $0x400,0x4(%rsp)
mov    0x2e63(%rip),%rcx
mov    (%rcx),%esi
lea    0x4(%rsp),%rdx
mov    %eax,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
je     119c <main+0x5c>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe7f(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@O_RDWR = global i32 0
@RNDADDTOENTCNT = global i32 0
@.str.1 = [26 x i8] c"RNDADDENTROPY failed: %s\0A\00"
@errno = global i32 0
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_RDWR
%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
store i32 1024, i32* %7
%10 = load i32, i32* %6
%11 = load i32, i32* @RNDADDTOENTCNT
%12 = call i64 @ioctl(i32 %10, i32 %11, i32* %7)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %19
18: ; preds = %2
store i32 0, i32* %3
br label %19
19: ; preds = %18, %14
%20 = load i32, i32* %3
ret i32 %20
}

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