#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*/ ret;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main() {
  FILE *fp;
  int ret;
  fp = fopen("/dev/urandom", "r");
  if (fp == NULL) {
    fprintf(stderr, "fp is null\n");
    exit(1);
  }
  int reslen = fread(&ret, sizeof(int), 1, fp);
  printf("0x%x\n", ret);
  fclose(fp);
  ret = 0;
  unsigned char *p = (unsigned char *)&ret;
  p[sizeof(ret) - 1] = 255;
  p[sizeof(ret) - 2] = '\n';
  printf("0x%x\n", ret);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b0 <main+0x50>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe47(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x14(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0xff,0x3(%rax)
mov    -0x20(%rbp),%rax
movb   $0xa,0x2(%rax)
mov    -0x14(%rbp),%esi
lea    0xe10(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d0 <main+0x70>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    0x4(%rsp),%esi
lea    0xe7a(%rip),%r14
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movl   $0xff0a0000,0x4(%rsp)
ff
mov    %r14,%rdi
mov    $0xff0a0000,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"fp is null\0A\00"
@.str.3 = [6 x i8] c"0x%x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i32*, i32** %2
%15 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %14)
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
store i32 0, i32* %3
%20 = bitcast i32* %3 to i8*
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 3
store i8 -1, i8* %22
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 2
store i8 10, i8* %24
%25 = load i32, i32* %3
%26 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"fp is null\0A\00"
@.str.3 = [6 x i8] c"0x%x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %3)
%11 = load i32, i32* %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = tail call i32 @fclose(i32* %3)
store i32 -16121856, i32* %1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 -16121856)
ret i32 0
}