#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*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
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 scanf(char *, int *);
int /*<<< orphan*/ stderr;
int main(void) {
  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, "Count not open %s for output\n", file);
    exit(EXIT_FAILURE);
  }
  fwrite(numbers, sizeof(double), 1000, iofile);
  fclose(iofile);
  if ((iofile = fopen(file, "rb")) == NULL) {
    fprintf(stderr, "Couldn't open %s for random access\n", file);
    exit(EXIT_FAILURE);
  }
  printf("Enter an index in the range 0-%d\n", 1000 - 1);
  while (scanf("%d", &i) == 1 && 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): ");
  }
  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    127d <main+0xdd>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    -0x1f60(%rbp),%rdx
lea    0xdb5(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%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    0xd89(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x1f78(%rbp)
cmp    $0x0,%rax
jne    12f4 <main+0x154>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
mov    -0x1f60(%rbp),%rdx
lea    0xd5f(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xd69(%rip),%rdi
mov    $0x3e7,%esi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd78(%rip),%rdi
lea    -0x1f64(%rbp),%rsi
call   1090 <scanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x1f79(%rbp)
jne    1355 <main+0x1b5>
xor    %eax,%eax
cmpl   $0x0,-0x1f64(%rbp)
mov    %al,-0x1f79(%rbp)
jl     1355 <main+0x1b5>
cmpl   $0x3e8,-0x1f64(%rbp)
setl   %al
mov    %al,-0x1f79(%rbp)
mov    -0x1f79(%rbp),%al
test   $0x1,%al
jne    1368 <main+0x1c8>
jmp    13dc <main+0x23c>
movslq -0x1f64(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x1f70(%rbp)
mov    -0x1f78(%rbp),%rdi
mov    -0x1f70(%rbp),%rsi
mov    0x2c49(%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    0xcc7(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xcd0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1307 <main+0x167>
mov    -0x1f78(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xcd5(%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     138d <main+0x1ed>
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    0xe0c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     139f <main+0x1ff>
mov    %rax,%rbx
lea    0xe1b(%rip),%rdi
mov    $0x3e7,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2a(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
cmp    $0x1,%eax
jne    1365 <main+0x1c5>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     1365 <main+0x1c5>
cmp    $0x3e7,%eax
jg     1365 <main+0x1c5>
lea    0x8(%rsp),%r14
lea    0xdf7(%rip),%r15
lea    0xe07(%rip),%r12
lea    0xde6(%rip),%r13
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%esi
shl    $0x3,%rsi
mov    0x2ccb(%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
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1090 <scanf@plt>
cmp    $0x1,%eax
jne    1365 <main+0x1c5>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     1365 <main+0x1c5>
cmp    $0x3e8,%eax
jl     1300 <main+0x160>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xda0(%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    0x2c4c(%rip),%rax
mov    (%rax),%edi
lea    0xcd2(%rip),%rsi
jmp    13af <main+0x20f>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
lea    0xce1(%rip),%rsi
lea    0xcaa(%rip),%rdx
call   1070 <fprintf@plt>
mov    0x2c0e(%rip),%rax
mov    (%rax),%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 = [30 x i8] c"Count not open %s for output\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [36 x i8] c"Couldn't open %s for random access\0A\00"
@.str.5 = [34 x i8] c"Enter an index in the range 0-%d\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@.str.7 = [23 x i8] c"The value there is %f\0A\00"
@.str.8 = [36 x i8] c"Next index (out of range to quit): \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 %35
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %25
%36 = getelementptr inbounds [1000 x double], [1000 x double]* %2, i64 0, i64 0
%37 = load i32*, i32** %7
%38 = call i32 @fwrite(double* %36, i32 8, i32 1000, i32* %37)
%39 = load i32*, i32** %7
%40 = call i32 @fclose(i32* %39)
%41 = load i8*, i8** %4
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %42, i32** %7
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %50
44: ; preds = %35
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %4
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %35
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 999)
br label %52
52: ; preds = %63, %50
%53 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %61
55: ; preds = %52
%56 = load i32, i32* %5
%57 = icmp sge i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %5
%60 = icmp slt i32 %59, 1000
br label %61
61: ; preds = %58, %55, %52
%62 = phi i1 [ false, %55 ], [ false, %52 ], [ %60, %58 ]
br i1 %62, label %63, label %76
63: ; preds = %61
%64 = load i32, i32* %5
%65 = sext i32 %64 to i64
%66 = mul i64 %65, 8
store i64 %66, i64* %6
%67 = load i32*, i32** %7
%68 = load i64, i64* %6
%69 = load i32, i32* @SEEK_SET
%70 = call i32 @fseek(i32* %67, i64 %68, i32 %69)
%71 = load i32*, i32** %7
%72 = call i32 @fread(double* %3, i32 8, i32 1, i32* %71)
%73 = load double, double* %3
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), double %73)
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
br label %52
76: ; preds = %61
%77 = load i32*, i32** %7
%78 = call i32 @fclose(i32* %77)
%79 = 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 = [30 x i8] c"Count not open %s for output\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [36 x i8] c"Couldn't open %s for random access\0A\00"
@.str.5 = [34 x i8] c"Enter an index in the range 0-%d\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@.str.7 = [23 x i8] c"The value there is %f\0A\00"
@.str.8 = [36 x i8] c"Next index (out of range to quit): \00"
@.str.9 = [5 x i8] c"Bye!\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 %31
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
%32 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 0
%33 = call i32 @fwrite(double* %32, i32 8, i32 1000, i32* %24)
%34 = tail call i32 @fclose(i32* %24)
%35 = 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))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %31
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 999)
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%45 = icmp eq i32 %44, 1
%46 = load i32, i32* %3
%47 = icmp sgt i32 %46, -1
%48 = select i1 %45, i1 %47, i1 false
%49 = icmp slt i32 %46, 1000
%50 = select i1 %48, i1 %49, i1 false
br i1 %50, label %51, label %68
51: ; preds = %42, %51
%52 = phi i32 [ %63, %51 ], [ %46, %42 ]
%53 = zext i32 %52 to i64
%54 = shl nuw nsw i64 %53, 3
%55 = load i32, i32* @SEEK_SET
%56 = call i32 @fseek(i32* %35, i64 %54, i32 %55)
%57 = call i32 @fread(double* %2, i32 8, i32 1, i32* %35)
%58 = load double, double* %2
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), double %58)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
%61 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%62 = icmp eq i32 %61, 1
%63 = load i32, i32* %3
%64 = icmp sgt i32 %63, -1
%65 = select i1 %62, i1 %64, i1 false
%66 = icmp slt i32 %63, 1000
%67 = select i1 %65, i1 %66, i1 false
br i1 %67, label %51, label %68
68: ; preds = %51, %42
%69 = call i32 @fclose(i32* %35)
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}