#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*/ i;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ is_prime(unsigned long long);
int /*<<< orphan*/ large_enough(unsigned long long);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned long long);
int /*<<< orphan*/ read(int, unsigned long long *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(void) {
  int err;
  int fd;
  unsigned long long i;
  fd = open("/dev/urandom", O_RDONLY);
  if (fd == -1) {
    err = errno;
    fprintf(stderr, "Could not open /dev/urandom, %s\n", strerror(err));
    exit(EXIT_FAILURE);
  }
  do {
    do {
      read(fd, &i, sizeof(i));
    } while (!large_enough(i));
  } while (!is_prime(i));
  printf("%llu\n", i);
  close(fd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe51(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1201 <main+0x71>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   10b0 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe1f(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1206 <main+0x76>
jmp    120b <main+0x7b>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
mov    -0x18(%rbp),%rdi
call   1040 <large_enough@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    120b <main+0x7b>
jmp    123a <main+0xaa>
mov    -0x18(%rbp),%rdi
call   1080 <is_prime@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1206 <main+0x76>
mov    -0x18(%rbp),%rsi
lea    0xdd0(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    11e8 <main+0x58>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%ebx
call   10b0 <strerror@plt>
lea    0xe3d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
nop
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <read@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <large_enough@plt>
test   %eax,%eax
je     11f0 <main+0x60>
mov    %rbx,%rdi
call   1080 <is_prime@plt>
test   %eax,%eax
je     11f0 <main+0x60>
lea    0xe0b(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"Could not open /dev/urandom, %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c"%llu\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = load i32, i32* @errno
store i32 %10, i32* %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* %2
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
br label %18
18: ; preds = %28, %17
br label %19
19: ; preds = %22, %18
%20 = load i32, i32* %3
%21 = call i32 @read(i32 %20, i64* %4, i32 8)
br label %22
22: ; preds = %19
%23 = load i64, i64* %4
%24 = call i32 @large_enough(i64 %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br i1 %26, label %19, label %27
27: ; preds = %22
br label %28
28: ; preds = %27
%29 = load i64, i64* %4
%30 = call i32 @is_prime(i64 %29)
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
br i1 %32, label %18, label %33
33: ; preds = %28
%34 = load i64, i64* %4
%35 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %34)
%36 = load i32, i32* %3
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* @EXIT_SUCCESS
%39 = call i32 @exit(i32 %38)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"Could not open /dev/urandom, %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c"%llu\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = load i32, i32* @stderr
%9 = tail call i8* @strerror(i32 %7)
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %0, %18
%14 = call i32 @read(i32 %4, i64* %1, i32 8)
%15 = load i64, i64* %1
%16 = tail call i32 @large_enough(i64 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13, %19
br label %13
19: ; preds = %13
%20 = tail call i32 @is_prime(i64 %15)
%21 = icmp eq i32 %20, 0
br i1 %21, label %18, label %22
22: ; preds = %19
%23 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %15)
%24 = tail call i32 @close(i32 %4)
%25 = load i32, i32* @EXIT_SUCCESS
%26 = tail call i32 @exit(i32 %25)
unreachable
}