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

/* 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*/ getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, int /*<<< orphan*/ *, int);
void arc4_stir(struct arc4_stream *as) {
  int fd, n, len;
  struct {
    struct timeval tv;
    pid_t pid;
    u_int8_t rnd[128 - sizeof(struct timeval) - sizeof(pid_t)];
  } rdat;
  gettimeofday(&rdat.tv, NULL);
  rdat.pid = getpid();
  fd = open("/dev/urandom", O_RDONLY, 0);
  if (fd >= 0) {
    len = sizeof(rdat.rnd);
    if (read(fd, rdat.rnd, len) != len)
      ;
    close(fd);
  }
  arc4_addrandom(as, (void *)&rdat, sizeof(rdat));
  for (n = 0; n < 1024; n++)
    arc4_getbyte(as);
}


x86 assembly (clang, -O0):
<arc4_stir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x200(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1fc(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11f3 <arc4_stir+0x83>
movl   $0x1e0,-0x14(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x200(%rbp),%rsi
add    $0x8,%rsi
mov    -0x14(%rbp),%edx
call   1060 <read@plt>
cmp    -0x14(%rbp),%eax
je     11eb <arc4_stir+0x7b>
jmp    11eb <arc4_stir+0x7b>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rdi
lea    -0x200(%rbp),%rsi
mov    $0x1e8,%edx
call   1090 <arc4_addrandom@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x400,-0x10(%rbp)
jge    1233 <arc4_stir+0xc3>
mov    -0x8(%rbp),%rdi
call   1070 <arc4_getbyte@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    120f <arc4_stir+0x9f>
add    $0x200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arc4_stir>:
push   %rbp
push   %rbx
sub    $0x1e8,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,0x4(%rsp)
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe5f(%rip),%rdi
xor    %edx,%edx
call   1080 <open@plt>
test   %eax,%eax
js     11c6 <arc4_stir+0x56>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x1e0,%edx
call   1060 <read@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x1e8,%edx
call   1090 <arc4_addrandom@plt>
mov    $0x400,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <arc4_getbyte@plt>
add    $0xffffffff,%ebp
jne    11e0 <arc4_stir+0x70>
add    $0x1e8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.arc4_stream = type { i32 }
%struct.anon = type { %struct.timeval, i32, [120 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 i32
%5 = alloca i32
%6 = alloca %struct.anon
store %struct.arc4_stream* %0, %struct.arc4_stream** %2
%7 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 0
%8 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%9 = call i32 (...) @getpid()
%10 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11, i32 0)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %1
store i32 480, i32* %5
%16 = load i32, i32* %3
%17 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 2
%18 = getelementptr inbounds [120 x i32], [120 x i32]* %17, i64 0, i64 0
%19 = load i32, i32* %5
%20 = call i32 @read(i32 %16, i32* %18, i32 %19)
%21 = load i32, i32* %5
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %15
br label %24
24: ; preds = %23, %15
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %24, %1
%28 = load %struct.arc4_stream*, %struct.arc4_stream** %2
%29 = bitcast %struct.anon* %6 to i8*
%30 = call i32 @arc4_addrandom(%struct.arc4_stream* %28, i8* %29, i32 488)
store i32 0, i32* %4
br label %31
31: ; preds = %37, %27
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 1024
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load %struct.arc4_stream*, %struct.arc4_stream** %2
%36 = call i32 @arc4_getbyte(%struct.arc4_stream* %35)
br label %37
37: ; preds = %34
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %31
40: ; preds = %31
ret void
}

LLVM IR (-O2):
%struct.arc4_stream = type { i32 }
%struct.anon = type { %struct.timeval, i32, [120 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 = tail call i32 (...) @getpid()
%7 = getelementptr inbounds %struct.anon, %struct.anon* %2, i64 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8, i32 0)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = getelementptr inbounds %struct.anon, %struct.anon* %2, i64 0, i32 2, i64 0
%13 = call i32 @read(i32 %9, i32* %12, i32 480)
%14 = tail call i32 @close(i32 %9)
br label %15
15: ; preds = %11, %1
%16 = call i32 @arc4_addrandom(%struct.arc4_stream* %0, i8* %3, i32 488)
br label %17
17: ; preds = %15, %17
%18 = phi i32 [ 0, %15 ], [ %20, %17 ]
%19 = call i32 @arc4_getbyte(%struct.arc4_stream* %0)
%20 = add nuw nsw i32 %18, 1
%21 = icmp eq i32 %20, 1024
br i1 %21, label %22, label %17
22: ; preds = %17
ret void
}