#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 /*<<< orphan*/ ConvertWriteDouble(int, double);
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int);
int main(int argc, char *argv[]) {
  int i;
  double val[8] = {0.1, 0.2, 0.5, -0.5, 0.6, 1.2, 1.8, -0.8};
  int fd;
  fd = open("test.dat", O_WRONLY | O_CREAT);
  for (i = 0; i < 8; i++)
    ConvertWriteDouble(fd, val[i]);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e7d(%rip),%rax
or     (%rax),%esi
lea    0xebc(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x64(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    11bd <main+0x7d>
mov    -0x64(%rbp),%edi
movslq -0x14(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm0
call   1050 <ConvertWriteDouble@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <main+0x53>
mov    -0x64(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e98(%rip),%rax
mov    0x2eb9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xef6(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
movsd  0xea7(%rip),%xmm0
mov    %eax,%edi
call   1040 <ConvertWriteDouble@plt>
movsd  0xea0(%rip),%xmm0
mov    %ebx,%edi
call   1040 <ConvertWriteDouble@plt>
movsd  0xe99(%rip),%xmm0
mov    %ebx,%edi
call   1040 <ConvertWriteDouble@plt>
movsd  0xe92(%rip),%xmm0
mov    %ebx,%edi
call   1040 <ConvertWriteDouble@plt>
movsd  0xe8b(%rip),%xmm0
mov    %ebx,%edi
call   1040 <ConvertWriteDouble@plt>
movsd  0xe84(%rip),%xmm0
mov    %ebx,%edi
call   1040 <ConvertWriteDouble@plt>
movsd  0xe7d(%rip),%xmm0
mov    %ebx,%edi
call   1040 <ConvertWriteDouble@plt>
movsd  0xe76(%rip),%xmm0
mov    %ebx,%edi
call   1040 <ConvertWriteDouble@plt>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.val = [8 x double] [double 1.000000e-01, double 2.000000e-01, double 5.000000e-01, double -5.000000e-01, double 6.000000e-01, double 1.200000e+00, double 1.800000e+00, double -8.000000e-01]
@.str = [9 x i8] c"test.dat\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [8 x double]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [8 x double]* %7 to i8*
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %8
store i32 0, i32* %6
br label %14
14: ; preds = %24, %2
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 8
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [8 x double], [8 x double]* %7, i64 0, i64 %20
%22 = load double, double* %21
%23 = call i32 @ConvertWriteDouble(i32 %18, double %22)
br label %24
24: ; preds = %17
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %14
27: ; preds = %14
%28 = load i32, i32* %8
%29 = call i32 @close(i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.dat\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @ConvertWriteDouble(i32 %6, double 1.000000e-01)
%8 = tail call i32 @ConvertWriteDouble(i32 %6, double 2.000000e-01)
%9 = tail call i32 @ConvertWriteDouble(i32 %6, double 5.000000e-01)
%10 = tail call i32 @ConvertWriteDouble(i32 %6, double -5.000000e-01)
%11 = tail call i32 @ConvertWriteDouble(i32 %6, double 6.000000e-01)
%12 = tail call i32 @ConvertWriteDouble(i32 %6, double 1.200000e+00)
%13 = tail call i32 @ConvertWriteDouble(i32 %6, double 1.800000e+00)
%14 = tail call i32 @ConvertWriteDouble(i32 %6, double -8.000000e-01)
%15 = tail call i32 @close(i32 %6)
ret i32 0
}