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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, long, ...);
int /*<<< orphan*/ scanf(char *, long *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fp;
  int data, count, array[50];
  long offset;
  for (count = 0; count < 50; count++)
    array[count] = count * 10;
  if ((fp = fopen("RANDOM.DAT", "wb")) == NULL) {
    fprintf(stderr, "\nError opening file.");
    exit(1);
  }
  if ((fwrite(array, sizeof(int), 50, fp)) != 50) {
    fprintf(stderr, "\nerror writing data to file.");
    exit(1);
  }
  fclose(fp);
  if ((fp = fopen("RANDOM.DAT", "rb")) == NULL) {
    fprintf(stderr, "\nError opening file.");
    exit(1);
  }
  while (1) {
    printf("\nenter element to read, 0-%d, -1 to quit: ", 50 - 1);
    scanf("%ld", &offset);
    if (offset < 0)
      break;
    else if (offset > 50 - 1)
      continue;
    if ((fseek(fp, (offset * sizeof(int)), SEEK_SET)) != 0) {
      fprintf(stderr, "\nError using fseek().");
      exit(1);
    }
    fread(&data, sizeof(int), 1, fp);
    printf("\nElement %ld has value %d.", offset, data);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x32,-0x20(%rbp)
jge    11d7 <main+0x47>
imul   $0xa,-0x20(%rbp),%ecx
movslq -0x20(%rbp),%rax
mov    %ecx,-0xf0(%rbp,%rax,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b0 <main+0x20>
lea    0xe22(%rip),%rdi
lea    0xe26(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1217 <main+0x87>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x32,%edx
call   10b0 <fwrite@plt>
cmp    $0x32,%eax
je     1259 <main+0xc9>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd97(%rip),%rdi
lea    0xdd0(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    12a2 <main+0x112>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12a7 <main+0x117>
lea    0xd95(%rip),%rdi
mov    $0x31,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdad(%rip),%rdi
lea    -0xf8(%rbp),%rsi
call   1080 <scanf@plt>
cmpq   $0x0,-0xf8(%rbp)
jge    12e0 <main+0x150>
jmp    1372 <main+0x1e2>
cmpq   $0x31,-0xf8(%rbp)
31
jle    12f3 <main+0x163>
jmp    12a7 <main+0x117>
jmp    12f8 <main+0x168>
mov    -0x18(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
shl    $0x2,%rsi
mov    0x2cca(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     133e <main+0x1ae>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0xf8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a7 <main+0x117>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
movaps 0xe58(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe5c(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe60(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe64(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe68(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe6c(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe70(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe75(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe76(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xe77(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xe78(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movabs $0x1ea000001e0,%rax
mov    %rax,0xd0(%rsp)
lea    0xe67(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     13b7 <main+0x227>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x4,%esi
mov    $0x32,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
cmp    $0x32,%eax
jne    13c9 <main+0x239>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe20(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     13b7 <main+0x227>
mov    %rax,%rbx
lea    0xe44(%rip),%rdi
mov    $0x31,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5c(%rip),%rdi
mov    %rsp,%rsi
call   1080 <scanf@plt>
mov    (%rsp),%rsi
test   %rsi,%rsi
js     137c <main+0x1ec>
lea    0xe15(%rip),%r14
lea    0xe39(%rip),%r15
mov    %rsp,%r12
lea    0xc(%rsp),%r13
lea    0xe44(%rip),%rbp
jmp    1333 <main+0x1a3>
cs nopw 0x0(%rax,%rax,1)
mov    $0x31,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
mov    (%rsp),%rsi
test   %rsi,%rsi
js     137c <main+0x1ec>
cmp    $0x31,%rsi
ja     1310 <main+0x180>
shl    $0x2,%rsi
mov    0x2c94(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1070 <fseek@plt>
test   %rax,%rax
jne    1398 <main+0x208>
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    (%rsp),%rsi
mov    0xc(%rsp),%edx
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1310 <main+0x180>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c41(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
lea    0xd07(%rip),%rsi
jmp    13a8 <main+0x218>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
lea    0xd0a(%rip),%rsi
jmp    13a8 <main+0x218>

LLVM IR (-O0):
@.str = [11 x i8] c"RANDOM.DAT\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"\0AError opening file.\00"
@.str.3 = [29 x i8] c"\0Aerror writing data to file.\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [43 x i8] c"\0Aenter element to read, 0-%d, -1 to quit: \00"
@.str.6 = [4 x i8] c"%ld\00"
@SEEK_SET = global i32 0
@.str.7 = [22 x i8] c"\0AError using fseek().\00"
@.str.8 = [27 x i8] c"\0AElement %ld has value %d.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [50 x i32]
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %11
11: ; preds = %20, %2
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 50
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i32, i32* %8
%16 = mul nsw i32 %15, 10
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [50 x i32], [50 x i32]* %9, i64 0, i64 %18
store i32 %16, i32* %19
br label %20
20: ; preds = %14
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
br label %11
23: ; preds = %11
%24 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %23
%31 = getelementptr inbounds [50 x i32], [50 x i32]* %9, i64 0, i64 0
%32 = load i32*, i32** %6
%33 = call i32 @fwrite(i32* %31, i32 4, i32 50, i32* %32)
%34 = icmp ne i32 %33, 50
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %30
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %42, i32** %6
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %39
br label %49
49: ; preds = %48, %58, %71
%50 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i64 49)
%51 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64* %10)
%52 = load i64, i64* %10
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %49
br label %77
55: ; preds = %49
%56 = load i64, i64* %10
%57 = icmp sgt i64 %56, 49
br i1 %57, label %58, label %59
58: ; preds = %55
br label %49
59: ; preds = %55
br label %60
60: ; preds = %59
%61 = load i32*, i32** %6
%62 = load i64, i64* %10
%63 = mul i64 %62, 4
%64 = load i32, i32* @SEEK_SET
%65 = call i64 @fseek(i32* %61, i64 %63, i32 %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %60
%72 = load i32*, i32** %6
%73 = call i32 @fread(i32* %7, i32 4, i32 1, i32* %72)
%74 = load i64, i64* %10
%75 = load i32, i32* %7
%76 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i64 %74, i32 %75)
br label %49
77: ; preds = %54
%78 = load i32*, i32** %6
%79 = call i32 @fclose(i32* %78)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"RANDOM.DAT\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"\0AError opening file.\00"
@.str.3 = [29 x i8] c"\0Aerror writing data to file.\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [43 x i8] c"\0Aenter element to read, 0-%d, -1 to quit: \00"
@.str.6 = [4 x i8] c"%ld\00"
@SEEK_SET = global i32 0
@.str.7 = [22 x i8] c"\0AError using fseek().\00"
@.str.8 = [27 x i8] c"\0AElement %ld has value %d.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [50 x i32]
%5 = alloca i64
%6 = bitcast i32* %3 to i8*
%7 = bitcast [50 x i32]* %4 to i8*
%8 = bitcast i64* %5 to i8*
%9 = bitcast [50 x i32]* %4 to <4 x i32>*
store <4 x i32> <i32 0, i32 10, i32 20, i32 30>, <4 x i32>* %9
%10 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 4
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 40, i32 50, i32 60, i32 70>, <4 x i32>* %11
%12 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 8
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 80, i32 90, i32 100, i32 110>, <4 x i32>* %13
%14 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 12
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 120, i32 130, i32 140, i32 150>, <4 x i32>* %15
%16 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 16
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 160, i32 170, i32 180, i32 190>, <4 x i32>* %17
%18 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 20
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 200, i32 210, i32 220, i32 230>, <4 x i32>* %19
%20 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 24
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 240, i32 250, i32 260, i32 270>, <4 x i32>* %21
%22 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 28
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 280, i32 290, i32 300, i32 310>, <4 x i32>* %23
%24 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 32
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 320, i32 330, i32 340, i32 350>, <4 x i32>* %25
%26 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 36
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 360, i32 370, i32 380, i32 390>, <4 x i32>* %27
%28 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 40
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> <i32 400, i32 410, i32 420, i32 430>, <4 x i32>* %29
%30 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 44
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> <i32 440, i32 450, i32 460, i32 470>, <4 x i32>* %31
%32 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 48
store i32 480, i32* %32
%33 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 49
store i32 490, i32* %33
%34 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %40
36: ; preds = %2
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %2
%41 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
%42 = call i32 @fwrite(i32* %41, i32 4, i32 50, i32* %34)
%43 = icmp eq i32 %42, 50
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = tail call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %40
%49 = tail call i32 @fclose(i32* %34)
%50 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%51 = icmp eq i32* %50, null
br i1 %51, label %57, label %52
52: ; preds = %48
%53 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i64 49)
%54 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64* %5)
%55 = load i64, i64* %5
%56 = icmp slt i64 %55, 0
br i1 %56, label %83, label %61
57: ; preds = %48
%58 = load i32, i32* @stderr
%59 = tail call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%60 = tail call i32 @exit(i32 1)
unreachable
61: ; preds = %52, %78
%62 = phi i64 [ %81, %78 ], [ %55, %52 ]
%63 = icmp ugt i64 %62, 49
br i1 %63, label %78, label %64
64: ; preds = %61
%65 = shl nuw nsw i64 %62, 2
%66 = load i32, i32* @SEEK_SET
%67 = call i64 @fseek(i32* %50, i64 %65, i32 %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %73, label %69
69: ; preds = %64
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %64
%74 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %50)
%75 = load i64, i64* %5
%76 = load i32, i32* %3
%77 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i64 %75, i32 %76)
br label %78
78: ; preds = %73, %61
%79 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i64 49)
%80 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64* %5)
%81 = load i64, i64* %5
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %61
83: ; preds = %78, %52
%84 = call i32 @fclose(i32* %50)
ret i32 0
}