#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 */
scalar_t__ hecmw_write_bin_value(unsigned char *, int, int /*<<< orphan*/ *);
int hecmw_write_bin_double_arr(double *x, int n, FILE *fp) {
  int i;
  for (i = 0; i < n; i++, x++) {
    if (hecmw_write_bin_value((unsigned char *)&x, sizeof(double), fp) != 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<hecmw_write_bin_double_arr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117d <hecmw_write_bin_double_arr+0x6d>
lea    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x8,%esi
call   1030 <hecmw_write_bin_value@plt>
cmp    $0x0,%rax
je     115e <hecmw_write_bin_double_arr+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <hecmw_write_bin_double_arr+0x74>
jmp    1163 <hecmw_write_bin_double_arr+0x53>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    112a <hecmw_write_bin_double_arr+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hecmw_write_bin_double_arr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,(%rsp)
xor    %r14d,%r14d
test   %esi,%esi
jle    1157 <hecmw_write_bin_double_arr+0x47>
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x8,%esi
mov    %rbx,%rdx
call   1030 <hecmw_write_bin_value@plt>
test   %rax,%rax
jne    1151 <hecmw_write_bin_double_arr+0x41>
addq   $0x8,(%rsp)
add    $0xffffffff,%ebp
jne    1130 <hecmw_write_bin_double_arr+0x20>
jmp    1157 <hecmw_write_bin_double_arr+0x47>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hecmw_write_bin_double_arr(double* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 0, i32* %8
br label %9
9: ; preds = %20, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = bitcast double** %5 to i8*
%15 = load i32*, i32** %7
%16 = call i64 @hecmw_write_bin_value(i8* %14, i32 8, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %4
br label %26
19: ; preds = %13
br label %20
20: ; preds = %19
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
%23 = load double*, double** %5
%24 = getelementptr inbounds double, double* %23, i32 1
store double* %24, double** %5
br label %9
25: ; preds = %9
store i32 0, i32* %4
br label %26
26: ; preds = %25, %18
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
define i32 @hecmw_write_bin_double_arr(double* %0, i32 %1, i32* %2) {
%4 = alloca double*
%5 = bitcast double** %4 to i8*
store double* %0, double** %4
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %16
7: ; preds = %3, %11
%8 = phi i32 [ %12, %11 ], [ 0, %3 ]
%9 = call i64 @hecmw_write_bin_value(i8* %5, i32 8, i32* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = add nuw nsw i32 %8, 1
%13 = load double*, double** %4
%14 = getelementptr inbounds double, double* %13, i64 1
store double* %14, double** %4
%15 = icmp eq i32 %12, %1
br i1 %15, label %16, label %7
16: ; preds = %7, %11, %3
%17 = phi i32 [ 0, %3 ], [ 0, %11 ], [ -1, %7 ]
ret i32 %17
}