#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 O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
double exp(int);
double j1(double);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(int, double *, int);
int create_Result_file(void) {
  int i, nbVal;
  double tabR[20000], Inc;
  char *F_name;
  int fp;
  F_name = "j1_out.ref2";
  nbVal = 20000;
  Inc = exp(1);
  for (i = 0; i < nbVal; i++)
    tabR[i] = j1(Inc * i);
  fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
  if (!fp) {
    printf("error opening file");
    close(fp);
    return -1;
  } else {
    for (i = 0; i < nbVal; i++) {
      write(fp, &tabR[i], sizeof(double));
    }
    close(fp);
    return 0;
  }
  return (0);
}


x86 assembly (clang, -O0):
<create_Result_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27130,%rsp
lea    0xe8e(%rip),%rax
mov    %rax,-0x27120(%rbp)
movl   $0x4e20,-0xc(%rbp)
mov    $0x1,%edi
call   1070 <exp@plt>
movsd  %xmm0,-0x27118(%rbp)
ff
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d6 <create_Result_file+0x76>
movsd  -0x27118(%rbp),%xmm0
ff
cvtsi2sdl -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <j1@plt>
movslq -0x8(%rbp),%rax
movsd  %xmm0,-0x27110(%rbp,%rax,8)
fd ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1199 <create_Result_file+0x39>
mov    -0x27120(%rbp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    0x2e0b(%rip),%rax
or     (%rax),%esi
mov    0x2dfa(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x27124(%rbp)
cmpl   $0x0,-0x27124(%rbp)
jne    1238 <create_Result_file+0xd8>
lea    0xdf0(%rip),%rdi
call   1050 <printf@plt>
mov    -0x27124(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128d <create_Result_file+0x12d>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    127b <create_Result_file+0x11b>
mov    -0x27124(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x27110(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    123f <create_Result_file+0xdf>
mov    -0x27124(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x27130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_Result_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x27110,%rsp
mov    $0x1,%edi
call   1070 <exp@plt>
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x8(%rsp),%xmm0
call   1030 <j1@plt>
movsd  %xmm0,0x10(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x4e20,%rbx
jne    1180 <create_Result_file+0x20>
mov    0x2e2c(%rip),%rax
mov    0x2e45(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e32(%rip),%rax
or     (%rax),%esi
lea    0xe39(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
test   %eax,%eax
je     1203 <create_Result_file+0xa3>
mov    %eax,%ebp
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1040 <write@plt>
add    $0x8,%rbx
cmp    $0x27100,%rbx
jne    11e0 <create_Result_file+0x80>
jmp    1217 <create_Result_file+0xb7>
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
xor    %ebp,%ebp
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14d,%eax
add    $0x27110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"j1_out.ref2\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [19 x i8] c"error opening file\00"
define i32 @create_Result_file() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20000 x double]
%5 = alloca double
%6 = alloca i8*
%7 = alloca i32
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 20000, i32* %3
%8 = call double @exp(i32 1)
store double %8, double* %5
store i32 0, i32* %2
br label %9
9: ; preds = %22, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = load double, double* %5
%15 = load i32, i32* %2
%16 = sitofp i32 %15 to double
%17 = fmul double %14, %16
%18 = call double @j1(double %17)
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [20000 x double], [20000 x double]* %4, i64 0, i64 %20
store double %18, double* %21
br label %22
22: ; preds = %13
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %9
25: ; preds = %9
%26 = load i8*, i8** %6
%27 = load i32, i32* @O_RDWR
%28 = load i32, i32* @O_CREAT
%29 = or i32 %27, %28
%30 = load i32, i32* @O_TRUNC
%31 = or i32 %29, %30
%32 = call i32 @open(i8* %26, i32 %31, i32 511)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %25
%36 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
store i32 -1, i32* %1
br label %56
39: ; preds = %25
store i32 0, i32* %2
br label %40
40: ; preds = %50, %39
%41 = load i32, i32* %2
%42 = load i32, i32* %3
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = load i32, i32* %7
%46 = load i32, i32* %2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [20000 x double], [20000 x double]* %4, i64 0, i64 %47
%49 = call i32 @write(i32 %45, double* %48, i32 8)
br label %50
50: ; preds = %44
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %40
53: ; preds = %40
%54 = load i32, i32* %7
%55 = call i32 @close(i32 %54)
store i32 0, i32* %1
br label %56
56: ; preds = %53, %35
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [12 x i8] c"j1_out.ref2\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [19 x i8] c"error opening file\00"
define i32 @create_Result_file() {
%1 = alloca [20000 x double]
%2 = bitcast [20000 x double]* %1 to i8*
%3 = tail call double @exp(i32 1)
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 0, %0 ], [ %11, %4 ]
%6 = trunc i64 %5 to i32
%7 = sitofp i32 %6 to double
%8 = fmul double %3, %7
%9 = tail call double @j1(double %8)
%10 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %5
store double %9, double* %10
%11 = add nuw nsw i64 %5, 1
%12 = icmp eq i64 %11, 20000
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_CREAT
%16 = or i32 %15, %14
%17 = load i32, i32* @O_TRUNC
%18 = or i32 %16, %17
%19 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %18, i32 511)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %29
23: ; preds = %13, %23
%24 = phi i64 [ %27, %23 ], [ 0, %13 ]
%25 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %24
%26 = call i32 @write(i32 %19, double* %25, i32 8)
%27 = add nuw nsw i64 %24, 1
%28 = icmp eq i64 %27, 20000
br i1 %28, label %29, label %23
29: ; preds = %23, %21
%30 = phi i32 [ 0, %21 ], [ %19, %23 ]
%31 = phi i32 [ -1, %21 ], [ 0, %23 ]
%32 = tail call i32 @close(i32 %30)
ret i32 %31
}