#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(int);
double log(int);
double modf(double, double *);
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, tabRI[20000];
  char *F_name, *F_name1;
  int fp, fp1;
  double TestInputValue, TestChkSum;
  F_name = "modf_out.ref";
  F_name1 = "modf1_out.ref";
  nbVal = 20000;
  Inc = log(exp(1) / 10);
  for (i = 0; i < nbVal; i++) {
    TestInputValue = ((Inc * i) + Inc);
    tabR[i] = modf(TestInputValue, &tabRI[i]);
    if ((TestChkSum = tabR[i] + tabRI[i]) != TestInputValue) {
      return -1;
    }
  }
  fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
  fp1 = open(F_name1, O_RDWR | O_CREAT | O_TRUNC, 0777);
  if (!fp || !fp1) {
    printf("error opening file");
    close(fp);
    close(fp1);
    return -1;
  } else {
    for (i = 0; i < nbVal; i++) {
      write(fp, &tabR[i], sizeof(double));
      write(fp1, &tabRI[i], sizeof(double));
    }
    close(fp);
    close(fp1);
    return 0;
  }
}


x86 assembly (clang, -O0):
<create_Result_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e250,%rsp
lea    0xe7e(%rip),%rax
mov    %rax,-0x4e228(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x4e230(%rbp)
movl   $0x4e20,-0xc(%rbp)
mov    $0x1,%edi
call   1070 <exp@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1090 <log@plt>
movsd  %xmm0,-0x27118(%rbp)
ff
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    127d <create_Result_file+0x10d>
movsd  -0x27118(%rbp),%xmm0
ff
cvtsi2sdl -0x8(%rbp),%xmm2
movsd  -0x27118(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x4e240(%rbp)
ff
movsd  -0x4e240(%rbp),%xmm0
ff
movslq -0x8(%rbp),%rax
lea    -0x4e220(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
call   1050 <modf@plt>
movslq -0x8(%rbp),%rax
movsd  %xmm0,-0x27110(%rbp,%rax,8)
fd ff
movslq -0x8(%rbp),%rax
movsd  -0x27110(%rbp,%rax,8),%xmm0
fd ff
movslq -0x8(%rbp),%rax
addsd  -0x4e220(%rbp,%rax,8),%xmm0
fb ff
movsd  %xmm0,-0x4e248(%rbp)
ff
ucomisd -0x4e240(%rbp),%xmm0
ff
jne    125e <create_Result_file+0xee>
jp     125e <create_Result_file+0xee>
jmp    126a <create_Result_file+0xfa>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ab <create_Result_file+0x23b>
jmp    126f <create_Result_file+0xff>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c6 <create_Result_file+0x56>
mov    -0x4e228(%rbp),%rdi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
mov    0x2d64(%rip),%rax
or     (%rax),%esi
mov    0x2d53(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x4e234(%rbp)
mov    -0x4e230(%rbp),%rdi
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
mov    0x2d32(%rip),%rax
or     (%rax),%esi
mov    0x2d21(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x4e238(%rbp)
cmpl   $0x0,-0x4e234(%rbp)
je     12fb <create_Result_file+0x18b>
cmpl   $0x0,-0x4e238(%rbp)
jne    1329 <create_Result_file+0x1b9>
lea    0xd19(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4e234(%rbp),%edi
call   1060 <close@plt>
mov    -0x4e238(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ab <create_Result_file+0x23b>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    138e <create_Result_file+0x21e>
mov    -0x4e234(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x27110(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x4e238(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x4e220(%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    1330 <create_Result_file+0x1c0>
mov    -0x4e234(%rbp),%edi
call   1060 <close@plt>
mov    -0x4e238(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4e250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_Result_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4e218,%rsp
mov    $0x1,%edi
call   1070 <exp@plt>
cltq
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x22,%rdi
add    %eax,%edi
call   1090 <log@plt>
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
call   1050 <modf@plt>
movsd  %xmm0,0x27110(%rsp,%rbp,8)
addsd  0x10(%rsp,%rbp,8),%xmm0
ucomisd 0x8(%rsp),%xmm0
jne    12ab <create_Result_file+0x13b>
jp     12ab <create_Result_file+0x13b>
add    $0x1,%rbp
add    $0x8,%rbx
cmp    $0x4e20,%rbp
jne    11b0 <create_Result_file+0x40>
mov    0x2dc8(%rip),%r14
mov    0x2de1(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r14),%esi
mov    0x2dcc(%rip),%rbx
or     (%rbx),%esi
lea    0xdd3(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,%r15d
mov    0x0(%rbp),%esi
or     (%r14),%esi
or     (%rbx),%esi
lea    0xdc4(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,%ebp
test   %r15d,%r15d
je     12b3 <create_Result_file+0x143>
test   %ebp,%ebp
je     12b3 <create_Result_file+0x143>
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%rsp,%rbx,1),%rsi
add    $0x27110,%rsi
mov    %r15d,%edi
mov    $0x8,%edx
call   1030 <write@plt>
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    1270 <create_Result_file+0x100>
jmp    12c5 <create_Result_file+0x155>
mov    $0xffffffff,%r14d
jmp    12d4 <create_Result_file+0x164>
lea    0xd61(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r15d,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14d,%eax
add    $0x4e218,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"modf_out.ref\00"
@.str.1 = [14 x i8] c"modf1_out.ref\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [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 [20000 x double]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i32 20000, i32* %3
%13 = call i32 @exp(i32 1)
%14 = sdiv i32 %13, 10
%15 = call double @log(i32 %14)
store double %15, double* %5
store i32 0, i32* %2
br label %16
16: ; preds = %47, %0
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %50
20: ; preds = %16
%21 = load double, double* %5
%22 = load i32, i32* %2
%23 = sitofp i32 %22 to double
%24 = load double, double* %5
%25 = call double @llvm.fmuladd.f64(double %21, double %23, double %24)
store double %25, double* %11
%26 = load double, double* %11
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [20000 x double], [20000 x double]* %6, i64 0, i64 %28
%30 = call double @modf(double %26, double* %29)
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [20000 x double], [20000 x double]* %4, i64 0, i64 %32
store double %30, double* %33
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [20000 x double], [20000 x double]* %4, i64 0, i64 %35
%37 = load double, double* %36
%38 = load i32, i32* %2
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [20000 x double], [20000 x double]* %6, i64 0, i64 %39
%41 = load double, double* %40
%42 = fadd double %37, %41
store double %42, double* %12
%43 = load double, double* %11
%44 = fcmp une double %42, %43
br i1 %44, label %45, label %46
45: ; preds = %20
store i32 -1, i32* %1
br label %100
46: ; preds = %20
br label %47
47: ; preds = %46
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %16
50: ; preds = %16
%51 = load i8*, i8** %7
%52 = load i32, i32* @O_RDWR
%53 = load i32, i32* @O_CREAT
%54 = or i32 %52, %53
%55 = load i32, i32* @O_TRUNC
%56 = or i32 %54, %55
%57 = call i32 @open(i8* %51, i32 %56, i32 511)
store i32 %57, i32* %9
%58 = load i8*, i8** %8
%59 = load i32, i32* @O_RDWR
%60 = load i32, i32* @O_CREAT
%61 = or i32 %59, %60
%62 = load i32, i32* @O_TRUNC
%63 = or i32 %61, %62
%64 = call i32 @open(i8* %58, i32 %63, i32 511)
store i32 %64, i32* %10
%65 = load i32, i32* %9
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %50
%68 = load i32, i32* %10
%69 = icmp ne i32 %68, 0
br i1 %69, label %76, label %70
70: ; preds = %67, %50
%71 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%72 = load i32, i32* %9
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %10
%75 = call i32 @close(i32 %74)
store i32 -1, i32* %1
br label %100
76: ; preds = %67
store i32 0, i32* %2
br label %77
77: ; preds = %92, %76
%78 = load i32, i32* %2
%79 = load i32, i32* %3
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %95
81: ; preds = %77
%82 = load i32, i32* %9
%83 = load i32, i32* %2
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [20000 x double], [20000 x double]* %4, i64 0, i64 %84
%86 = call i32 @write(i32 %82, double* %85, i32 8)
%87 = load i32, i32* %10
%88 = load i32, i32* %2
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [20000 x double], [20000 x double]* %6, i64 0, i64 %89
%91 = call i32 @write(i32 %87, double* %90, i32 8)
br label %92
92: ; preds = %81
%93 = load i32, i32* %2
%94 = add nsw i32 %93, 1
store i32 %94, i32* %2
br label %77
95: ; preds = %77
%96 = load i32, i32* %9
%97 = call i32 @close(i32 %96)
%98 = load i32, i32* %10
%99 = call i32 @close(i32 %98)
store i32 0, i32* %1
br label %100
100: ; preds = %95, %70, %45
%101 = load i32, i32* %1
ret i32 %101
}

LLVM IR (-O2):
@.str = [13 x i8] c"modf_out.ref\00"
@.str.1 = [14 x i8] c"modf1_out.ref\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [19 x i8] c"error opening file\00"
define i32 @create_Result_file() {
%1 = alloca [20000 x double]
%2 = alloca [20000 x double]
%3 = bitcast [20000 x double]* %1 to i8*
%4 = bitcast [20000 x double]* %2 to i8*
%5 = tail call i32 @exp(i32 1)
%6 = sdiv i32 %5, 10
%7 = tail call double @log(i32 %6)
br label %11
8: ; preds = %11
%9 = add nuw nsw i64 %12, 1
%10 = icmp eq i64 %9, 20000
br i1 %10, label %22, label %11
11: ; preds = %0, %8
%12 = phi i64 [ 0, %0 ], [ %9, %8 ]
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to double
%15 = tail call double @llvm.fmuladd.f64(double %7, double %14, double %7)
%16 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %12
%17 = call double @modf(double %15, double* %16)
%18 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %12
store double %17, double* %18
%19 = load double, double* %16
%20 = fadd double %17, %19
%21 = fcmp une double %20, %15
br i1 %21, label %52, label %8
22: ; preds = %8
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_CREAT
%25 = or i32 %24, %23
%26 = load i32, i32* @O_TRUNC
%27 = or i32 %25, %26
%28 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %27, i32 511)
%29 = load i32, i32* @O_RDWR
%30 = load i32, i32* @O_CREAT
%31 = or i32 %30, %29
%32 = load i32, i32* @O_TRUNC
%33 = or i32 %31, %32
%34 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 511)
%35 = icmp ne i32 %28, 0
%36 = icmp ne i32 %34, 0
%37 = and i1 %35, %36
br i1 %37, label %40, label %38
38: ; preds = %22
%39 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %48
40: ; preds = %22, %40
%41 = phi i64 [ %46, %40 ], [ 0, %22 ]
%42 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %41
%43 = call i32 @write(i32 %28, double* %42, i32 8)
%44 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %41
%45 = call i32 @write(i32 %34, double* %44, i32 8)
%46 = add nuw nsw i64 %41, 1
%47 = icmp eq i64 %46, 20000
br i1 %47, label %48, label %40
48: ; preds = %40, %38
%49 = phi i32 [ -1, %38 ], [ 0, %40 ]
%50 = tail call i32 @close(i32 %28)
%51 = tail call i32 @close(i32 %34)
br label %52
52: ; preds = %11, %48
%53 = phi i32 [ %49, %48 ], [ -1, %11 ]
ret i32 %53
}