#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 uint32_t;
typedef int /*<<< orphan*/ res;

/* Variables and functions */
int arc4random();
int /*<<< orphan*/ printf(char *, ...);
int _arc4random(char const *progname) {
  uint32_t res[4];
  size_t i;
  printf("%s: Testing arc4random()\n", progname);
  for (i = 0; i < sizeof(res) / sizeof(*res); i++)
    res[i] = arc4random();
  for (i = 0; i < sizeof(res) / sizeof(*res); i++)
    printf("%u. 0x%08x\n", i + 1, res[i]);
  if (res[0] == res[1] && res[0] == res[2] && res[0] == res[3])
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<_arc4random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x4,-0x28(%rbp)
jae    1173 <_arc4random+0x53>
mov    $0x0,%al
call   1030 <arc4random@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1146 <_arc4random+0x26>
movq   $0x0,-0x28(%rbp)
cmpq   $0x4,-0x28(%rbp)
jae    11b5 <_arc4random+0x95>
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117b <_arc4random+0x5b>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11e5 <_arc4random+0xc5>
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11e5 <_arc4random+0xc5>
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11e5 <_arc4random+0xc5>
movl   $0x1,-0x4(%rbp)
jmp    11ec <_arc4random+0xcc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_arc4random>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rsi
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <arc4random@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <arc4random@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <arc4random@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <arc4random@plt>
mov    %eax,%r15d
lea    0xeb4(%rip),%r12
mov    $0x1,%esi
mov    %r12,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%esi
mov    %r12,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3,%esi
mov    %r12,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x4,%esi
mov    %r12,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebx,%r14d
xor    %ebx,%ebp
or     %r14d,%ebp
xor    %r15d,%ebx
xor    %eax,%eax
or     %ebp,%ebx
sete   %al
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"%s: Testing arc4random()\0A\00"
@.str.1 = [12 x i8] c"%u. 0x%08x\0A\00"
define i32 @_arc4random(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i32]
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %6)
store i64 0, i64* %5
br label %8
8: ; preds = %15, %1
%9 = load i64, i64* %5
%10 = icmp ult i64 %9, 4
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = call i32 (...) @arc4random()
%13 = load i64, i64* %5
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %13
store i32 %12, i32* %14
br label %15
15: ; preds = %11
%16 = load i64, i64* %5
%17 = add i64 %16, 1
store i64 %17, i64* %5
br label %8
18: ; preds = %8
store i64 0, i64* %5
br label %19
19: ; preds = %29, %18
%20 = load i64, i64* %5
%21 = icmp ult i64 %20, 4
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = load i64, i64* %5
%24 = add i64 %23, 1
%25 = load i64, i64* %5
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %24, i32 %27)
br label %29
29: ; preds = %22
%30 = load i64, i64* %5
%31 = add i64 %30, 1
store i64 %31, i64* %5
br label %19
32: ; preds = %19
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%36 = load i32, i32* %35
%37 = icmp eq i32 %34, %36
br i1 %37, label %38, label %51
38: ; preds = %32
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%40 = load i32, i32* %39
%41 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%42 = load i32, i32* %41
%43 = icmp eq i32 %40, %42
br i1 %43, label %44, label %51
44: ; preds = %38
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%46 = load i32, i32* %45
%47 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%48 = load i32, i32* %47
%49 = icmp eq i32 %46, %48
br i1 %49, label %50, label %51
50: ; preds = %44
store i32 1, i32* %2
br label %52
51: ; preds = %44, %38, %32
store i32 0, i32* %2
br label %52
52: ; preds = %51, %50
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@.str = [26 x i8] c"%s: Testing arc4random()\0A\00"
@.str.1 = [12 x i8] c"%u. 0x%08x\0A\00"
define i32 @_arc4random(i8* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32 (...) @arc4random()
%4 = tail call i32 (...) @arc4random()
%5 = tail call i32 (...) @arc4random()
%6 = tail call i32 (...) @arc4random()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 1, i32 %3)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 2, i32 %4)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 3, i32 %5)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 4, i32 %6)
%11 = icmp eq i32 %3, %4
%12 = icmp eq i32 %3, %5
%13 = select i1 %11, i1 %12, i1 false
%14 = icmp eq i32 %3, %6
%15 = select i1 %13, i1 %14, i1 false
%16 = zext i1 %15 to i32
ret i32 %16
}