#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 frexp(double, int *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(int, ...);
int create_Result_file() {
  int i, nbVal, tabRI[20000];
  double tabR[20000], Inc, Val;
  char *F_name, *F_name1;
  int fp, fp1;
  F_name = "frexp_out.ref";
  F_name1 = "frexp1_out.ref";
  nbVal = 20000;
  Inc = exp(1);
  for (i = 0; i < nbVal; i++) {
    Val = Inc * (i + 1);
    tabR[i] = frexp(Val, &(tabRI[i]));
  }
  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(int));
    }
    close(fp);
    close(fp1);
    return 0;
  }
}


x86 assembly (clang, -O0):
<create_Result_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3a9c0,%rsp
lea    0xe8e(%rip),%rax
mov    %rax,-0x3a9a8(%rbp)
lea    0xe8e(%rip),%rax
mov    %rax,-0x3a9b0(%rbp)
movl   $0x4e20,-0xc(%rbp)
mov    $0x1,%edi
call   1070 <exp@plt>
movsd  %xmm0,-0x3a998(%rbp)
ff
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120b <create_Result_file+0xab>
movsd  -0x3a998(%rbp),%xmm0
ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x3a9a0(%rbp)
ff
movsd  -0x3a9a0(%rbp),%xmm0
ff
movslq -0x8(%rbp),%rax
lea    -0x13890(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
call   1060 <frexp@plt>
movslq -0x8(%rbp),%rax
movsd  %xmm0,-0x3a990(%rbp,%rax,8)
fc ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a7 <create_Result_file+0x47>
mov    -0x3a9a8(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
mov    0x2dd6(%rip),%rax
or     (%rax),%esi
mov    0x2dc5(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x3a9b4(%rbp)
mov    -0x3a9b0(%rbp),%rdi
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
mov    0x2da4(%rip),%rax
or     (%rax),%esi
mov    0x2d93(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x3a9b8(%rbp)
cmpl   $0x0,-0x3a9b4(%rbp)
je     1289 <create_Result_file+0x129>
cmpl   $0x0,-0x3a9b8(%rbp)
jne    12b7 <create_Result_file+0x157>
lea    0xd8d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x3a9b4(%rbp),%edi
call   1050 <close@plt>
mov    -0x3a9b8(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133d <create_Result_file+0x1dd>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1320 <create_Result_file+0x1c0>
mov    -0x3a9b4(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x3a990(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x3a9b8(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x13890(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12be <create_Result_file+0x15e>
mov    -0x3a9b4(%rbp),%edi
call   1050 <close@plt>
mov    -0x3a9b8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3a9c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_Result_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3a998,%rsp
mov    $0x1,%edi
call   1070 <exp@plt>
movsd  %xmm0,0x8(%rsp)
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%rbp),%r14
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
mulsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
call   1060 <frexp@plt>
movsd  %xmm0,0x13890(%rsp,%rbp,8)
add    $0x4,%rbx
mov    %r14,%rbp
cmp    $0x4e20,%r14
jne    1190 <create_Result_file+0x30>
mov    0x2e0e(%rip),%r15
mov    0x2e27(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r15),%esi
mov    0x2e12(%rip),%rbx
or     (%rbx),%esi
lea    0xe19(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,%r14d
mov    0x0(%rbp),%esi
or     (%r15),%esi
or     (%rbx),%esi
lea    0xe0b(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,%r15d
test   %r14d,%r14d
je     127e <create_Result_file+0x11e>
test   %r15d,%r15d
je     127e <create_Result_file+0x11e>
lea    0x13890(%rsp),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x8,%edx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <write@plt>
lea    (%rsp,%rbp,1),%rsi
add    $0x10,%rsi
mov    $0x4,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <write@plt>
add    $0x4,%rbp
add    $0x8,%rbx
cmp    $0x13880,%rbp
jne    1230 <create_Result_file+0xd0>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    129f <create_Result_file+0x13f>
lea    0xd98(%rip),%rdi
call   1040 <printf@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
add    $0x3a998,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"frexp_out.ref\00"
@.str.1 = [15 x i8] c"frexp1_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 i32]
%2 = alloca [20000 x double]
%3 = bitcast [20000 x i32]* %1 to i8*
%4 = bitcast [20000 x double]* %2 to i8*
%5 = tail call double @exp(i32 1)
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 0, %0 ], [ %8, %6 ]
%8 = add nuw nsw i64 %7, 1
%9 = trunc i64 %8 to i32
%10 = sitofp i32 %9 to double
%11 = fmul double %5, %10
%12 = getelementptr inbounds [20000 x i32], [20000 x i32]* %1, i64 0, i64 %7
%13 = call double @frexp(double %11, i32* %12)
%14 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %7
store double %13, double* %14
%15 = icmp eq i64 %8, 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 ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %21, i32 511)
%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 ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 511)
%29 = icmp ne i32 %22, 0
%30 = icmp ne i32 %28, 0
%31 = and i1 %29, %30
br i1 %31, label %36, label %32
32: ; preds = %16
%33 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%34 = tail call i32 @close(i32 %22)
%35 = tail call i32 @close(i32 %28)
br label %47
36: ; preds = %16, %36
%37 = phi i64 [ %42, %36 ], [ 0, %16 ]
%38 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %37
%39 = call i32 (i32, ...) @write(i32 %22, double* %38, i64 8)
%40 = getelementptr inbounds [20000 x i32], [20000 x i32]* %1, i64 0, i64 %37
%41 = call i32 (i32, ...) @write(i32 %28, i32* %40, i64 4)
%42 = add nuw nsw i64 %37, 1
%43 = icmp eq i64 %42, 20000
br i1 %43, label %44, label %36
44: ; preds = %36
%45 = call i32 @close(i32 %22)
%46 = call i32 @close(i32 %28)
br label %47
47: ; preds = %44, %32
%48 = phi i32 [ 0, %44 ], [ -1, %32 ]
ret i32 %48
}