#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);
int exp(double);
double log(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(int, double *, int);
int create_Result_file() {
  int i, nbVal;
  double tabR[20000], Inc;
  char *F_name;
  int fp;
  F_name = "exp_out.ref";
  nbVal = 20000;
  Inc = log(exp(1) / 10);
  for (i = 0; i < nbVal; i++)
    tabR[i] = exp((Inc * i) + Inc);
  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;
  }
}


x86 assembly (clang, -O0):
<create_Result_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27130,%rsp
lea    0xe96(%rip),%rax
mov    %rax,-0x27120(%rbp)
movl   $0x4e20,-0xc(%rbp)
movsd  0xe78(%rip),%xmm0
call   1060 <exp@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1080 <log@plt>
movsd  %xmm0,-0x27118(%rbp)
ff
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f8 <create_Result_file+0x98>
movsd  -0x27118(%rbp),%xmm0
ff
cvtsi2sdl -0x8(%rbp),%xmm2
movsd  -0x27118(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1060 <exp@plt>
cvtsi2sd %eax,%xmm0
movslq -0x8(%rbp),%rax
movsd  %xmm0,-0x27110(%rbp,%rax,8)
fd ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ab <create_Result_file+0x4b>
mov    -0x27120(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
mov    0x2de9(%rip),%rax
or     (%rax),%esi
mov    0x2dd8(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,-0x27124(%rbp)
cmpl   $0x0,-0x27124(%rbp)
jne    125a <create_Result_file+0xfa>
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x27124(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12af <create_Result_file+0x14f>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    129d <create_Result_file+0x13d>
mov    -0x27124(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x27110(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1261 <create_Result_file+0x101>
mov    -0x27124(%rbp),%edi
call   1050 <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
movsd  0xe8d(%rip),%xmm0
call   1060 <exp@plt>
cltq
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x22,%rdi
add    %eax,%edi
call   1080 <log@plt>
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
call   1060 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x4e20,%rbx
jne    11a0 <create_Result_file+0x40>
mov    0x2dfd(%rip),%rax
mov    0x2e16(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e03(%rip),%rax
or     (%rax),%esi
lea    0xe12(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <open@plt>
test   %eax,%eax
je     1233 <create_Result_file+0xd3>
mov    %eax,%ebp
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1030 <write@plt>
add    $0x8,%rbx
cmp    $0x27100,%rbx
jne    1210 <create_Result_file+0xb0>
jmp    1247 <create_Result_file+0xe7>
lea    0xdda(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
xor    %ebp,%ebp
mov    %ebp,%edi
call   1050 <close@plt>
mov    %r14d,%eax
add    $0x27110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"exp_out.ref\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 i32 @exp(double 1.000000e+00)
%9 = sdiv i32 %8, 10
%10 = call double @log(i32 %9)
store double %10, double* %5
store i32 0, i32* %2
br label %11
11: ; preds = %26, %0
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load double, double* %5
%17 = load i32, i32* %2
%18 = sitofp i32 %17 to double
%19 = load double, double* %5
%20 = call double @llvm.fmuladd.f64(double %16, double %18, double %19)
%21 = call i32 @exp(double %20)
%22 = sitofp i32 %21 to double
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [20000 x double], [20000 x double]* %4, i64 0, i64 %24
store double %22, double* %25
br label %26
26: ; preds = %15
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %11
29: ; preds = %11
%30 = load i8*, i8** %6
%31 = load i32, i32* @O_RDWR
%32 = load i32, i32* @O_CREAT
%33 = or i32 %31, %32
%34 = load i32, i32* @O_TRUNC
%35 = or i32 %33, %34
%36 = call i32 @open(i8* %30, i32 %35, i32 511)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %29
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* %7
%42 = call i32 @close(i32 %41)
store i32 -1, i32* %1
br label %60
43: ; preds = %29
store i32 0, i32* %2
br label %44
44: ; preds = %54, %43
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %57
48: ; preds = %44
%49 = load i32, i32* %7
%50 = load i32, i32* %2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [20000 x double], [20000 x double]* %4, i64 0, i64 %51
%53 = call i32 @write(i32 %49, double* %52, i32 8)
br label %54
54: ; preds = %48
%55 = load i32, i32* %2
%56 = add nsw i32 %55, 1
store i32 %56, i32* %2
br label %44
57: ; preds = %44
%58 = load i32, i32* %7
%59 = call i32 @close(i32 %58)
store i32 0, i32* %1
br label %60
60: ; preds = %57, %39
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [12 x i8] c"exp_out.ref\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 i32 @exp(double 1.000000e+00)
%4 = sdiv i32 %3, 10
%5 = tail call double @log(i32 %4)
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 0, %0 ], [ %14, %6 ]
%8 = trunc i64 %7 to i32
%9 = sitofp i32 %8 to double
%10 = tail call double @llvm.fmuladd.f64(double %5, double %9, double %5)
%11 = tail call i32 @exp(double %10)
%12 = sitofp i32 %11 to double
%13 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %7
store double %12, double* %13
%14 = add nuw nsw i64 %7, 1
%15 = icmp eq i64 %14, 20000
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_CREAT
%19 = or i32 %18, %17
%20 = load i32, i32* @O_TRUNC
%21 = or i32 %19, %20
%22 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %21, i32 511)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %32
26: ; preds = %16, %26
%27 = phi i64 [ %30, %26 ], [ 0, %16 ]
%28 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %27
%29 = call i32 @write(i32 %22, double* %28, i32 8)
%30 = add nuw nsw i64 %27, 1
%31 = icmp eq i64 %30, 20000
br i1 %31, label %32, label %26
32: ; preds = %26, %24
%33 = phi i32 [ 0, %24 ], [ %22, %26 ]
%34 = phi i32 [ -1, %24 ], [ 0, %26 ]
%35 = tail call i32 @close(i32 %33)
ret i32 %34
}