#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 */
double *alloc_parse_doubles(int, char *, int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(double *);
double *read_ascii_doubles(int /*<<< orphan*/ *, int *);
int read_n_doubles_from_string(double *out, char *string, int n) {
  for (int i = 0; i < n; i++)
    out[i] = 0;
  int no;
  double *buf = NULL;
  FILE *f = fopen(string, "r");
  if (f) {
    buf = read_ascii_doubles(f, &no);
    fclose(f);
  } else {
    buf = alloc_parse_doubles(n, string, &no);
  }
  if (no > n)
    no = n;
  for (int i = 0; i < no; i++)
    out[i] = buf[i];
  free(buf);
  return no;
}


x86 assembly (clang, -O0):
<read_n_doubles_from_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1194 <read_n_doubles_from_string+0x44>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116a <read_n_doubles_from_string+0x1a>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11da <read_n_doubles_from_string+0x8a>
mov    -0x30(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <read_ascii_doubles@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
jmp    11ee <read_n_doubles_from_string+0x9e>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <alloc_parse_doubles@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1200 <read_n_doubles_from_string+0xb0>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123b <read_n_doubles_from_string+0xeb>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1207 <read_n_doubles_from_string+0xb7>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_n_doubles_from_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
test   %edx,%edx
jle    1185 <read_n_doubles_from_string+0x25>
mov    %r15d,%edx
shl    $0x3,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11b6 <read_n_doubles_from_string+0x56>
mov    %rax,%rbp
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
call   1070 <read_ascii_doubles@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1050 <fclose@plt>
jmp    11c9 <read_n_doubles_from_string+0x69>
lea    0x4(%rsp),%rdx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <alloc_parse_doubles@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%ecx
cmp    %r15d,%ecx
jle    11da <read_n_doubles_from_string+0x7a>
mov    %r15d,0x4(%rsp)
mov    %r15d,%ecx
test   %ecx,%ecx
jle    1344 <read_n_doubles_from_string+0x1e4>
mov    %ecx,%eax
cmp    $0x4,%ecx
jb     11fb <read_n_doubles_from_string+0x9b>
lea    (%rbx,%rax,8),%rcx
cmp    %r14,%rcx
jbe    1270 <read_n_doubles_from_string+0x110>
lea    (%r14,%rax,8),%rcx
cmp    %rcx,%rbx
jae    1270 <read_n_doubles_from_string+0x110>
xor    %ecx,%ecx
mov    %rcx,%rdx
not    %rdx
add    %rax,%rdx
mov    %rax,%rsi
and    $0x3,%rsi
je     1225 <read_n_doubles_from_string+0xc5>
nop
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,(%r14,%rcx,8)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
jne    1210 <read_n_doubles_from_string+0xb0>
cmp    $0x3,%rdx
jb     1344 <read_n_doubles_from_string+0x1e4>
nop
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,(%r14,%rcx,8)
movsd  0x8(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x8(%r14,%rcx,8)
movsd  0x10(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x10(%r14,%rcx,8)
movsd  0x18(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x18(%r14,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%rax
jne    1230 <read_n_doubles_from_string+0xd0>
jmp    1344 <read_n_doubles_from_string+0x1e4>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdi
mov    %rdi,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %esi,%edx
and    $0x3,%edx
cmp    $0xc,%rdi
jae    1293 <read_n_doubles_from_string+0x133>
xor    %edi,%edi
jmp    1300 <read_n_doubles_from_string+0x1a0>
and    $0xfffffffffffffffc,%rsi
xor    %edi,%edi
nopl   0x0(%rax)
movups (%rbx,%rdi,8),%xmm0
movups 0x10(%rbx,%rdi,8),%xmm1
movups %xmm0,(%r14,%rdi,8)
movups %xmm1,0x10(%r14,%rdi,8)
movups 0x20(%rbx,%rdi,8),%xmm0
movups 0x30(%rbx,%rdi,8),%xmm1
movups %xmm0,0x20(%r14,%rdi,8)
movups %xmm1,0x30(%r14,%rdi,8)
movups 0x40(%rbx,%rdi,8),%xmm0
movups 0x50(%rbx,%rdi,8),%xmm1
movups %xmm0,0x40(%r14,%rdi,8)
movups %xmm1,0x50(%r14,%rdi,8)
movups 0x60(%rbx,%rdi,8),%xmm0
movups 0x70(%rbx,%rdi,8),%xmm1
movups %xmm0,0x60(%r14,%rdi,8)
movups %xmm1,0x70(%r14,%rdi,8)
add    $0x10,%rdi
add    $0xfffffffffffffffc,%rsi
jne    12a0 <read_n_doubles_from_string+0x140>
test   %rdx,%rdx
je     133b <read_n_doubles_from_string+0x1db>
lea    (%r14,%rdi,8),%rsi
add    $0x10,%rsi
lea    (%rbx,%rdi,8),%rdi
add    $0x10,%rdi
shl    $0x5,%rdx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movups -0x10(%rdi,%rbp,1),%xmm0
movups (%rdi,%rbp,1),%xmm1
movups %xmm0,-0x10(%rsi,%rbp,1)
movups %xmm1,(%rsi,%rbp,1)
add    $0x20,%rbp
cmp    %rbp,%rdx
jne    1320 <read_n_doubles_from_string+0x1c0>
cmp    %rax,%rcx
jne    11fd <read_n_doubles_from_string+0x9d>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @read_n_doubles_from_string(double* %0, i8* %1, i32 %2) {
%4 = alloca double*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32*
%11 = alloca i32
store double* %0, double** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %12
12: ; preds = %21, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load double*, double** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
store double 0.000000e+00, double* %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %12
24: ; preds = %12
store double* null, double** %9
%25 = load i8*, i8** %5
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %26, i32** %10
%27 = load i32*, i32** %10
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32*, i32** %10
%31 = call double* @read_ascii_doubles(i32* %30, i32* %8)
store double* %31, double** %9
%32 = load i32*, i32** %10
%33 = call i32 @fclose(i32* %32)
br label %38
34: ; preds = %24
%35 = load i32, i32* %6
%36 = load i8*, i8** %5
%37 = call double* @alloc_parse_doubles(i32 %35, i8* %36, i32* %8)
store double* %37, double** %9
br label %38
38: ; preds = %34, %29
%39 = load i32, i32* %8
%40 = load i32, i32* %6
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = load i32, i32* %6
store i32 %43, i32* %8
br label %44
44: ; preds = %42, %38
store i32 0, i32* %11
br label %45
45: ; preds = %59, %44
%46 = load i32, i32* %11
%47 = load i32, i32* %8
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %62
49: ; preds = %45
%50 = load double*, double** %9
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = load double*, double** %4
%56 = load i32, i32* %11
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
store double %54, double* %58
br label %59
59: ; preds = %49
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
br label %45
62: ; preds = %45
%63 = load double*, double** %9
%64 = call i32 @free(double* %63)
%65 = load i32, i32* %8
ret i32 %65
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @read_n_doubles_from_string(double* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = bitcast double* %0 to i8*
%8 = zext i32 %2 to i64
%9 = shl nuw nsw i64 %8, 3
br label %10
10: ; preds = %6, %3
%11 = bitcast i32* %4 to i8*
%12 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call double* @read_ascii_doubles(i32* %12, i32* %4)
%16 = call i32 @fclose(i32* %12)
br label %19
17: ; preds = %10
%18 = call double* @alloc_parse_doubles(i32 %2, i8* %1, i32* %4)
br label %19
19: ; preds = %17, %14
%20 = phi double* [ %15, %14 ], [ %18, %17 ]
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, %2
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 %2, i32* %4
br label %24
24: ; preds = %23, %19
%25 = phi i32 [ %2, %23 ], [ %21, %19 ]
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %133
27: ; preds = %24
%28 = zext i32 %25 to i64
%29 = icmp ult i32 %25, 4
br i1 %29, label %115, label %30
30: ; preds = %27
%31 = getelementptr double, double* %0, i64 %28
%32 = getelementptr double, double* %20, i64 %28
%33 = icmp ugt double* %32, %0
%34 = icmp ult double* %20, %31
%35 = and i1 %33, %34
br i1 %35, label %115, label %36
36: ; preds = %30
%37 = and i64 %28, 4294967292
%38 = add nsw i64 %37, -4
%39 = lshr exact i64 %38, 2
%40 = add nuw nsw i64 %39, 1
%41 = and i64 %40, 3
%42 = icmp ult i64 %38, 12
br i1 %42, label %94, label %43
43: ; preds = %36
%44 = and i64 %40, 9223372036854775804
br label %45
45: ; preds = %45, %43
%46 = phi i64 [ 0, %43 ], [ %91, %45 ]
%47 = phi i64 [ 0, %43 ], [ %92, %45 ]
%48 = getelementptr inbounds double, double* %20, i64 %46
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = getelementptr inbounds double, double* %48, i64 2
%52 = bitcast double* %51 to <2 x double>*
%53 = load <2 x double>, <2 x double>* %52
%54 = getelementptr inbounds double, double* %0, i64 %46
%55 = bitcast double* %54 to <2 x double>*
store <2 x double> %50, <2 x double>* %55
%56 = getelementptr inbounds double, double* %54, i64 2
%57 = bitcast double* %56 to <2 x double>*
store <2 x double> %53, <2 x double>* %57
%58 = or i64 %46, 4
%59 = getelementptr inbounds double, double* %20, i64 %58
%60 = bitcast double* %59 to <2 x double>*
%61 = load <2 x double>, <2 x double>* %60
%62 = getelementptr inbounds double, double* %59, i64 2
%63 = bitcast double* %62 to <2 x double>*
%64 = load <2 x double>, <2 x double>* %63
%65 = getelementptr inbounds double, double* %0, i64 %58
%66 = bitcast double* %65 to <2 x double>*
store <2 x double> %61, <2 x double>* %66
%67 = getelementptr inbounds double, double* %65, i64 2
%68 = bitcast double* %67 to <2 x double>*
store <2 x double> %64, <2 x double>* %68
%69 = or i64 %46, 8
%70 = getelementptr inbounds double, double* %20, i64 %69
%71 = bitcast double* %70 to <2 x double>*
%72 = load <2 x double>, <2 x double>* %71
%73 = getelementptr inbounds double, double* %70, i64 2
%74 = bitcast double* %73 to <2 x double>*
%75 = load <2 x double>, <2 x double>* %74
%76 = getelementptr inbounds double, double* %0, i64 %69
%77 = bitcast double* %76 to <2 x double>*
store <2 x double> %72, <2 x double>* %77
%78 = getelementptr inbounds double, double* %76, i64 2
%79 = bitcast double* %78 to <2 x double>*
store <2 x double> %75, <2 x double>* %79
%80 = or i64 %46, 12
%81 = getelementptr inbounds double, double* %20, i64 %80
%82 = bitcast double* %81 to <2 x double>*
%83 = load <2 x double>, <2 x double>* %82
%84 = getelementptr inbounds double, double* %81, i64 2
%85 = bitcast double* %84 to <2 x double>*
%86 = load <2 x double>, <2 x double>* %85
%87 = getelementptr inbounds double, double* %0, i64 %80
%88 = bitcast double* %87 to <2 x double>*
store <2 x double> %83, <2 x double>* %88
%89 = getelementptr inbounds double, double* %87, i64 2
%90 = bitcast double* %89 to <2 x double>*
store <2 x double> %86, <2 x double>* %90
%91 = add nuw i64 %46, 16
%92 = add nuw i64 %47, 4
%93 = icmp eq i64 %92, %44
br i1 %93, label %94, label %45
94: ; preds = %45, %36
%95 = phi i64 [ 0, %36 ], [ %91, %45 ]
%96 = icmp eq i64 %41, 0
br i1 %96, label %113, label %97
97: ; preds = %94, %97
%98 = phi i64 [ %110, %97 ], [ %95, %94 ]
%99 = phi i64 [ %111, %97 ], [ 0, %94 ]
%100 = getelementptr inbounds double, double* %20, i64 %98
%101 = bitcast double* %100 to <2 x double>*
%102 = load <2 x double>, <2 x double>* %101
%103 = getelementptr inbounds double, double* %100, i64 2
%104 = bitcast double* %103 to <2 x double>*
%105 = load <2 x double>, <2 x double>* %104
%106 = getelementptr inbounds double, double* %0, i64 %98
%107 = bitcast double* %106 to <2 x double>*
store <2 x double> %102, <2 x double>* %107
%108 = getelementptr inbounds double, double* %106, i64 2
%109 = bitcast double* %108 to <2 x double>*
store <2 x double> %105, <2 x double>* %109
%110 = add nuw i64 %98, 4
%111 = add i64 %99, 1
%112 = icmp eq i64 %111, %41
br i1 %112, label %113, label %97
113: ; preds = %97, %94
%114 = icmp eq i64 %37, %28
br i1 %114, label %133, label %115
115: ; preds = %30, %27, %113
%116 = phi i64 [ 0, %30 ], [ 0, %27 ], [ %37, %113 ]
%117 = xor i64 %116, -1
%118 = add nsw i64 %117, %28
%119 = and i64 %28, 3
%120 = icmp eq i64 %119, 0
br i1 %120, label %130, label %121
121: ; preds = %115, %121
%122 = phi i64 [ %127, %121 ], [ %116, %115 ]
%123 = phi i64 [ %128, %121 ], [ 0, %115 ]
%124 = getelementptr inbounds double, double* %20, i64 %122
%125 = load double, double* %124
%126 = getelementptr inbounds double, double* %0, i64 %122
store double %125, double* %126
%127 = add nuw nsw i64 %122, 1
%128 = add i64 %123, 1
%129 = icmp eq i64 %128, %119
br i1 %129, label %130, label %121
130: ; preds = %121, %115
%131 = phi i64 [ %116, %115 ], [ %127, %121 ]
%132 = icmp ult i64 %118, 3
br i1 %132, label %133, label %136
133: ; preds = %130, %136, %113, %24
%134 = call i32 @free(double* %20)
%135 = load i32, i32* %4
ret i32 %135
136: ; preds = %130, %136
%137 = phi i64 [ %153, %136 ], [ %131, %130 ]
%138 = getelementptr inbounds double, double* %20, i64 %137
%139 = load double, double* %138
%140 = getelementptr inbounds double, double* %0, i64 %137
store double %139, double* %140
%141 = add nuw nsw i64 %137, 1
%142 = getelementptr inbounds double, double* %20, i64 %141
%143 = load double, double* %142
%144 = getelementptr inbounds double, double* %0, i64 %141
store double %143, double* %144
%145 = add nuw nsw i64 %137, 2
%146 = getelementptr inbounds double, double* %20, i64 %145
%147 = load double, double* %146
%148 = getelementptr inbounds double, double* %0, i64 %145
store double %147, double* %148
%149 = add nuw nsw i64 %137, 3
%150 = getelementptr inbounds double, double* %20, i64 %149
%151 = load double, double* %150
%152 = getelementptr inbounds double, double* %0, i64 %149
store double %151, double* %152
%153 = add nuw nsw i64 %137, 4
%154 = icmp eq i64 %153, %28
br i1 %154, label %133, label %136
}