#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ fread(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stderr;
int main() {
  double numbers[1000];
  double value;
  const char *file = "numbers.dat";
  int i;
  long pos;
  FILE *iofile;
  for (i = 0; i < 1000; i++)
    numbers[i] = 100.0 * i + 1.0 / (i + 1);
  if ((iofile = fopen(file, "wb")) == NULL) {
    fprintf(stderr, "Could not open %s for output.\n", file);
    exit(1);
  }
  fwrite(numbers, sizeof(double), 1000, iofile);
  fclose(iofile);
  if ((iofile = fopen(file, "rb")) == NULL) {
    fprintf(stderr, "Could not open %s for random access.\n", file);
    exit(1);
  }
  printf("Enter an index in the rang 0-%d.\n", 1000 - 1);
  scanf("%d", &i);
  while (i >= 0 && i < 1000) {
    pos = (long)i * sizeof(double);
    fseek(iofile, pos, SEEK_SET);
    fread(&value, sizeof(double), 1, iofile);
    printf("The value there is %f.\n", value);
    printf("Next index (out of range to quit): \n");
    scanf("%d", &i);
  }
  fclose(iofile);
  puts("Bye!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rax
mov    %rax,-0x1f60(%rbp)
movl   $0x0,-0x1f64(%rbp)
cmpl   $0x3e8,-0x1f64(%rbp)
jge    122f <main+0x8f>
cvtsi2sdl -0x1f64(%rbp),%xmm0
ff
mov    -0x1f64(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm2
movsd  0xe11(%rip),%xmm1
divsd  %xmm2,%xmm1
movsd  0xdfd(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movslq -0x1f64(%rbp),%rax
movsd  %xmm0,-0x1f50(%rbp,%rax,8)
ff ff
mov    -0x1f64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f64(%rbp)
jmp    11ca <main+0x2a>
mov    -0x1f60(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x1f78(%rbp)
cmp    $0x0,%rax
jne    1279 <main+0xd9>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    -0x1f60(%rbp),%rdx
lea    0xdb5(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x1f50(%rbp),%rdi
mov    -0x1f78(%rbp),%rcx
mov    $0x8,%esi
mov    $0x3e8,%edx
call   10c0 <fwrite@plt>
mov    -0x1f78(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1f60(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x1f78(%rbp)
cmp    $0x0,%rax
jne    12ec <main+0x14c>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
mov    -0x1f60(%rbp),%rdx
lea    0xd64(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd74(%rip),%rdi
mov    $0x3e7,%esi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd83(%rip),%rdi
lea    -0x1f64(%rbp),%rsi
call   1090 <scanf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x1f64(%rbp)
mov    %al,-0x1f79(%rbp)
jl     133a <main+0x19a>
cmpl   $0x3e8,-0x1f64(%rbp)
setl   %al
mov    %al,-0x1f79(%rbp)
mov    -0x1f79(%rbp),%al
test   $0x1,%al
jne    134d <main+0x1ad>
jmp    13d4 <main+0x234>
movslq -0x1f64(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x1f70(%rbp)
mov    -0x1f78(%rbp),%rdi
mov    -0x1f70(%rbp),%rsi
mov    0x2c64(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    -0x1f78(%rbp),%rcx
lea    -0x1f58(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
movsd  -0x1f58(%rbp),%xmm0
ff
lea    0xce5(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xcc6(%rip),%rdi
lea    -0x1f64(%rbp),%rsi
call   1090 <scanf@plt>
jmp    1312 <main+0x172>
mov    -0x1f78(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xce2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1f80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f58,%rsp
movdqa 0xe47(%rip),%xmm0
movdqa 0xe4f(%rip),%xmm1
xor    %eax,%eax
pcmpeqd %xmm8,%xmm8
movapd 0xe4f(%rip),%xmm9
movapd 0xe57(%rip),%xmm4
movdqa 0xe5f(%rip),%xmm5
movdqa 0xe67(%rip),%xmm6
nopl   0x0(%rax)
cvtdq2pd %xmm0,%xmm7
pshufd $0xe8,%xmm1,%xmm2
psubd  %xmm8,%xmm2
cvtdq2pd %xmm2,%xmm2
movapd %xmm9,%xmm3
divpd  %xmm2,%xmm3
mulpd  %xmm4,%xmm7
addpd  %xmm3,%xmm7
movapd %xmm7,0x10(%rsp,%rax,8)
add    $0x2,%rax
paddq  %xmm5,%xmm1
paddd  %xmm6,%xmm0
cmp    $0x3e8,%rax
jne    11f0 <main+0x50>
movl   $0x3e8,0x4(%rsp)
lea    0xe24(%rip),%rdi
lea    0xe29(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1372 <main+0x1d2>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x8,%esi
mov    $0x3e8,%edx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xde6(%rip),%rdi
lea    0xe0d(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1384 <main+0x1e4>
mov    %rax,%rbx
lea    0xe1e(%rip),%rdi
mov    $0x3e7,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2d(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x3e7,%eax
ja     134a <main+0x1aa>
lea    0x8(%rsp),%r14
lea    0xe0b(%rip),%r15
lea    0xe21(%rip),%r12
lea    0xdfa(%rip),%r13
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%esi
shl    $0x3,%rsi
mov    0x2cdb(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1080 <fseek@plt>
mov    %r14,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movq   0x8(%rsp),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1090 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x3e8,%eax
jb     12f0 <main+0x150>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xd9b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c67(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
jmp    1394 <main+0x1f4>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
lea    0xcfd(%rip),%rsi
lea    0xcc5(%rip),%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"numbers.dat\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Could not open %s for output.\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [38 x i8] c"Could not open %s for random access.\0A\00"
@.str.5 = [34 x i8] c"Enter an index in the rang 0-%d.\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@.str.7 = [24 x i8] c"The value there is %f.\0A\00"
@.str.8 = [37 x i8] c"Next index (out of range to quit): \0A\00"
@.str.9 = [5 x i8] c"Bye!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x double]
%3 = alloca double
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32*
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %4
store i32 0, i32* %5
br label %8
8: ; preds = %22, %0
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 1000
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32, i32* %5
%13 = sitofp i32 %12 to double
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
%16 = sitofp i32 %15 to double
%17 = fdiv double 1.000000e+00, %16
%18 = call double @llvm.fmuladd.f64(double 1.000000e+02, double %13, double %17)
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1000 x double], [1000 x double]* %2, i64 0, i64 %20
store double %18, double* %21
br label %22
22: ; preds = %11
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %8
25: ; preds = %8
%26 = load i8*, i8** %4
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %7
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %25
%35 = getelementptr inbounds [1000 x double], [1000 x double]* %2, i64 0, i64 0
%36 = load i32*, i32** %7
%37 = call i32 @fwrite(double* %35, i32 8, i32 1000, i32* %36)
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
%40 = load i8*, i8** %4
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %41, i32** %7
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %34
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %4
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %34
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 999)
%50 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %5)
br label %51
51: ; preds = %59, %48
%52 = load i32, i32* %5
%53 = icmp sge i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %5
%56 = icmp slt i32 %55, 1000
br label %57
57: ; preds = %54, %51
%58 = phi i1 [ false, %51 ], [ %56, %54 ]
br i1 %58, label %59, label %73
59: ; preds = %57
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = mul i64 %61, 8
store i64 %62, i64* %6
%63 = load i32*, i32** %7
%64 = load i64, i64* %6
%65 = load i32, i32* @SEEK_SET
%66 = call i32 @fseek(i32* %63, i64 %64, i32 %65)
%67 = load i32*, i32** %7
%68 = call i32 @fread(double* %3, i32 8, i32 1, i32* %67)
%69 = load double, double* %3
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), double %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
%72 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %5)
br label %51
73: ; preds = %57
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
%76 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"numbers.dat\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Could not open %s for output.\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [38 x i8] c"Could not open %s for random access.\0A\00"
@.str.5 = [34 x i8] c"Enter an index in the rang 0-%d.\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@.str.7 = [24 x i8] c"The value there is %f.\0A\00"
@.str.9 = [5 x i8] c"Bye!\00"
@str = [36 x i8] c"Next index (out of range to quit): \00"
define i32 @main() {
%1 = alloca [1000 x double]
%2 = alloca double
%3 = alloca i32
%4 = bitcast [1000 x double]* %1 to i8*
%5 = bitcast double* %2 to i8*
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %7, %0
%8 = phi i64 [ 0, %0 ], [ %19, %7 ]
%9 = phi <2 x i64> [ <i64 0, i64 1>, %0 ], [ %20, %7 ]
%10 = phi <2 x i32> [ <i32 0, i32 1>, %0 ], [ %21, %7 ]
%11 = sitofp <2 x i32> %10 to <2 x double>
%12 = trunc <2 x i64> %9 to <2 x i32>
%13 = add <2 x i32> %12, <i32 1, i32 1>
%14 = sitofp <2 x i32> %13 to <2 x double>
%15 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %14
%16 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %11, <2 x double> <double 1.000000e+02, double 1.000000e+02>, <2 x double> %15)
%17 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %8
%18 = bitcast double* %17 to <2 x double>*
store <2 x double> %16, <2 x double>* %18
%19 = add nuw i64 %8, 2
%20 = add <2 x i64> %9, <i64 2, i64 2>
%21 = add <2 x i32> %10, <i32 2, i32 2>
%22 = icmp eq i64 %19, 1000
br i1 %22, label %23, label %7
23: ; preds = %7
store i32 1000, i32* %3
%24 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %23
%31 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 0
%32 = call i32 @fwrite(double* %31, i32 8, i32 1000, i32* %24)
%33 = tail call i32 @fclose(i32* %24)
%34 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %30
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 999)
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%43 = load i32, i32* %3
%44 = icmp ult i32 %43, 1000
br i1 %44, label %45, label %58
45: ; preds = %40, %45
%46 = phi i32 [ %56, %45 ], [ %43, %40 ]
%47 = zext i32 %46 to i64
%48 = shl nuw nsw i64 %47, 3
%49 = load i32, i32* @SEEK_SET
%50 = call i32 @fseek(i32* %34, i64 %48, i32 %49)
%51 = call i32 @fread(double* %2, i32 8, i32 1, i32* %34)
%52 = load double, double* %2
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), double %52)
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%55 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%56 = load i32, i32* %3
%57 = icmp ult i32 %56, 1000
br i1 %57, label %45, label %58
58: ; preds = %45, %40
%59 = call i32 @fclose(i32* %34)
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}