#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_RDONLY;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
double fabs(double);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, double *, int);
int /*<<< orphan*/ write(int, double *, int);
int create_Result_file(void) {
  int i, nbVal;
  double tabR[20000], Val;
  char *F_name, *F_naminp;
  int fp, fpi;
  F_name = "fabs_out.ref";
  F_naminp = "fabs_inp.ref";
  nbVal = 20000;
  fpi = open(F_naminp, O_RDONLY, 0777);
  if (!fpi) {
    printf("error opening file");
    close(fpi);
    return -1;
  } else {
    for (i = 0; i < nbVal; i++) {
      read(fpi, &Val, sizeof(double));
      tabR[i] = fabs(Val);
    }
    close(fpi);
    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    0xeae(%rip),%rax
mov    %rax,-0x27120(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x27128(%rbp)
movl   $0x4e20,-0xc(%rbp)
mov    -0x27128(%rbp),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,-0x27130(%rbp)
cmpl   $0x0,-0x27130(%rbp)
jne    11ce <create_Result_file+0x7e>
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
mov    -0x27130(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e8 <create_Result_file+0x198>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1226 <create_Result_file+0xd6>
mov    -0x27130(%rbp),%edi
lea    -0x27118(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
movsd  -0x27118(%rbp),%xmm0
ff
movaps 0xdf9(%rip),%xmm1
pand   %xmm1,%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    11d5 <create_Result_file+0x85>
mov    -0x27130(%rbp),%edi
call   1050 <close@plt>
mov    -0x27120(%rbp),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
mov    0x2db0(%rip),%rax
or     (%rax),%esi
mov    0x2d9f(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,-0x2712c(%rbp)
cmpl   $0x0,-0x2712c(%rbp)
jne    1293 <create_Result_file+0x143>
lea    0xdb3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x2712c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e8 <create_Result_file+0x198>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12d6 <create_Result_file+0x186>
mov    -0x2712c(%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    129a <create_Result_file+0x14a>
mov    -0x2712c(%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
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xeb2(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <open@plt>
test   %eax,%eax
je     1223 <create_Result_file+0xd3>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <read@plt>
movsd  0x8(%rsp),%xmm0
andps  0xe54(%rip),%xmm0
movlps %xmm0,0x10(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x4e20,%rbx
jne    1190 <create_Result_file+0x40>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2e0c(%rip),%rax
mov    0x2e25(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e12(%rip),%rax
or     (%rax),%esi
lea    0xe29(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <open@plt>
test   %eax,%eax
je     1223 <create_Result_file+0xd3>
mov    %eax,%ebx
xor    %r14d,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
lea    (%rsp,%rbp,1),%rsi
add    $0x10,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <write@plt>
add    $0x8,%rbp
cmp    $0x27100,%rbp
jne    1200 <create_Result_file+0xb0>
jmp    1237 <create_Result_file+0xe7>
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
xor    %ebx,%ebx
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r14d,%eax
add    $0x27110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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