#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 */
struct timespec {
  unsigned short tv_sec;
  unsigned short tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int RAND_bytes(unsigned char *, int);
int RAND_pseudo_bytes(unsigned char *, int);
int /*<<< orphan*/ RAND_seed(unsigned char *, int);
int /*<<< orphan*/ assert(int);
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int get_random_bytes(unsigned char *, int);
unsigned short getpid();
int /*<<< orphan*/ memcpy(unsigned char *, ...);
long long rdtsc();
int generate_aes_key(unsigned char key[32], unsigned char iv[32]) {
  unsigned char a[64];
  long long r = rdtsc();
  struct timespec T;
  assert(clock_gettime(CLOCK_REALTIME, &T) >= 0);
  memcpy(a, &T.tv_sec, 4);
  memcpy(a + 4, &T.tv_nsec, 4);
  memcpy(a + 8, &r, 8);
  unsigned short p = getpid();
  memcpy(a + 16, &p, 2);
  int s = get_random_bytes(a + 18, 32);
  RAND_seed(a, s + 18);
  assert(RAND_bytes(key, 32));
  assert(RAND_pseudo_bytes(iv, 32));
  return 0;
}


x86 assembly (clang, -O0):
<generate_aes_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <rdtsc@plt>
mov    %rax,-0x58(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
xor    %eax,%eax
mov    $0x4,%edx
call   1090 <memcpy@plt>
lea    -0x50(%rbp),%rdi
add    $0x4,%rdi
lea    -0x60(%rbp),%rsi
add    $0x2,%rsi
xor    %eax,%eax
mov    $0x4,%edx
call   1090 <memcpy@plt>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
xor    %eax,%eax
lea    -0x58(%rbp),%rsi
mov    $0x8,%edx
call   1090 <memcpy@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %ax,-0x62(%rbp)
lea    -0x50(%rbp),%rdi
add    $0x10,%rdi
xor    %eax,%eax
lea    -0x62(%rbp),%rsi
mov    $0x2,%edx
call   1090 <memcpy@plt>
lea    -0x50(%rbp),%rdi
add    $0x12,%rdi
mov    $0x20,%esi
call   10b0 <get_random_bytes@plt>
mov    %eax,-0x68(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x68(%rbp),%esi
add    $0x12,%esi
call   1030 <RAND_seed@plt>
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1060 <RAND_bytes@plt>
mov    %eax,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   10a0 <RAND_pseudo_bytes@plt>
mov    %eax,%edi
call   1080 <assert@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_aes_key>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1070 <rdtsc@plt>
mov    %rax,0x18(%rsp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <clock_gettime@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1090 <memcpy@plt>
lea    0x24(%rsp),%rdi
lea    0x12(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1090 <memcpy@plt>
lea    0x28(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1090 <memcpy@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %ax,0xe(%rsp)
lea    0x30(%rsp),%rdi
lea    0xe(%rsp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1090 <memcpy@plt>
lea    0x32(%rsp),%rdi
mov    $0x20,%esi
call   10b0 <get_random_bytes@plt>
lea    0x12(%rax),%esi
mov    %r12,%rdi
call   1030 <RAND_seed@plt>
mov    %r15,%rdi
mov    $0x20,%esi
call   1060 <RAND_bytes@plt>
mov    %eax,%edi
call   1080 <assert@plt>
mov    %r14,%rdi
mov    $0x20,%esi
call   10a0 <RAND_pseudo_bytes@plt>
mov    %eax,%edi
call   1080 <assert@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i16, i16 }
@CLOCK_REALTIME = global i32 0
define i32 @generate_aes_key(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [64 x i8]
%6 = alloca i64
%7 = alloca %struct.timespec
%8 = alloca i16
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = call i64 (...) @rdtsc()
store i64 %10, i64* %6
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i64 @clock_gettime(i32 %11, %struct.timespec* %7)
%13 = icmp sge i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%18 = call i32 (i8*, ...) @memcpy(i8* %16, i16* %17, i32 4)
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds i8, i8* %19, i64 4
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%22 = call i32 (i8*, ...) @memcpy(i8* %20, i16* %21, i32 4)
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 8
%25 = call i32 (i8*, ...) @memcpy(i8* %24, i64* %6, i32 8)
%26 = call zeroext i16 (...) @getpid()
store i16 %26, i16* %8
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%28 = getelementptr inbounds i8, i8* %27, i64 16
%29 = call i32 (i8*, ...) @memcpy(i8* %28, i16* %8, i32 2)
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%31 = getelementptr inbounds i8, i8* %30, i64 18
%32 = call i32 @get_random_bytes(i8* %31, i32 32)
store i32 %32, i32* %9
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 18
%36 = call i32 @RAND_seed(i8* %33, i32 %35)
%37 = load i8*, i8** %3
%38 = call i32 @RAND_bytes(i8* %37, i32 32)
%39 = call i32 @assert(i32 %38)
%40 = load i8*, i8** %4
%41 = call i32 @RAND_pseudo_bytes(i8* %40, i32 32)
%42 = call i32 @assert(i32 %41)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i16, i16 }
@CLOCK_REALTIME = global i32 0
define i32 @generate_aes_key(i8* %0, i8* %1) {
%3 = alloca [64 x i8]
%4 = alloca i64
%5 = alloca %struct.timespec
%6 = alloca i16
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%8 = bitcast i64* %4 to i8*
%9 = tail call i64 (...) @rdtsc()
store i64 %9, i64* %4
%10 = bitcast %struct.timespec* %5 to i8*
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i64 @clock_gettime(i32 %11, %struct.timespec* %5)
%13 = lshr i64 %12, 63
%14 = trunc i64 %13 to i32
%15 = xor i32 %14, 1
%16 = call i32 @assert(i32 %15)
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
%18 = call i32 (i8*, ...) @memcpy(i8* %7, i16* %17, i32 4)
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 4
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
%21 = call i32 (i8*, ...) @memcpy(i8* %19, i16* %20, i32 4)
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 8
%23 = call i32 (i8*, ...) @memcpy(i8* %22, i64* %4, i32 8)
%24 = bitcast i16* %6 to i8*
%25 = call zeroext i16 (...) @getpid()
store i16 %25, i16* %6
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 16
%27 = call i32 (i8*, ...) @memcpy(i8* %26, i16* %6, i32 2)
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 18
%29 = call i32 @get_random_bytes(i8* %28, i32 32)
%30 = add nsw i32 %29, 18
%31 = call i32 @RAND_seed(i8* %7, i32 %30)
%32 = call i32 @RAND_bytes(i8* %0, i32 32)
%33 = call i32 @assert(i32 %32)
%34 = call i32 @RAND_pseudo_bytes(i8* %1, i32 32)
%35 = call i32 @assert(i32 %34)
ret i32 0
}