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

/* Variables and functions */
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int _generate_random(char *, int);
int _open_random_dev();
int _read_random_dev(int, char *, int);
scalar_t__ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int rand_num = 0;
  int count = 1000;
  char buff[1024] = {
      0,
  };
  int fd = _open_random_dev();
  while (count--) {
    int read_len = _read_random_dev(fd, buff, 1024);
    rand_num = _generate_random(buff, read_len);
    printf("random num = %d\n", rand_num);
  }
  if (close(fd)) {
    printf("Error in closing file\n");
    _exit(errno);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x3e8,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    $0x0,%al
call   1080 <_open_random_dev@plt>
mov    %eax,-0x424(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     1213 <main+0xa3>
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1090 <_read_random_dev@plt>
mov    %eax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%esi
call   1070 <_generate_random@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b7 <main+0x47>
mov    -0x424(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
je     1244 <main+0xd4>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%r15
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
xor    %eax,%eax
call   1090 <_open_random_dev@plt>
mov    %eax,%ebp
mov    $0xfffffc18,%ebx
lea    0xe4c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   10a0 <_read_random_dev@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1080 <_generate_random@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
inc    %ebx
jne    11c0 <main+0x40>
mov    %ebp,%edi
call   1070 <close@plt>
test   %rax,%rax
jne    1205 <main+0x85>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe05(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"random num = %d\0A\00"
@.str.1 = [23 x i8] c"Error in closing file\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1000, i32* %7
%11 = bitcast [1024 x i8]* %8 to i8*
%12 = call i32 (...) @_open_random_dev()
store i32 %12, i32* %9
br label %13
13: ; preds = %17, %2
%14 = load i32, i32* %7
%15 = add nsw i32 %14, -1
store i32 %15, i32* %7
%16 = icmp ne i32 %14, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32, i32* %9
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%20 = call i32 @_read_random_dev(i32 %18, i8* %19, i32 1024)
store i32 %20, i32* %10
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%22 = load i32, i32* %10
%23 = call i32 @_generate_random(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %13
26: ; preds = %13
%27 = load i32, i32* %9
%28 = call i64 @close(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @errno
%33 = call i32 @_exit(i32 %32)
unreachable
34: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"random num = %d\0A\00"
@errno = global i32 0
@str = [22 x i8] c"Error in closing file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @_open_random_dev()
br label %6
6: ; preds = %2, %6
%7 = phi i32 [ 1000, %2 ], [ %8, %6 ]
%8 = add nsw i32 %7, -1
%9 = call i32 @_read_random_dev(i32 %5, i8* %4, i32 1024)
%10 = call i32 @_generate_random(i8* %4, i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %8, 0
br i1 %12, label %13, label %6
13: ; preds = %6
%14 = call i64 @close(i32 %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%18 = load i32, i32* @errno
%19 = call i32 @_exit(i32 %18)
unreachable
20: ; preds = %13
ret i32 0
}