#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 time_t;
typedef int /*<<< orphan*/ t;
typedef int /*<<< orphan*/ pid;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int getpid();
int /*<<< orphan*/ memcpy(char *, int *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ time(int *);
int sqlite3UnixRandomSeed(char *zBuf) {
  memset(zBuf, 0, 256);
  {
    int pid, fd;
    fd = open("/dev/urandom", O_RDONLY);
    if (fd < 0) {
      time_t t;
      time(&t);
      memcpy(zBuf, &t, sizeof(t));
      pid = getpid();
      memcpy(&zBuf[sizeof(time_t)], &pid, sizeof(pid));
    } else {
      read(fd, zBuf, 256);
      close(fd);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<sqlite3UnixRandomSeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11ee <sqlite3UnixRandomSeed+0x7e>
lea    -0x14(%rbp),%rdi
call   1080 <time@plt>
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
jmp    1207 <sqlite3UnixRandomSeed+0x97>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite3UnixRandomSeed>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0xe6e(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     11b5 <sqlite3UnixRandomSeed+0x45>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11f0 <sqlite3UnixRandomSeed+0x80>
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <time@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,(%rsp)
add    $0x4,%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @sqlite3UnixRandomSeed(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @memset(i8* %6, i32 0, i32 256)
%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* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = call i32 @time(i32* %5)
%14 = load i8*, i8** %2
%15 = call i32 @memcpy(i8* %14, i32* %5, i32 4)
%16 = call i32 (...) @getpid()
store i32 %16, i32* %3
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 4
%19 = call i32 @memcpy(i8* %18, i32* %3, i32 4)
br label %26
20: ; preds = %1
%21 = load i32, i32* %4
%22 = load i8*, i8** %2
%23 = call i32 @read(i32 %21, i8* %22, i32 256)
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
br label %26
26: ; preds = %20, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @sqlite3UnixRandomSeed(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 @memset(i8* %0, i32 0, i32 256)
%5 = bitcast i32* %2 to i8*
%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 slt i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = bitcast i32* %3 to i8*
%11 = call i32 @time(i32* %3)
%12 = call i32 @memcpy(i8* %0, i32* %3, i32 4)
%13 = call i32 (...) @getpid()
store i32 %13, i32* %2
%14 = getelementptr inbounds i8, i8* %0, i64 4
%15 = call i32 @memcpy(i8* %14, i32* %2, i32 4)
br label %19
16: ; preds = %1
%17 = tail call i32 @read(i32 %7, i8* %0, i32 256)
%18 = tail call i32 @close(i32 %7)
br label %19
19: ; preds = %16, %9
ret i32 0
}