#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*/ randomData;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char **, int);
long randomSeed() {
  int randomFD = open("/dev/random", O_RDONLY);
  char randomData[100];
  memset(randomData, 0, sizeof(randomData));
  long randomValue = 0;
  for (int i = 0; i < 100; i++) {
    read(randomFD, &randomData, 100);
    for (int i = 0; i < 100; i++) {
      randomValue += randomData[i];
    }
  }
  close(randomFD);
  return randomValue;
}


x86 assembly (clang, -O0):
<randomSeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1030 <memset@plt>
movq   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
cmpl   $0x64,-0x7c(%rbp)
jge    11e1 <randomSeed+0xa1>
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
movl   $0x0,-0x80(%rbp)
cmpl   $0x64,-0x80(%rbp)
jge    11ce <randomSeed+0x8e>
movslq -0x80(%rbp),%rax
movsbq -0x70(%rbp,%rax,1),%rax
add    -0x78(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    11a4 <randomSeed+0x64>
jmp    11d3 <randomSeed+0x93>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    1182 <randomSeed+0x42>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x78(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomSeed>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%r15d
mov    %rsp,%r14
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1030 <memset@plt>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1050 <read@plt>
mov    $0x4,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movsbq -0x4(%rsp,%rax,1),%rcx
add    %rbx,%rcx
movsbq -0x3(%rsp,%rax,1),%rdx
add    %rcx,%rdx
movsbq -0x2(%rsp,%rax,1),%rcx
add    %rdx,%rcx
movsbq -0x1(%rsp,%rax,1),%rdx
add    %rcx,%rdx
movsbq (%rsp,%rax,1),%rbx
add    %rdx,%rbx
add    $0x5,%rax
cmp    $0x68,%rax
jne    11a0 <randomSeed+0x60>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1180 <randomSeed+0x40>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %rbx,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
define i64 @randomSeed() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %1
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 100)
store i64 0, i64* %3
store i32 0, i32* %4
br label %10
10: ; preds = %32, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 100
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = load i32, i32* %1
%15 = bitcast [100 x i8]* %2 to i8**
%16 = call i32 @read(i32 %14, i8** %15, i32 100)
store i32 0, i32* %5
br label %17
17: ; preds = %28, %13
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 100
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i64
%26 = load i64, i64* %3
%27 = add nsw i64 %26, %25
store i64 %27, i64* %3
br label %28
28: ; preds = %20
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %17
31: ; preds = %17
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %10
35: ; preds = %10
%36 = load i32, i32* %1
%37 = call i32 @close(i32 %36)
%38 = load i64, i64* %3
ret i64 %38
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
define i64 @randomSeed() {
%1 = alloca [100 x i8]
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 100)
%6 = bitcast [100 x i8]* %1 to i8**
br label %9
7: ; preds = %13
%8 = call i32 @close(i32 %3)
ret i64 %42
9: ; preds = %0, %13
%10 = phi i32 [ 0, %0 ], [ %14, %13 ]
%11 = phi i64 [ 0, %0 ], [ %42, %13 ]
%12 = call i32 @read(i32 %3, i8** %6, i32 100)
br label %16
13: ; preds = %16
%14 = add nuw nsw i32 %10, 1
%15 = icmp eq i32 %14, 100
br i1 %15, label %7, label %9
16: ; preds = %16, %9
%17 = phi i64 [ 0, %9 ], [ %43, %16 ]
%18 = phi i64 [ %11, %9 ], [ %42, %16 ]
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %17
%20 = load i8, i8* %19
%21 = sext i8 %20 to i64
%22 = add nsw i64 %18, %21
%23 = add nuw nsw i64 %17, 1
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i64
%27 = add nsw i64 %22, %26
%28 = add nuw nsw i64 %17, 2
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i64
%32 = add nsw i64 %27, %31
%33 = add nuw nsw i64 %17, 3
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i64
%37 = add nsw i64 %32, %36
%38 = add nuw nsw i64 %17, 4
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i64
%42 = add nsw i64 %37, %41
%43 = add nuw nsw i64 %17, 5
%44 = icmp eq i64 %43, 100
br i1 %44, label %13, label %16
}