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

/* Variables and functions */
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ access(char const *, int /*<<< orphan*/);
const char *random_tell_source(void) {
  size_t i;
  static const char *random_sources[] = {"/dev/urandom", "/dev/random"};
  for (i = 0; i < (sizeof(random_sources) / sizeof((random_sources)[0])); i++) {
    if (!access(random_sources[i], R_OK))
      return random_sources[i];
  }
  return ("libc pseudo-random functions");
}


x86 assembly (clang, -O0):
<random_tell_source>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x10(%rbp)
cmpq   $0x2,-0x10(%rbp)
jae    117f <random_tell_source+0x6f>
mov    -0x10(%rbp),%rcx
lea    0x2efa(%rip),%rax
mov    (%rax,%rcx,8),%rdi
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
call   1030 <access@plt>
cmp    $0x0,%eax
jne    1169 <random_tell_source+0x59>
mov    -0x10(%rbp),%rcx
lea    0x2ed4(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    118a <random_tell_source+0x7a>
jmp    116e <random_tell_source+0x5e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <random_tell_source+0x10>
lea    0xe93(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_tell_source>:
push   %r14
push   %rbx
push   %rax
mov    0x2ec5(%rip),%r14
mov    (%r14),%esi
lea    0xedb(%rip),%rbx
mov    %rbx,%rdi
call   1030 <access@plt>
test   %eax,%eax
je     1150 <random_tell_source+0x40>
mov    (%r14),%esi
lea    0xed2(%rip),%r14
mov    %r14,%rdi
call   1030 <access@plt>
test   %eax,%eax
lea    0xecd(%rip),%rbx
cmove  %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@random_tell_source.random_sources = internal global [2 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i32 0, i32 0)]
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [12 x i8] c"/dev/random\00"
@R_OK = global i32 0
@.str.2 = [29 x i8] c"libc pseudo-random functions\00"
define i8* @random_tell_source() {
%1 = alloca i8*
%2 = alloca i64
store i64 0, i64* %2
br label %3
3: ; preds = %18, %0
%4 = load i64, i64* %2
%5 = icmp ult i64 %4, 2
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = load i64, i64* %2
%8 = getelementptr inbounds [2 x i8*], [2 x i8*]* @random_tell_source.random_sources, i64 0, i64 %7
%9 = load i8*, i8** %8
%10 = load i32, i32* @R_OK
%11 = call i32 @access(i8* %9, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %6
%14 = load i64, i64* %2
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* @random_tell_source.random_sources, i64 0, i64 %14
%16 = load i8*, i8** %15
store i8* %16, i8** %1
br label %22
17: ; preds = %6
br label %18
18: ; preds = %17
%19 = load i64, i64* %2
%20 = add i64 %19, 1
store i64 %20, i64* %2
br label %3
21: ; preds = %3
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %22
22: ; preds = %21, %13
%23 = load i8*, i8** %1
ret i8* %23
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [12 x i8] c"/dev/random\00"
@R_OK = global i32 0
@.str.2 = [29 x i8] c"libc pseudo-random functions\00"
define i8* @random_tell_source() {
%1 = load i32, i32* @R_OK
%2 = tail call i32 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %0
%5 = load i32, i32* @R_OK
%6 = tail call i32 @access(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0)
br label %9
9: ; preds = %4, %0
%10 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %0 ], [ %8, %4 ]
ret i8* %10
}