#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  char *first;
  int i, ended, flag;
  FILE *fp1;
  struct stat stat1;
  double *df, *ds;
  int dsize;
  double double_min;
  double_min = (1e-10);
  if (argc != 2) {
    printf("usage:  printdouble file\n");
    exit(1);
  }
  if ((fp1 = fopen(argv[1], "r")) == NULL) {
    printf("file not found\n");
    exit(1);
  }
  stat(argv[1], &stat1);
  first = (char *)malloc(stat1.st_size);
  ended = 0;
  while (1) {
    ended += fread(first + ended, 1, stat1.st_size - ended, fp1);
    if (ended >= stat1.st_size)
      break;
  }
  fclose(fp1);
  dsize = stat1.st_size / (sizeof(double) / sizeof(char));
  df = (double *)first;
  flag = 0;
  for (i = 0; i < dsize; i++) {
    printf("a[%d]=%.20e\n", i, df[i]);
    flag++;
  }
  printf("%d values in %s.\n", flag, argv[1]);
  free(first);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xe62(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c5 <main+0x45>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ff <main+0x7f>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x38(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x38(%rbp),%edx
sub    -0x20(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x38(%rbp),%eax
jl     1260 <main+0xe0>
jmp    1265 <main+0xe5>
jmp    1223 <main+0xa3>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movslq -0x38(%rbp),%rax
shr    $0x3,%rax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    12d0 <main+0x150>
mov    -0x1c(%rbp),%esi
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd82(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    128f <main+0x10f>
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1278 <main+0xe8>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe4c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1281 <main+0xf1>
mov    %rax,%r12
mov    0x8(%r14),%rdi
lea    0x8(%rsp),%rsi
call   1080 <stat@plt>
mov    0x8(%rsp),%r13d
mov    %r13d,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movslq %eax,%rbx
lea    (%r15,%rbx,1),%rdi
mov    %r13d,%edx
sub    %ebx,%edx
mov    $0x1,%esi
mov    %r12,%rcx
call   1050 <fread@plt>
add    %ebx,%eax
cmp    %r13d,%eax
jl     11f0 <main+0x60>
mov    %r12,%rdi
call   1060 <fclose@plt>
xor    %esi,%esi
cmp    $0x8,%r13d
jl     124e <main+0xbe>
shr    $0x3,%r13
xor    %ebx,%ebx
lea    0xdd5(%rip),%r12
nopl   (%rax)
movsd  (%r15,%rbx,8),%xmm0
mov    %r12,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1230 <main+0xa0>
mov    %r13d,%esi
mov    0x8(%r14),%rdx
lea    0xdb6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdb1(%rip),%rdi
jmp    1288 <main+0xf8>
lea    0xd99(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [26 x i8] c"usage: printdouble file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"file not found\0A\00"
@.str.3 = [13 x i8] c"a[%d]=%.20e\0A\00"
@.str.4 = [18 x i8] c"%d values in %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca %struct.stat
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32
%15 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 1.000000e-10, double* %15
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %10
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @stat(i8* %33, %struct.stat* %11)
%35 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %6
store i32 0, i32* %8
br label %39
39: ; preds = %30, %59
%40 = load i8*, i8** %6
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%45 = load i32, i32* %44
%46 = load i32, i32* %8
%47 = sub nsw i32 %45, %46
%48 = load i32*, i32** %10
%49 = call i64 @fread(i8* %43, i32 1, i32 %47, i32* %48)
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = add nsw i64 %51, %49
%53 = trunc i64 %52 to i32
store i32 %53, i32* %8
%54 = load i32, i32* %8
%55 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%56 = load i32, i32* %55
%57 = icmp sge i32 %54, %56
br i1 %57, label %58, label %59
58: ; preds = %39
br label %60
59: ; preds = %39
br label %39
60: ; preds = %58
%61 = load i32*, i32** %10
%62 = call i32 @fclose(i32* %61)
%63 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%64 = load i32, i32* %63
%65 = sext i32 %64 to i64
%66 = udiv i64 %65, 8
%67 = trunc i64 %66 to i32
store i32 %67, i32* %14
%68 = load i8*, i8** %6
%69 = bitcast i8* %68 to double*
store double* %69, double** %12
store i32 0, i32* %9
store i32 0, i32* %7
br label %70
70: ; preds = %84, %60
%71 = load i32, i32* %7
%72 = load i32, i32* %14
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %87
74: ; preds = %70
%75 = load i32, i32* %7
%76 = load double*, double** %12
%77 = load i32, i32* %7
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %76, i64 %78
%80 = load double, double* %79
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %75, double %80)
%82 = load i32, i32* %9
%83 = add nsw i32 %82, 1
store i32 %83, i32* %9
br label %84
84: ; preds = %74
%85 = load i32, i32* %7
%86 = add nsw i32 %85, 1
store i32 %86, i32* %7
br label %70
87: ; preds = %70
%88 = load i32, i32* %9
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %88, i8* %91)
%93 = load i8*, i8** %6
%94 = call i32 @free(i8* %93)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [13 x i8] c"a[%d]=%.20e\0A\00"
@.str.4 = [18 x i8] c"%d values in %s.\0A\00"
@str = [15 x i8] c"file not found\00"
@str.5 = [25 x i8] c"usage: printdouble file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = load i8*, i8** %10
%19 = call i32 @stat(i8* %18, %struct.stat* %3)
%20 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
br label %24
24: ; preds = %24, %17
%25 = phi i32 [ 0, %17 ], [ %31, %24 ]
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = sub nsw i32 %21, %25
%29 = tail call i64 @fread(i8* %27, i32 1, i32 %28, i32* %12)
%30 = trunc i64 %29 to i32
%31 = add i32 %25, %30
%32 = icmp slt i32 %31, %21
br i1 %32, label %24, label %33
33: ; preds = %24
%34 = tail call i32 @fclose(i32* %12)
%35 = inttoptr i64 %22 to double*
%36 = icmp sgt i32 %21, 7
br i1 %36, label %37, label %48
37: ; preds = %33
%38 = lshr i32 %21, 3
%39 = zext i32 %38 to i64
br label %40
40: ; preds = %37, %40
%41 = phi i64 [ 0, %37 ], [ %46, %40 ]
%42 = getelementptr inbounds double, double* %35, i64 %41
%43 = load double, double* %42
%44 = trunc i64 %41 to i32
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %44, double %43)
%46 = add nuw nsw i64 %41, 1
%47 = icmp eq i64 %46, %39
br i1 %47, label %48, label %40
48: ; preds = %40, %33
%49 = phi i32 [ 0, %33 ], [ %38, %40 ]
%50 = load i8*, i8** %10
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %49, i8* %50)
%52 = tail call i32 @free(i8* %23)
ret i32 0
}