#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*/ uint;
struct timeval {
  int dummy;
};
struct arc4_stream {
  int dummy;
};
typedef int /*<<< orphan*/ rdat;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ arc4_addrandom(struct arc4_stream *, void *, int);
int /*<<< orphan*/ arc4_getbyte(struct arc4_stream *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, int /*<<< orphan*/ *, int);
void arc4_stir(struct arc4_stream *as) {
  int fd;
  struct {
    struct timeval tv;
    uint rnd[(128 - sizeof(struct timeval)) / sizeof(uint)];
  } rdat;
  int n;
  gettimeofday(&rdat.tv, NULL);
  fd = open("/dev/urandom", O_RDONLY);
  if (fd != -1) {
    read(fd, rdat.rnd, sizeof(rdat.rnd));
    close(fd);
  }
  arc4_addrandom(as, (void *)&rdat, sizeof(rdat));
  for (n = 0; n < 256 * 4; n++)
    arc4_getbyte(as);
}


x86 assembly (clang, -O0):
<arc4_stir>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     11c1 <arc4_stir+0x61>
mov    -0xc(%rbp),%edi
lea    -0x90(%rbp),%rsi
add    $0x4,%rsi
mov    $0x7c,%edx
call   1050 <read@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1080 <arc4_addrandom@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x400,-0x94(%rbp)
jge    120d <arc4_stir+0xad>
mov    -0x8(%rbp),%rdi
call   1060 <arc4_getbyte@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11e0 <arc4_stir+0x80>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arc4_stir>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11ac <arc4_stir+0x4c>
mov    %eax,%ebp
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x7c,%edx
call   1050 <read@plt>
mov    %ebp,%edi
call   1040 <close@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x80,%edx
call   1080 <arc4_addrandom@plt>
mov    $0x400,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <arc4_getbyte@plt>
add    $0xffffffff,%ebp
jne    11d0 <arc4_stir+0x70>
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.arc4_stream = type { i32 }
%struct.anon = type { %struct.timeval, [31 x i32] }
%struct.timeval = type { i32 }
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define void @arc4_stir(%struct.arc4_stream* %0) {
%2 = alloca %struct.arc4_stream*
%3 = alloca i32
%4 = alloca %struct.anon
%5 = alloca i32
store %struct.arc4_stream* %0, %struct.arc4_stream** %2
%6 = getelementptr inbounds %struct.anon, %struct.anon* %4, i32 0, i32 0
%7 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %19
12: ; preds = %1
%13 = load i32, i32* %3
%14 = getelementptr inbounds %struct.anon, %struct.anon* %4, i32 0, i32 1
%15 = getelementptr inbounds [31 x i32], [31 x i32]* %14, i64 0, i64 0
%16 = call i32 @read(i32 %13, i32* %15, i32 124)
%17 = load i32, i32* %3
%18 = call i32 @close(i32 %17)
br label %19
19: ; preds = %12, %1
%20 = load %struct.arc4_stream*, %struct.arc4_stream** %2
%21 = bitcast %struct.anon* %4 to i8*
%22 = call i32 @arc4_addrandom(%struct.arc4_stream* %20, i8* %21, i32 128)
store i32 0, i32* %5
br label %23
23: ; preds = %29, %19
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 1024
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load %struct.arc4_stream*, %struct.arc4_stream** %2
%28 = call i32 @arc4_getbyte(%struct.arc4_stream* %27)
br label %29
29: ; preds = %26
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %23
32: ; preds = %23
ret void
}

LLVM IR (-O2):
%struct.arc4_stream = type { i32 }
%struct.anon = type { %struct.timeval, [31 x i32] }
%struct.timeval = type { i32 }
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define void @arc4_stir(%struct.arc4_stream* %0) {
%2 = alloca %struct.anon
%3 = bitcast %struct.anon* %2 to i8*
%4 = getelementptr inbounds %struct.anon, %struct.anon* %2, i64 0, i32 0
%5 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = getelementptr inbounds %struct.anon, %struct.anon* %2, i64 0, i32 1, i64 0
%11 = call i32 @read(i32 %7, i32* %10, i32 124)
%12 = tail call i32 @close(i32 %7)
br label %13
13: ; preds = %9, %1
%14 = call i32 @arc4_addrandom(%struct.arc4_stream* %0, i8* %3, i32 128)
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ 0, %13 ], [ %18, %15 ]
%17 = call i32 @arc4_getbyte(%struct.arc4_stream* %0)
%18 = add nuw nsw i32 %16, 1
%19 = icmp eq i32 %18, 1024
br i1 %19, label %20, label %15
20: ; preds = %15
ret void
}