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

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
scalar_t__ parse_double_array(char *, double *, int);
char *readfile(int);
int /*<<< orphan*/ write_double_array(int, double *, int);
void test_double_array() {
  char *p;
  double a[10];
  int i, fd;
  fd = open("testfile", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  assert(fd > 1 && "Couldn't open file to write test output");
  for (i = 0; i < 10; i++) {
    a[i] = (double)i;
  }
  write_double_array(fd, a, 10);
  close(fd);
  fd = open("testfile", O_RDONLY);
  assert(fd > 1 && "Couldn't open file to read test input");
  p = readfile(fd);
  close(fd);
  assert(parse_double_array(p, a, 10) == 0);
  for (i = 0; i < 10; i++) {
    assert(a[i] == ((double)i));
  }
}


x86 assembly (clang, -O0):
<test_double_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    0x2e80(%rip),%rax
or     (%rax),%esi
mov    0x2e6f(%rip),%rax
or     (%rax),%esi
lea    0xe76(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x68(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x68(%rbp)
mov    %al,-0x69(%rbp)
jle    11b2 <test_double_array+0x52>
mov    $0x1,%al
mov    %al,-0x69(%rbp)
jmp    11b2 <test_double_array+0x52>
mov    -0x69(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    11ed <test_double_array+0x8d>
cvtsi2sdl -0x64(%rbp),%xmm0
movslq -0x64(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11c6 <test_double_array+0x66>
mov    -0x68(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xa,%edx
call   1080 <write_double_array@plt>
mov    -0x68(%rbp),%edi
call   1030 <close@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x68(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x68(%rbp)
mov    %al,-0x6a(%rbp)
jle    1239 <test_double_array+0xd9>
mov    $0x1,%al
mov    %al,-0x6a(%rbp)
jmp    1239 <test_double_array+0xd9>
mov    -0x6a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x68(%rbp),%edi
call   1070 <readfile@plt>
mov    %rax,-0x8(%rbp)
mov    -0x68(%rbp),%edi
call   1030 <close@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0xa,%edx
call   1050 <parse_double_array@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    12c1 <test_double_array+0x161>
movslq -0x64(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm0
cvtsi2sdl -0x64(%rbp),%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1284 <test_double_array+0x124>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_double_array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x2e4f(%rip),%rax
mov    0x2e80(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6d(%rip),%rax
or     (%rax),%esi
lea    0xf04(%rip),%r14
mov    %r14,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0x2,%eax
setge  %dil
call   1040 <assert@plt>
movsd  0xe4d(%rip),%xmm1
xorps  %xmm0,%xmm0
movlhps %xmm1,%xmm0
movaps %xmm0,(%rsp)
movaps 0xe8c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe94(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movapd 0xe97(%rip),%xmm0
movapd %xmm0,0x40(%rsp)
mov    %rsp,%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1080 <write_double_array@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0x2,%eax
setge  %dil
call   1040 <assert@plt>
mov    %ebp,%edi
call   1070 <readfile@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <close@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1050 <parse_double_array@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xorpd  %xmm0,%xmm0
cmpeqsd (%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
movsd  0xd87(%rip),%xmm0
cmpeqsd 0x8(%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
movsd  0xd73(%rip),%xmm0
cmpeqsd 0x10(%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
movsd  0xd5f(%rip),%xmm0
cmpeqsd 0x18(%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
movsd  0xd4b(%rip),%xmm0
cmpeqsd 0x20(%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
movsd  0xd37(%rip),%xmm0
cmpeqsd 0x28(%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
movsd  0xd23(%rip),%xmm0
cmpeqsd 0x30(%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
movsd  0xd0f(%rip),%xmm0
cmpeqsd 0x38(%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
movsd  0xcfb(%rip),%xmm0
cmpeqsd 0x40(%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
movsd  0xce7(%rip),%xmm0
cmpeqsd 0x48(%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1040 <assert@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"testfile\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [40 x i8] c"Couldn't open file to write test output\00"
@O_RDONLY = global i32 0
@.str.2 = [38 x i8] c"Couldn't open file to read test input\00"
define void @test_double_array() {
%1 = alloca i8*
%2 = alloca [10 x double]
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9, i32 438)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %0
br label %14
14: ; preds = %13, %0
%15 = phi i1 [ false, %0 ], [ true, %13 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
store i32 0, i32* %3
br label %18
18: ; preds = %27, %14
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = load i32, i32* %3
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 %25
store double %23, double* %26
br label %27
27: ; preds = %21
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %18
30: ; preds = %18
%31 = load i32, i32* %4
%32 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%33 = call i32 @write_double_array(i32 %31, double* %32, i32 10)
%34 = load i32, i32* %4
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* @O_RDONLY
%37 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %36)
store i32 %37, i32* %4
%38 = load i32, i32* %4
%39 = icmp sgt i32 %38, 1
br i1 %39, label %40, label %41
40: ; preds = %30
br label %41
41: ; preds = %40, %30
%42 = phi i1 [ false, %30 ], [ true, %40 ]
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = load i32, i32* %4
%46 = call i8* @readfile(i32 %45)
store i8* %46, i8** %1
%47 = load i32, i32* %4
%48 = call i32 @close(i32 %47)
%49 = load i8*, i8** %1
%50 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%51 = call i64 @parse_double_array(i8* %49, double* %50, i32 10)
%52 = icmp eq i64 %51, 0
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
store i32 0, i32* %3
br label %55
55: ; preds = %68, %41
%56 = load i32, i32* %3
%57 = icmp slt i32 %56, 10
br i1 %57, label %58, label %71
58: ; preds = %55
%59 = load i32, i32* %3
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 %60
%62 = load double, double* %61
%63 = load i32, i32* %3
%64 = sitofp i32 %63 to double
%65 = fcmp oeq double %62, %64
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
br label %68
68: ; preds = %58
%69 = load i32, i32* %3
%70 = add nsw i32 %69, 1
store i32 %70, i32* %3
br label %55
71: ; preds = %55
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"testfile\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDONLY = global i32 0
define void @test_double_array() {
%1 = alloca [10 x double]
%2 = bitcast [10 x double]* %1 to i8*
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7, i32 438)
%9 = icmp sgt i32 %8, 1
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 0
%13 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 1
%14 = bitcast [10 x double]* %1 to <2 x double>*
store <2 x double> <double 0.000000e+00, double 1.000000e+00>, <2 x double>* %14
%15 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 2
%16 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 3
%17 = bitcast double* %15 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 3.000000e+00>, <2 x double>* %17
%18 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 4
%19 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 5
%20 = bitcast double* %18 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 5.000000e+00>, <2 x double>* %20
%21 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 6
%22 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 7
%23 = bitcast double* %21 to <2 x double>*
store <2 x double> <double 6.000000e+00, double 7.000000e+00>, <2 x double>* %23
%24 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 8
%25 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 9
%26 = bitcast double* %24 to <2 x double>*
store <2 x double> <double 8.000000e+00, double 9.000000e+00>, <2 x double>* %26
%27 = call i32 @write_double_array(i32 %8, double* %12, i32 10)
%28 = call i32 @close(i32 %8)
%29 = load i32, i32* @O_RDONLY
%30 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = icmp sgt i32 %30, 1
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i8* @readfile(i32 %30)
%35 = call i32 @close(i32 %30)
%36 = call i64 @parse_double_array(i8* %34, double* %12, i32 10)
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load double, double* %12
%41 = fcmp oeq double %40, 0.000000e+00
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load double, double* %13
%45 = fcmp oeq double %44, 1.000000e+00
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load double, double* %15
%49 = fcmp oeq double %48, 2.000000e+00
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = load double, double* %16
%53 = fcmp oeq double %52, 3.000000e+00
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = load double, double* %18
%57 = fcmp oeq double %56, 4.000000e+00
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = load double, double* %19
%61 = fcmp oeq double %60, 5.000000e+00
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = load double, double* %21
%65 = fcmp oeq double %64, 6.000000e+00
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = load double, double* %22
%69 = fcmp oeq double %68, 7.000000e+00
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = load double, double* %24
%73 = fcmp oeq double %72, 8.000000e+00
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = load double, double* %25
%77 = fcmp oeq double %76, 9.000000e+00
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
ret void
}